其他分享
首页 > 其他分享> > .NET Core 企业微信openapi回调地址请求不通过

.NET Core 企业微信openapi回调地址请求不通过

作者:互联网

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

 

标签:Core,sEchoStr,Wx,微信,ret,openapi,AppSetting,Configuration,string
来源: https://www.cnblogs.com/zspwf/p/16381688.html