From c488e94534c6a0aec4d20303230b9d2a428247e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=B7=E6=AC=A7=EF=BC=88=E6=9E=97=E5=B9=B3=E5=87=A1?= =?UTF-8?q?=EF=BC=89?= Date: Thu, 4 Sep 2025 17:54:18 +0800 Subject: [PATCH] 1 --- .../business/controller/WXController.java | 17 ++--------- .../cn/van333/wxsend/util/WxSendUtil.java | 30 ++++++++----------- 2 files changed, 15 insertions(+), 32 deletions(-) diff --git a/src/main/java/cn/van333/wxsend/business/controller/WXController.java b/src/main/java/cn/van333/wxsend/business/controller/WXController.java index dfe02bc..d61c6b8 100644 --- a/src/main/java/cn/van333/wxsend/business/controller/WXController.java +++ b/src/main/java/cn/van333/wxsend/business/controller/WXController.java @@ -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); diff --git a/src/main/java/cn/van333/wxsend/util/WxSendUtil.java b/src/main/java/cn/van333/wxsend/util/WxSendUtil.java index 78f2c68..f179471 100644 --- a/src/main/java/cn/van333/wxsend/util/WxSendUtil.java +++ b/src/main/java/cn/van333/wxsend/util/WxSendUtil.java @@ -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", "
"); - if (content.contains("\n")){ + if (content.contains("\n")) { content = text.replaceAll("\\n", "
"); } - articles.put("content",content); + articles.put("content", content); //articles.put("content",text.replaceAll("\n", System.getProperty("line.separator"))); articlesList.add(articles); HashMap 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", "

"); @@ -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 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 touser, WXMessageType wxMessageType) throws Exception { + public static String sendNotifyForText(String content, List touser, WXMessageType wxMessageType) throws Exception { - if (!StrUtil.isAllNotEmpty(title, content)) { - return "title,text不能为空!"; - } HashMap 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", "
"); - if (content.contains("\n")){ + if (content.contains("\n")) { content = content.replaceAll("\\n", "
"); } - text.put("content",title + "
" + 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", "

");