1
This commit is contained in:
@@ -468,11 +468,6 @@ public class JDUtils {
|
||||
|
||||
// 推送
|
||||
wxUtil.sendTextMessage(WXUtil.super_admin_wxid, content, 1, WXUtil.super_admin_wxid);
|
||||
try {
|
||||
sleep(300);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -15,7 +15,9 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Leo
|
||||
@@ -80,13 +82,31 @@ 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:群发
|
||||
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);
|
||||
List<String> strings = splitStringByLength(content, 500);
|
||||
int count = 0;
|
||||
for (String string : strings) {
|
||||
if (count > 0) {
|
||||
string += "---长消息---" + count;
|
||||
}
|
||||
count++;
|
||||
// 如果是自己的微信,所有信息都加上少爷
|
||||
if (wxid.equals(super_admin_wxid) || fromwxid.equals(super_admin_wxid)) {
|
||||
content = "超管: 凡 !\r\n" + content;
|
||||
string = "超管: 凡 !\r\n" + string;
|
||||
}
|
||||
//JSONObject wxList = getWxList();
|
||||
//JSONObject wxBotInfo = (JSONObject) wxList.getJSONArray("result").get(0);
|
||||
@@ -111,32 +131,29 @@ public class WXUtil {
|
||||
"msg": "666大佬~"
|
||||
}*/
|
||||
JSONObject data = new JSONObject();
|
||||
data.put("msg", content);
|
||||
data.put("msg", string);
|
||||
data.put("wxid", wxid);
|
||||
jsonObject.put("data", data);
|
||||
|
||||
System.out.println(JSON.toJSONString(jsonObject));
|
||||
//System.out.println(JSON.toJSONString(jsonObject));
|
||||
//wxReqDate.setData(jsonObject);
|
||||
while (Util.isNotEmpty(wxid)) {
|
||||
String responseStr = HttpRequest.post(WX_BASE_URL).body(JSON.toJSONString(jsonObject)).execute().body();
|
||||
if (Util.isNotEmpty(wxid)) {
|
||||
String responseStr = HttpRequest.post(WX_BASE_URL)
|
||||
.body(JSON.toJSONString(jsonObject)).execute().body();
|
||||
if (ObjectUtil.isNotEmpty(responseStr)) {
|
||||
JSONObject response = JSON.parseObject(responseStr);
|
||||
//WxResponse wxResponse = JSON.parseObject(responseStr, WxResponse.class);
|
||||
//System.out.println(wxResponse);
|
||||
//if (Objects.equals(String.valueOf(wxResponse.getCode()), "200")) {
|
||||
// return wxResponse.getData();
|
||||
//}
|
||||
//JSONObject jsonObject = HttpUtil.sendPost(url, wxReqDate.getData());
|
||||
logger.info("消息响应:" + response.toString());
|
||||
return response;
|
||||
//return response;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
Thread.sleep(100);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
//private JSONObject sendWxReq(WxReqDate wxReqDate) {
|
||||
|
||||
Reference in New Issue
Block a user