From 82dc0771b951cb4381146d217a93c5b71a3932b7 Mon Sep 17 00:00:00 2001
From: BAOLH <baolh@yhzhg.cn>
Date: Wed, 06 Aug 2025 05:23:42 +0000
Subject: [PATCH] 智能机器人回调API修改
---
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/temp/service/impl/WechatRobotServiceImpl.java | 13 +++++++++++--
1 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/temp/service/impl/WechatRobotServiceImpl.java b/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/temp/service/impl/WechatRobotServiceImpl.java
index 85db8db..c0d0a37 100644
--- a/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/temp/service/impl/WechatRobotServiceImpl.java
+++ b/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/temp/service/impl/WechatRobotServiceImpl.java
@@ -3,6 +3,7 @@
import com.alibaba.fastjson.JSONObject;
import lombok.RequiredArgsConstructor;
import me.zhengjie.modules.temp.service.WechatRobotService;
+import me.zhengjie.utils.weixin.AesException;
import me.zhengjie.utils.weixin.WXBizJsonMsgCrypt;
import org.springframework.stereotype.Service;
@@ -42,8 +43,9 @@
@Override
public Object handleRobotCallback(String msgSignature, String timestamp, String nonce, HttpServletRequest request, HttpServletResponse response) {
+ WXBizJsonMsgCrypt wxcpt = null;
try {
- WXBizJsonMsgCrypt wxcpt = new WXBizJsonMsgCrypt(TOKEN, ENCODING_AES_KEY, CORP_ID);
+ wxcpt = new WXBizJsonMsgCrypt(TOKEN, ENCODING_AES_KEY, CORP_ID);
// 读取回调数据
StringBuilder sb = new StringBuilder();
BufferedReader reader = new BufferedReader(new InputStreamReader(request.getInputStream()));
@@ -55,13 +57,20 @@
String callbackData = sb.toString();
JSONObject jsonObject = JSONObject.parseObject(callbackData);
- String decryptedMessage = wxcpt.DecryptMsg(msgSignature, timestamp, nonce, jsonObject.toString());
+ String decryptedMessage = wxcpt.DecryptRobotMsg(msgSignature, timestamp, nonce, jsonObject.toString());
System.out.println("接收到机器人发送的加密消息:" + jsonObject.toJSONString());
System.out.println("接收到机器人发送的解密后消息:" + decryptedMessage);
return wxcpt.EncryptMsg("消息已收到", "", nonce);
} catch (Exception e) {
e.printStackTrace();
+ try {
+ if (wxcpt != null) {
+ return wxcpt.EncryptMsg("消息接收出现异常,请联系管理员处理 o(╥﹏╥o...)", "", nonce);
+ }
+ } catch (AesException aesException) {
+ aesException.printStackTrace();
+ }
}
return null;
--
Gitblit v1.9.3