如何接收视频号订单的回调信息?
[图片] 在视频号管理后台配置的服务器地址是个get请求,为了验证数据的,我参考的是https://developers.weixin.qq.com/doc/channels/API/basics/message_push.html 这篇文档,这个接口要通的话返回的是入参中的echostr,将这个接口配置在图中“服务器地址”处是能成功的。但是回调接口的文档是https://developers.weixin.qq.com/doc/channels/API/order/callback/channels_ec_order_cancel.html,无论是参数还是响应都和上述文档不一样,而且无法将这个回调逻辑的地址配置在“服务器地址”处。那么我的业务逻辑该写在哪个接口呢? @GetMapping("/wechatChannel/callback/validation")
public Long wechatChannelOrderCallbackValidation(@RequestParam String signature,
@RequestParam String timestamp,
@RequestParam String nonce,
@RequestParam String echostr
) {
String[] strings = {WECHAT_CHANNEL_ORDER_CALLBACK_TOKEN, timestamp, nonce};
// 使用Arrays.sort方法和Comparator进行字典排序
Arrays.sort(strings);
log.info("字典排序后的参数{}", JSON.toJSONString(strings));
String sign = SignUtils.callbackSign(Lists.newArrayList(strings));
log.info("视频号回调签名:{},{},{}", sign, signature, sign.equals(signature));
if(sign.equals(signature)){
return Long.valueOf(echostr);
}
return 0L;
}
@PostMapping("/wechatChannel/paySuccess/callback")
public String wechatChannelOrderPaySuccessCallback(@RequestParam String signature,
@RequestParam String timestamp,
@RequestParam String nonce,
@RequestParam(required = false) String openid,
@RequestParam(required = false, defaultValue = "aes") String encrypt_type,
@RequestParam String msg_signature,
@RequestBody WechatChannelOrderPaySuccessCallbackRequest request) throws AesException {
log.info("收到视频号消息推送,参数:{},appId:{}, {}, {}", JSON.toJSONString(request), request.getToUserName(), appId, request.getToUserName().equals(appId));
WXBizJsonMsgCrypt wxcpt = new WXBizJsonMsgCrypt(WECHAT_CHANNEL_ORDER_CALLBACK_TOKEN, WECHAT_CHANNEL_ORDER_CALLBACK_ENCODING_AES_KEY, appId);
WechatChannelOrderPaySuccessCallbackData data = null;
try {
String sMsg = wxcpt.DecryptMsg(msg_signature, timestamp, nonce, JSON.toJSONString(request));
log.info("视频号订单回调,解密出的参数为:{}", sMsg);
JSONObject jsonObject = JSON.parseObject(sMsg, JSONObject.class);
String debugStr = jsonObject.getString("debug_str");
data = JSON.parseObject(debugStr, WechatChannelOrderPaySuccessCallbackData.class);
} catch (Exception e) {
log.error("视频号订单支付完成回调解析参数失败,参数:{}", JSON.toJSONString(request), e);
return Constants.FAIL;
}
try{
if(data != null){
if(WechatChannelEventTypeEnum.PAY_SUCCESS.getEvent().equals(data.getEvent())){
wechatChannelService.orderPaySuccessCallback(data);
}
}
} catch(Exception e){
log.error("视频号订单支付完成回调失败", e);
}
return "success";
} 上面一个接口可以配置在店铺里面,但是仅仅是做了验签;下面一个接口有业务逻辑,但是没法配置在店铺管理里面。