| | |
| | | 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; |
| | | |
| | |
| | | |
| | | @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())); |
| | |
| | | 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; |