|
|
@ -3,18 +3,11 @@ package com.tduck.cloud.api.web.controller; |
|
|
import lombok.AllArgsConstructor; |
|
|
import lombok.AllArgsConstructor; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import me.chanjar.weixin.mp.api.WxMpMessageRouter; |
|
|
import me.chanjar.weixin.mp.api.WxMpMessageRouter; |
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
|
|
import org.springframework.web.bind.annotation.GetMapping; |
|
|
|
|
|
import org.springframework.web.bind.annotation.PathVariable; |
|
|
|
|
|
import org.springframework.web.bind.annotation.PostMapping; |
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestBody; |
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping; |
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestParam; |
|
|
|
|
|
import org.springframework.web.bind.annotation.RestController; |
|
|
|
|
|
|
|
|
|
|
|
import me.chanjar.weixin.mp.api.WxMpService; |
|
|
import me.chanjar.weixin.mp.api.WxMpService; |
|
|
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage; |
|
|
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage; |
|
|
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage; |
|
|
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage; |
|
|
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
|
|
import org.springframework.web.bind.annotation.*; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* @author Binary Wang(https://github.com/binarywang)
|
|
|
* @author Binary Wang(https://github.com/binarywang)
|
|
|
@ -35,7 +28,7 @@ public class WxPortalController { |
|
|
@RequestParam(name = "echostr", required = false) String echostr) { |
|
|
@RequestParam(name = "echostr", required = false) String echostr) { |
|
|
|
|
|
|
|
|
log.info("\n接收到来自微信服务器的认证消息:[{}, {}, {}, {}]", signature, |
|
|
log.info("\n接收到来自微信服务器的认证消息:[{}, {}, {}, {}]", signature, |
|
|
timestamp, nonce, echostr); |
|
|
timestamp, nonce, echostr); |
|
|
if (StringUtils.isAnyBlank(signature, timestamp, nonce, echostr)) { |
|
|
if (StringUtils.isAnyBlank(signature, timestamp, nonce, echostr)) { |
|
|
throw new IllegalArgumentException("请求参数非法,请核实!"); |
|
|
throw new IllegalArgumentException("请求参数非法,请核实!"); |
|
|
} |
|
|
} |
|
|
@ -61,8 +54,8 @@ public class WxPortalController { |
|
|
@RequestParam(name = "encrypt_type", required = false) String encType, |
|
|
@RequestParam(name = "encrypt_type", required = false) String encType, |
|
|
@RequestParam(name = "msg_signature", required = false) String msgSignature) { |
|
|
@RequestParam(name = "msg_signature", required = false) String msgSignature) { |
|
|
log.info("\n接收微信请求:[openid=[{}], [signature=[{}], encType=[{}], msgSignature=[{}]," |
|
|
log.info("\n接收微信请求:[openid=[{}], [signature=[{}], encType=[{}], msgSignature=[{}]," |
|
|
+ " timestamp=[{}], nonce=[{}], requestBody=[\n{}\n] ", |
|
|
+ " timestamp=[{}], nonce=[{}], requestBody=[\n{}\n] ", |
|
|
openid, signature, encType, msgSignature, timestamp, nonce, requestBody); |
|
|
openid, signature, encType, msgSignature, timestamp, nonce, requestBody); |
|
|
|
|
|
|
|
|
if (!this.wxService.switchover(appid)) { |
|
|
if (!this.wxService.switchover(appid)) { |
|
|
throw new IllegalArgumentException(String.format("未找到对应appid=[%s]的配置,请核实!", appid)); |
|
|
throw new IllegalArgumentException(String.format("未找到对应appid=[%s]的配置,请核实!", appid)); |
|
|
@ -85,7 +78,7 @@ public class WxPortalController { |
|
|
} else if ("aes".equalsIgnoreCase(encType)) { |
|
|
} else if ("aes".equalsIgnoreCase(encType)) { |
|
|
// aes加密的消息
|
|
|
// aes加密的消息
|
|
|
WxMpXmlMessage inMessage = WxMpXmlMessage.fromEncryptedXml(requestBody, wxService.getWxMpConfigStorage(), |
|
|
WxMpXmlMessage inMessage = WxMpXmlMessage.fromEncryptedXml(requestBody, wxService.getWxMpConfigStorage(), |
|
|
timestamp, nonce, msgSignature); |
|
|
timestamp, nonce, msgSignature); |
|
|
log.debug("\n消息解密后内容为:\n{} ", inMessage.toString()); |
|
|
log.debug("\n消息解密后内容为:\n{} ", inMessage.toString()); |
|
|
WxMpXmlOutMessage outMessage = this.route(inMessage); |
|
|
WxMpXmlOutMessage outMessage = this.route(inMessage); |
|
|
if (outMessage == null) { |
|
|
if (outMessage == null) { |
|
|
|