1
This commit is contained in:
@@ -38,7 +38,7 @@ public class DCController {
|
||||
if (!StrUtil.isAllNotEmpty(message.getTitle(), message.getText())) {
|
||||
return R.error("缺少标题和内容");
|
||||
}
|
||||
String result = WxSendUtil.sendNotify(message.getTitle(), message.getText(), message.getTouser(), WXMessageType.TY);
|
||||
String result = WxSendUtil.sendNotifyForMpnews(message.getTitle(), message.getText(), message.getTouser(), WXMessageType.TY);
|
||||
return R.ok(result);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ public class WXController {
|
||||
if (ObjectUtil.isEmpty(WXMessageType.valueOf(message.getMessageType()))) {
|
||||
return R.error("消息类型不存在");
|
||||
}
|
||||
String result = WxSendUtil.sendNotify(message.getTitle(), message.getText(), message.getTouser(), WXMessageType.valueOf(message.getMessageType()));
|
||||
String result = WxSendUtil.sendNotifyForMpnews(message.getTitle(), message.getText(), message.getTouser(), WXMessageType.valueOf(message.getMessageType()));
|
||||
return R.ok(result);
|
||||
|
||||
}
|
||||
@@ -88,7 +88,7 @@ public class WXController {
|
||||
if (!StrUtil.isAllNotEmpty(message.getTitle(), message.getText())) {
|
||||
return R.error("缺少标题和内容");
|
||||
}
|
||||
String result = WxSendUtil.sendNotify("("+sourceForQL+") "+message.getTitle(), message.getText(), message.getTouser(), WXMessageType.QL);
|
||||
String result = WxSendUtil.sendNotifyForMpnews("("+sourceForQL+") "+message.getTitle(), message.getText(), message.getTouser(), WXMessageType.QL);
|
||||
logger.info("result 打印---{}",result);
|
||||
return R.ok(result);
|
||||
|
||||
@@ -106,7 +106,7 @@ public class WXController {
|
||||
if (!StrUtil.isAllNotEmpty(message.getTitle(), message.getText())) {
|
||||
return R.error("缺少标题和内容");
|
||||
}
|
||||
String result = WxSendUtil.sendNotify(message.getTitle(), message.getText(), message.getTouser(), WXMessageType.QH);
|
||||
String result = WxSendUtil.sendNotifyForMpnews(message.getTitle(), message.getText(), message.getTouser(), WXMessageType.QH);
|
||||
return R.ok(result);
|
||||
}
|
||||
|
||||
@@ -122,7 +122,7 @@ public class WXController {
|
||||
if (!StrUtil.isAllNotEmpty(message.getTitle(), message.getText())) {
|
||||
return R.error("缺少标题和内容");
|
||||
}
|
||||
String result = WxSendUtil.sendNotify(message.getTitle(), message.getText(), message.getTouser(), WXMessageType.MT);
|
||||
String result = WxSendUtil.sendNotifyForMpnews(message.getTitle(), message.getText(), message.getTouser(), WXMessageType.MT);
|
||||
return R.ok(result);
|
||||
}
|
||||
|
||||
@@ -138,7 +138,7 @@ public class WXController {
|
||||
if (!StrUtil.isAllNotEmpty(message.getTitle(), message.getText())) {
|
||||
return R.error("缺少标题和内容");
|
||||
}
|
||||
String result = WxSendUtil.sendNotify(message.getTitle(), message.getText(), message.getTouser(), WXMessageType.IMT);
|
||||
String result = WxSendUtil.sendNotifyForMpnews(message.getTitle(), message.getText(), message.getTouser(), WXMessageType.IMT);
|
||||
return R.ok(result);
|
||||
}
|
||||
|
||||
@@ -154,7 +154,7 @@ public class WXController {
|
||||
if (!StrUtil.isAllNotEmpty(message.getTitle(), message.getText())) {
|
||||
return R.error("缺少标题和内容");
|
||||
}
|
||||
String result = WxSendUtil.sendNotify(message.getTitle(), message.getText(), message.getTouser(), WXMessageType.TY);
|
||||
String result = WxSendUtil.sendNotifyForMpnews(message.getTitle(), message.getText(), message.getTouser(), WXMessageType.TY);
|
||||
return R.ok(result);
|
||||
}
|
||||
|
||||
@@ -183,7 +183,7 @@ public class WXController {
|
||||
if (!StrUtil.isAllNotEmpty(message.getTitle(), message.getText())) {
|
||||
return R.error("缺少标题和内容");
|
||||
}
|
||||
String result = WxSendUtil.sendNotify("("+sourceForQL+") "+message.getTitle(), message.getText(), message.getTouser(), WXMessageType.JENKINS);
|
||||
String result = WxSendUtil.sendNotifyForMpnews("("+sourceForQL+") "+message.getTitle(), message.getText(), message.getTouser(), WXMessageType.JENKINS);
|
||||
logger.info("result 打印---{}",result);
|
||||
return R.ok(result);
|
||||
|
||||
@@ -210,11 +210,11 @@ public class WXController {
|
||||
}
|
||||
logger.info("vanToken 打印---{}",vanToken);
|
||||
logger.info("source 打印---{}",source);
|
||||
String sourceForQL = SourceForQLUtil.transferSource(source);
|
||||
//String sourceForQL = SourceForQLUtil.transferSource(source);
|
||||
if (!StrUtil.isAllNotEmpty(message.getTitle(), message.getText())) {
|
||||
return R.error("缺少标题和内容");
|
||||
}
|
||||
String result = WxSendUtil.sendNotify("("+sourceForQL+") "+message.getTitle(), message.getText(), message.getTouser(), WXMessageType.JD);
|
||||
String result = WxSendUtil.sendNotifyForText(message.getTitle(), message.getText(), message.getTouser(), WXMessageType.JD);
|
||||
logger.info("result 打印---{}",result);
|
||||
return R.ok(result);
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@ public class WxSendUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public static String sendNotify(String title, String text, String touser, WXMessageType wxMessageType) throws Exception {
|
||||
public static String sendNotifyForMpnews(String title, String text, String touser, WXMessageType wxMessageType) throws Exception {
|
||||
if (!StrUtil.isAllNotEmpty(title, text)) {
|
||||
return "title,text不能为空!";
|
||||
}
|
||||
@@ -75,10 +75,10 @@ public class WxSendUtil {
|
||||
String[] split = touser.split(",");
|
||||
touserList.addAll(Arrays.asList(split));
|
||||
}
|
||||
return sendNotify(title, text, touserList, wxMessageType);
|
||||
return sendNotifyForMpnews(title, text, touserList, wxMessageType);
|
||||
}
|
||||
|
||||
public static String sendNotify(String title, String text, List<String> touser, WXMessageType wxMessageType) throws Exception {
|
||||
public static String sendNotifyForMpnews(String title, String text, List<String> touser, WXMessageType wxMessageType) throws Exception {
|
||||
|
||||
if (!StrUtil.isAllNotEmpty(title, text)) {
|
||||
return "title,text不能为空!";
|
||||
@@ -145,6 +145,81 @@ public class WxSendUtil {
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
public static String sendNotifyForText(String title, String text, String touser, WXMessageType wxMessageType) throws Exception {
|
||||
if (!StrUtil.isAllNotEmpty(title, text)) {
|
||||
return "title,text不能为空!";
|
||||
}
|
||||
ArrayList<String> touserList = new ArrayList<>();
|
||||
if (StringUtils.isNotEmpty(touser)) {
|
||||
String[] split = touser.split(",");
|
||||
touserList.addAll(Arrays.asList(split));
|
||||
}
|
||||
return sendNotifyForText(title, text, touserList, wxMessageType);
|
||||
}
|
||||
|
||||
public static String sendNotifyForText(String title, String content, List<String> touser, WXMessageType wxMessageType) throws Exception {
|
||||
|
||||
if (!StrUtil.isAllNotEmpty(title, content)) {
|
||||
return "title,text不能为空!";
|
||||
}
|
||||
|
||||
HashMap<String, Object> jsonMap = new HashMap<>();
|
||||
StringBuilder touserStringBuilder = new StringBuilder();
|
||||
String touserStr = "@all";
|
||||
if (ObjectUtil.isNotEmpty(touser)) {
|
||||
|
||||
if (touser.size() > 1) {
|
||||
touser.forEach(t ->
|
||||
touserStringBuilder.append(t).append("|")
|
||||
);
|
||||
touserStr = touserStringBuilder.substring(0, touser.size() - 1);
|
||||
} else {
|
||||
touserStr = touserStringBuilder.append(touser.get(0)).toString();
|
||||
}
|
||||
|
||||
}
|
||||
jsonMap.put("touser", touserStr);
|
||||
jsonMap.put("agentid", wxMessageType.getAgentid());
|
||||
jsonMap.put("safe", "0");
|
||||
jsonMap.put("msgtype", "text");
|
||||
HashMap<String, String> text = new HashMap<>();
|
||||
// 刘亦菲
|
||||
//articles.put("thumb_media_id", "258F4sbTUwwHLRtKDDr4yqH2PzfYPlHPbOLCazHou_3JCgq7Dh1f9PMvrIaIv2oHk");
|
||||
// 李星云
|
||||
//articles.put("thumb_media_id", "2ES5cuBiuNKcbFp7RKsjebNM3joCIloIr1QWYwGS86SQzgG_7uxGrJpFlmuHXZl75");
|
||||
content = content.replaceAll("\\\\n", "<br/>");
|
||||
if (content.contains("\n")){
|
||||
content = content.replaceAll("\\n", "<br/>");
|
||||
}
|
||||
text.put("content",title + "<br/>" + content);
|
||||
|
||||
jsonMap.put("text", text);
|
||||
// 表示是否开启id转译,0表示否,1表示是,默认0
|
||||
jsonMap.put("enable id trans",1);
|
||||
String finalSendStr = JSON.toJSONString(jsonMap);
|
||||
//finalSendStr = finalSendStr.replaceAll("\\\\n", "<p></p>");
|
||||
|
||||
logger.info("发送的消息内容: \n" + finalSendStr);
|
||||
|
||||
String token = getToken(wxMessageType.getCorpid(), wxMessageType.getCorpsecret());
|
||||
//logger.info("获取的token"+token);
|
||||
if (StrUtil.isEmptyIfStr(token)) {
|
||||
throw new Exception();
|
||||
}
|
||||
String responseStr = HttpRequest.post(SEND + getToken(wxMessageType.getCorpid(), wxMessageType.getCorpsecret()))
|
||||
.body(finalSendStr)//头信息,多个头信息多次调用此方法即可
|
||||
.execute().body();
|
||||
logger.info("发送消息的响应: \n" + responseStr);
|
||||
|
||||
SendRespones sendRespones = JSON.parseObject(responseStr, SendRespones.class);
|
||||
if (sendRespones.getErrcode().equals(0)) {
|
||||
return "企业微信应用消息发送通知消息成功\uD83C\uDF89。";
|
||||
} else {
|
||||
return sendRespones.getErrmsg();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user