æ¶æ¯æºå¶æªå®ç°ï¼ä¸é¢ä¸ºéç¥åè°ä¸è®¾ç½®ç代ç é¨å 以ä¸ä»£ç å¯éè¿è ¾è®¯å ¨ç½å叿µè¯ç¨ä¾ ``` @RestController @RequestMapping("notify") public class NotifyController extends WechatThridBaseController { @Autowired protected WxOpenServiceDemo wxOpenService; @RequestMapping("receive_ticket") public Object receiveTicket(@RequestBody(required = false) String requestBody, @RequestParam("timestamp") String timestamp, @RequestParam("nonce") String nonce, @RequestParam("signature") String signature, @RequestParam(name = "encrypt_type", required = false) String encType, @RequestParam(name = "msg_signature", required = false) String msgSignature) { this.logger.info( "\næ¥æ¶å¾®ä¿¡è¯·æ±ï¼[signature=[{}], encType=[{}], msgSignature=[{}]," + " timestamp=[{}], nonce=[{}], requestBody=[\n{}\n] ", signature, encType, msgSignature, timestamp, nonce, requestBody); if (!StringUtils.equalsIgnoreCase("aes", encType) || !wxOpenService.getWxOpenComponentService().checkSignature(timestamp, nonce, signature)) { throw new IllegalArgumentException("éæ³è¯·æ±ï¼å¯è½å±äºä¼ªé ç请æ±ï¼"); } // aeså å¯çæ¶æ¯ WxOpenXmlMessage inMessage = WxOpenXmlMessage.fromEncryptedXml(requestBody, wxOpenService.getWxOpenConfigStorage(), timestamp, nonce, msgSignature); this.logger.debug("\næ¶æ¯è§£å¯åå 容为ï¼\n{} ", inMessage.toString()); String out = null; try { out = wxOpenService.getWxOpenComponentService().route(inMessage); } catch (WxErrorException e) { throw new ResponseException(ErrorCodeEnum.ERROR, e); } this.logger.debug("\nç»è£ åå¤ä¿¡æ¯ï¼{}", out); return out; } @RequestMapping("{appId}/callback") public Object callback(@RequestBody(required = false)String requestBody, @PathVariable ("appId") String appId, @RequestParam("signature") String signature, @RequestParam("timestamp") String timestamp, @RequestParam("nonce") String nonce, @RequestParam("openid") String openid, @RequestParam("encrypt_type") String encType, @RequestParam("msg_signature") String msgSignature) { this.logger.info( "\næ¥æ¶å¾®ä¿¡è¯·æ±ï¼[appId=[{}], openid=[{}], signature=[{}], encType=[{}], msgSignature=[{}]," + " timestamp=[{}], nonce=[{}], requestBody=[\n{}\n] ", appId, openid, signature, encType, msgSignature, timestamp, nonce, requestBody); logger.info("query:"+getHttpServletRequest().getQueryString()+"\nbody:"+requestBody); if (!StringUtils.equalsIgnoreCase("aes", encType) || !wxOpenService.getWxOpenComponentService().checkSignature(timestamp, nonce, signature)) { throw new IllegalArgumentException("éæ³è¯·æ±ï¼å¯è½å±äºä¼ªé ç请æ±ï¼"); } String out = ""; // aeså å¯çæ¶æ¯ WxMpXmlMessage inMessage = WxOpenXmlMessage.fromEncryptedMpXml(requestBody, wxOpenService.getWxOpenConfigStorage(), timestamp, nonce, msgSignature); this.logger.debug("\næ¶æ¯è§£å¯åå 容为ï¼\n{} ", inMessage.toString()); // å ¨ç½å叿µè¯ç¨ä¾ if (StringUtils.equalsAnyIgnoreCase(appId, "wxd101a85aa106f53e", "wx570bc396a51b8ff8")) { try { if (StringUtils.equals(inMessage.getMsgType(), "text")) { if (StringUtils.equals(inMessage.getContent(), "TESTCOMPONENT_MSG_TYPE_TEXT")) { out = new WxOpenCryptUtil(wxOpenService.getWxOpenConfigStorage()).encrypt( WxMpXmlOutMessage.TEXT().content("TESTCOMPONENT_MSG_TYPE_TEXT_callback") .fromUser(inMessage.getToUser()) .toUser(inMessage.getFromUser()) .build() .toXml() ); } else if (StringUtils.startsWith(inMessage.getContent(), "QUERY_AUTH_CODE:")) { String msg = inMessage.getContent().replace("QUERY_AUTH_CODE:", "") + "_from_api"; WxMpKefuMessage kefuMessage = WxMpKefuMessage.TEXT().content(msg).toUser(inMessage.getFromUser()).build(); wxOpenService.getWxOpenComponentService().getWxMpServiceByAppid(appId).getKefuService().sendKefuMessage(kefuMessage); } } else if (StringUtils.equals(inMessage.getMsgType(), "event")) { WxMpKefuMessage kefuMessage = WxMpKefuMessage.TEXT().content(inMessage.getEvent() + "from_callback").toUser(inMessage.getFromUser()).build(); wxOpenService.getWxOpenComponentService().getWxMpServiceByAppid(appId).getKefuService().sendKefuMessage(kefuMessage); } } catch (WxErrorException e) { logger.error("callback", e); } } return out; } } ```