在视频号管理后台配置的服务器地址是个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";
}
上面一个接口可以配置在店铺里面,但是仅仅是做了验签;下面一个接口有业务逻辑,但是没法配置在店铺管理里面。
你好请问这个回调,是针对那个功能回调呀,关注视频号能回调吗
用户进注小店能回调吗
解决了,用同一个url,请求方式一个用GET,另一个用POST。GET请求只包含验证url的逻辑,POST请求写业务逻辑。
@GetMapping("/wechatChannel/callback") 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); String sign = SignUtils.callbackSign(Lists.newArrayList(strings)); if(sign.equals(signature)){ return Long.valueOf(echostr); } return 0L; } @PostMapping("/wechatChannel/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; } if(data != null){ if(WechatChannelEventTypeEnum.PAY_SUCCESS.getEvent().equals(data.getEvent())){ wechatChannelService.orderPaySuccessCallback(data); } } return "success"; }