BAOLH
2025-08-25 fca07751d3905b9e67bc20bd83a7893ee3b88137
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,22 @@
            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);
            JSONObject decryptedMessageJson =  JSONObject.parseObject(decryptedMessage);
            if (decryptedMessageJson.getString("msgtype").equals("text")) {
                return wxcpt.EncryptRobotMsg("消息已收到", "", nonce);
            }
        } catch (Exception e) {
            e.printStackTrace();
            try {
                if (wxcpt != null) {
                    return wxcpt.EncryptRobotMsg("消息接收出现异常,请联系管理员处理 o(╥﹏╥o...)", "", nonce);
                }
            } catch (AesException aesException) {
                aesException.printStackTrace();
            }
        }
        return null;