BAOLH
2025-09-19 ef18b51d7f5c89f0e45910d52c3c8f53a9cbf47d
智能机器人回调API修改
2 files modified
26 ■■■■■ changed files
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/temp/service/impl/WechatRobotServiceImpl.java 24 ●●●●● patch | view | raw | blame | history
eladmin-master/eladmin-system/src/main/java/me/zhengjie/utils/weixin/WXBizJsonMsgCrypt.java 2 ●●●●● patch | view | raw | blame | history
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/temp/service/impl/WechatRobotServiceImpl.java
@@ -21,6 +21,7 @@
    private final String TOKEN = "WTAgLRQif";
    private final String ENCODING_AES_KEY = "w2FEuoDg2D7DxnmJn4DL6YiD47OSHwB34WXVwa2eriY";
    private final String APPROVAL_AGENT_ID = "1000005";
    private final String ROBOT_ID = "aiboW1Wpr5Mg_9WNlzyBtIjtf-ETL6pTEFd";
    @Override
    public void robotBack(String msgSignature, String timestamp, String nonce, String echostr, HttpServletResponse response) {
@@ -64,8 +65,29 @@
            System.out.println("接收到机器人发送的消息是否存在msgtype:" + decryptedMessageJson.containsKey("msgtype"));
            if (decryptedMessageJson.getString("msgtype").equals("text")) {
                System.out.println("接收到机器人发送的消息中的msgtype:" + decryptedMessageJson.getString("msgtype"));
                // 第一版
//                return wxcpt.EncryptRobotMsg("{\"msgtype\": \"text\",\"text\": {\"content\": \"消息已收到\"}}", "", nonce);
                return wxcpt.EncryptRobotJsonMsg("{\"msgtype\": \"text\",\"text\": {\"content\": \"消息已收到\"}}", "", nonce);
                // 第二版
//                return wxcpt.EncryptRobotJsonMsg("{\"msgtype\": \"text\",\"text\": {\"content\": \"消息已收到\"}}", "", nonce);
                // 第三版
//                JSONObject responseJson = wxcpt.EncryptRobotJsonMsg("{\"msgtype\": \"text\",\"text\": {\"content\": \"消息已收到\"}}", "", nonce);
//                // 设置HTTP响应头并返回JSON
//                response.setContentType("application/json;charset=utf-8");
//                PrintWriter out = response.getWriter();
//                out.print(responseJson.toJSONString());
//                out.flush();
//                out.close();
                // 第四版
                String replyPlainText = "{\"msgtype\": \"text\",\"text\": {\"content\": \"消息已收到\"}}";
                String finalResponseJson = wxcpt.EncryptRobotMsg(replyPlainText, timestamp, nonce);
                // 设置HTTP响应头并直接返回结果
                response.setContentType("application/json;charset=utf-8");
                PrintWriter out = response.getWriter();
                out.print(finalResponseJson);
                out.flush();
                out.close();
                return null;
            }
        } catch (Exception e) {
            e.printStackTrace();
eladmin-master/eladmin-system/src/main/java/me/zhengjie/utils/weixin/WXBizJsonMsgCrypt.java
@@ -349,7 +349,7 @@
        // 生成发送的json'''
        JSONObject json = new JSONObject();
        json.put("encrypt", encrypt);
        json.put("msgsignature", signature);
        json.put("msg_signature", signature);
        json.put("timestamp", timeStamp);
        json.put("nonce", nonce);
        return json;