mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-09-20 02:29:44 +08:00
# 368 增加 微信第三方平台 模块
* 增加 微信第三方平台 接口 * WxOpenXmlMessage 消息处理
This commit is contained in:
62
weixin-java-open/README.md
Normal file
62
weixin-java-open/README.md
Normal file
@@ -0,0 +1,62 @@
|
||||
消息机制未实现,下面为通知回调中设置的代码部分
|
||||
```
|
||||
@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());
|
||||
//wxOpenService.getWxOpenComponentService().getWxMpServiceByAppid(appId);
|
||||
return out;
|
||||
}
|
||||
}
|
||||
```
|
Reference in New Issue
Block a user