This commit is contained in:
雷欧(林平凡)
2025-09-04 17:54:18 +08:00
parent 204dae5860
commit c488e94534
2 changed files with 15 additions and 32 deletions

View File

@@ -191,7 +191,7 @@ public class WXController {
@RequestMapping(value = "/send/jd")
@ResponseBody
@RateLimiter(time = 5, count = 60)
@RateLimiter(time = 2, count = 1)
public R sendToJD(HttpServletRequest request, @RequestBody MessageRequest message) throws Exception {
logger.info("message 打印---{}",JSON.toJSONString(message));
String vanToken = request.getHeader("vanToken");
@@ -201,20 +201,7 @@ public class WXController {
if (!TokenUtil.checkToken(vanToken)) {
return R.error("vanToken无效");
}
String source = request.getHeader("source");
if (StrUtil.isEmpty(source)) {
return R.error("来源为空");
}
if (!StrUtil.isAllNotEmpty(message.getTitle(), message.getText())) {
return R.error("缺少标题和内容");
}
logger.info("vanToken 打印---{}",vanToken);
logger.info("source 打印---{}",source);
//String sourceForQL = SourceForQLUtil.transferSource(source);
if (!StrUtil.isAllNotEmpty(message.getTitle(), message.getText())) {
return R.error("缺少标题和内容");
}
String result = WxSendUtil.sendNotifyForText(message.getTitle(), message.getText(), message.getTouser(), WXMessageType.JD);
String result = WxSendUtil.sendNotifyForText(message.getText(), message.getTouser(), WXMessageType.JD);
logger.info("result 打印---{}",result);
return R.ok(result);

View File

@@ -40,7 +40,7 @@ public class WxSendUtil {
public static String getToken(String corpid, String corpsecret) {
String token = redisCache.getCacheObject(WX_ACCESS_TOKEN+corpsecret);
String token = redisCache.getCacheObject(WX_ACCESS_TOKEN + corpsecret);
if (StrUtil.isNotEmpty(token)) {
return token;
} else {
@@ -56,7 +56,7 @@ public class WxSendUtil {
if (ObjectUtil.isNotEmpty(responseStr)) {
GetTokenResponse response = JSON.parseObject(responseStr, GetTokenResponse.class);
if (response.getErrcode() == 0) {
redisCache.setCacheObject(WX_ACCESS_TOKEN+corpsecret, response.getAccess_token(), 7200, TimeUnit.SECONDS);
redisCache.setCacheObject(WX_ACCESS_TOKEN + corpsecret, response.getAccess_token(), 7200, TimeUnit.SECONDS);
return response.getAccess_token();
}
}
@@ -111,17 +111,17 @@ public class WxSendUtil {
// 李星云
articles.put("thumb_media_id", "2ES5cuBiuNKcbFp7RKsjebNM3joCIloIr1QWYwGS86SQzgG_7uxGrJpFlmuHXZl75");
String content = text.replaceAll("\\\\n", "<br/>");
if (content.contains("\n")){
if (content.contains("\n")) {
content = text.replaceAll("\\n", "<br/>");
}
articles.put("content",content);
articles.put("content", content);
//articles.put("content",text.replaceAll("\n", System.getProperty("line.separator")));
articlesList.add(articles);
HashMap<Object, Object> mpnews = new HashMap<>();
mpnews.put("articles", articlesList);
jsonMap.put("mpnews", mpnews);
// 表示是否开启id转译0表示否1表示是默认0
jsonMap.put("enable id trans",1);
jsonMap.put("enable id trans", 1);
String finalSendStr = JSON.toJSONString(jsonMap);
//finalSendStr = finalSendStr.replaceAll("\\\\n", "<p></p>");
@@ -146,23 +146,19 @@ 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不能为空";
}
public static String sendNotifyForText(String content, String touser, WXMessageType wxMessageType) throws Exception {
ArrayList<String> touserList = new ArrayList<>();
if (StringUtils.isNotEmpty(touser)) {
String[] split = touser.split(",");
touserList.addAll(Arrays.asList(split));
}
return sendNotifyForText(title, text, touserList, wxMessageType);
return sendNotifyForText(content, touserList, wxMessageType);
}
public static String sendNotifyForText(String title, String content, List<String> touser, WXMessageType wxMessageType) throws Exception {
public static String sendNotifyForText(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();
@@ -189,14 +185,14 @@ public class WxSendUtil {
// 李星云
//articles.put("thumb_media_id", "2ES5cuBiuNKcbFp7RKsjebNM3joCIloIr1QWYwGS86SQzgG_7uxGrJpFlmuHXZl75");
content = content.replaceAll("\\\\n", "<br/>");
if (content.contains("\n")){
if (content.contains("\n")) {
content = content.replaceAll("\\n", "<br/>");
}
text.put("content",title + "<br/>" + content);
text.put("content", content);
jsonMap.put("text", text);
// 表示是否开启id转译0表示否1表示是默认0
jsonMap.put("enable id trans",1);
jsonMap.put("enable id trans", 1);
String finalSendStr = JSON.toJSONString(jsonMap);
//finalSendStr = finalSendStr.replaceAll("\\\\n", "<p></p>");