1.问题截图
2.测试回调模式成功
测试回调模式地址https://open.work.weixin.qq.com/wwopen/devtool/interface/combine,建立连接 => 测试回调模式
3.解决
测试回调成功,但是发现返回结果带了引号,可能是导致回调不成功原因。下面代码为错误示范。
[HttpGet, Route("callback/interAspect")] public IActionResult ReveiceMsg(string msg_signature,string timestamp,string nonce,string echostr) { //验证 WXBizMsgCrypt wxcpt = new WXBizMsgCrypt(AppSetting.Configuration["Wx:CallBackToken"] , AppSetting.Configuration["Wx:EncodingAESKey"] , AppSetting.Configuration["Wx:corpid"]); int ret = 0; string sEchoStr = ""; ret = wxcpt.VerifyURL(msg_signature, timestamp, nonce, echostr, ref sEchoStr); if (ret != 0) { return Json(null); } return Json(sEchoStr); }
返回值调整为ContentResult 或者string 后测试成功。
[HttpGet, Route("callback/interAspect")] public ContentResult ReveiceMsg(string msg_signature,string timestamp,string nonce,string echostr) { //验证 WXBizMsgCrypt wxcpt = new WXBizMsgCrypt(AppSetting.Configuration["Wx:CallBackToken"] , AppSetting.Configuration["Wx:EncodingAESKey"] , AppSetting.Configuration["Wx:corpid"]); int ret = 0; string sEchoStr = ""; ret = wxcpt.VerifyURL(msg_signature, timestamp, nonce, echostr, ref sEchoStr); if (ret != 0) { return Content(null); } return Content(sEchoStr); }
最后成功保存
服务端加解密库: https://developer.work.weixin.qq.com/tool#/tab/invoke/source
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持阿兔在线工具。