@@ -15,7 +15,9 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment ;
import org.springframework.core.env.Environment ;
import org.springframework.stereotype.Component ;
import org.springframework.stereotype.Component ;
import java.util.ArrayList ;
import java.util.HashMap ;
import java.util.HashMap ;
import java.util.List ;
/**
/**
* @author Leo
* @author Leo
@@ -80,63 +82,78 @@ public class WXUtil {
}
}
public static List < String > splitStringByLength ( String input , int length ) {
List < String > result = new ArrayList < > ( ) ;
// 循环增加长度直到超过字符串长度
for ( int start = 0 ; start < input . length ( ) ; start + = length ) {
// 截取字符串,但需要检查边界
int end = Math . min ( start + length , input . length ( ) ) ;
result . add ( input . substring ( start , end ) ) ;
}
return result ;
}
// 发送文本消息 msgType 1:私聊 2:群发
// 发送文本消息 msgType 1:私聊 2:群发
public JSONObject sendTextMessage ( String wxid , String content , Integer msgType , String fromwxid ) {
public void sendTextMessage ( String wxid , String content , Integer msgType , String fromwxid ) {
// 全部打印
// 全部打印
logger . info ( " 发送文本消息 msgType: " + msgType + " wxid: " + wxid + " fromwxid: " + fromwxid + " content: " + content ) ;
logger . info ( " 发送文本消息 msgType: " + msgType + " wxid: " + wxid + " fromwxid: " + fromwxid + " content: " + content ) ;
// 如果是自己的微信,所有信息都加上少爷
List < String > strings = splitStringByLength ( content , 500 ) ;
if ( wxid . equals ( super_admin_wxid ) | | fromwxid . equals ( super_admin_wxid ) ) {
int count = 0 ;
content = " 超管: 凡 ! \ r \ n " + content ;
for ( String string : strings ) {
}
if ( count > 0 ) {
//JSONObject wxList = getWxList() ;
string + = " ---长消息--- " + count ;
//JSONObject wxBotInfo = (JSONObject) wxList.getJSONArray("result").get(0);
}
//botWxid = wxBotInfo.getString("wxid") ;
count + + ;
//
// 如果是自己的微信,所有信息都加上少爷
////
if ( wxid . equals ( super_admin_wxid ) | | fromwxid . equals ( super_admin_wxid ) ) {
//WxReqDate wxReqDate = createWxReqData(WXReqType.SEND_TEXT_MESSAGE) ;
string = " 超管: 凡 ! \ r \ n " + string ;
JSONObject jsonObject = new JSONObject ( ) ;
}
jsonObject . put ( " type " , WXReqType . SEND_TEXT_MESSAGE . getType ( ) ) ;
//JSONObject wxList = getWxList() ;
//if ((msgType.equals(1))) {
//JSONObject wxBotInfo = (JSONObject) wxList.getJSONArray("result").get(0);
// jsonObject.put ("wxid", wxid );
//botWxid = wxBotInfo.getString ("wxid");
// content = content;
//
//}
////
////[@,wxid=对象wxid,nick=对象昵称,isAuto=true]
//WxReqDate wxReqDate = createWxReqData(WXReqType.SEND_TEXT_MESSAGE);
//if ((msgType.equals(2))) {
JSONObject jsonObject = new JSONObject ( ) ;
// jsonObject.put("wxid", fromwxid) ;
jsonObject. put ( " type " , WXReqType . SEND_TEXT_MESSAGE . getType ( ) ) ;
// content = "[@,wxid=" + wxid + ",nick=6,isAuto=true] " + content;
//if ((msgType.equals(1))) {
//}
// jsonObject.put("wxid", wxid);
// content = content;
//}
////[@,wxid=对象wxid,nick=对象昵称,isAuto=true]
//if ((msgType.equals(2))) {
// jsonObject.put("wxid", fromwxid);
// content = "[@,wxid=" + wxid + ",nick=6,isAuto=true] " + content;
//}
/*
/*
* {
* {
"wxid": "filehelper",
"wxid": "filehelper",
"msg": "666大佬~"
"msg": "666大佬~"
}*/
}*/
JSONObject data = new JSONObject ( ) ;
JSONObject data = new JSONObject ( ) ;
data . put ( " msg " , content ) ;
data . put ( " msg " , string ) ;
data . put ( " wxid " , wxid ) ;
data . put ( " wxid " , wxid ) ;
jsonObject . put ( " data " , data ) ;
jsonObject . put ( " data " , data ) ;
System . out . println ( JSON . toJSONString( jsonObject) ) ;
//System.out.println(JSON. toJSONString( jsonObject)) ;
//wxReqDate.setData(jsonObject);
//wxReqDate.setData(jsonObject);
while ( Util . isNotEmpty ( wxid ) ) {
if ( Util . isNotEmpty ( wxid ) ) {
String responseStr = HttpRequest . post ( WX_BASE_URL ) . body ( JSON . toJSONString ( jsonObject ) ) . execute ( ) . body ( ) ;
String responseStr = HttpRequest . post ( WX_BASE_URL )
if ( ObjectUtil . isNotEmpty ( responseStr ) ) {
. body ( JSON . toJSONString ( jsonObject ) ) . execute ( ) . body ( ) ;
JSONObject response = JSON . parseObject ( responseStr ) ;
if ( ObjectUtil . isNotEmpty ( responseStr ) ) {
//WxResponse wxResponse = JSON. parseObject( responseStr, WxResponse.class) ;
JSONObject response = JSON . parseObject( responseStr) ;
//System.out.println(wxResponse) ;
logger . info ( " 消息响应: " + response . toString ( ) ) ;
//if (Objects.equals(String.valueOf(wxResponse.getCode()), "200")) {
//return response;
// return wxResponse.getData() ;
continue ;
// }
}
//JSONObject jsonObject = HttpUtil.sendPost(url, wxReqDate.getData());
logger . info ( " 消息响应: " + response . toString ( ) ) ;
return response ;
}
}
try {
try {
Thread . sleep ( 1000 ) ;
Thread . sleep ( 100 ) ;
} catch ( InterruptedException e ) {
} catch ( InterruptedException e ) {
throw new RuntimeException ( e ) ;
throw new RuntimeException ( e ) ;
}
}
}
}
return null ;
}
}
//private JSONObject sendWxReq(WxReqDate wxReqDate) {
//private JSONObject sendWxReq(WxReqDate wxReqDate) {