设置以下内容
服务器设置
设置完成后,先不要点击提交
public static WechatApiClient GetWechatApiClient()
{
MpEntity defaultMpEntity = MpEntity.GetDefault();
var options = new WechatApiClientOptions()
{
AppId = defaultMpEntity.AppId,
AppSecret = defaultMpEntity.AppSecret,
PushToken = defaultMpEntity.Token
};
var client = new WechatApiClient(options);
return client;
}
MpEntity 是业务上的数据,主要定义,AppId, AppSecret, Token等微信公众号的基本信息
MpEntity定义如下
对应的Url是 https://www.xx.com/mp/check 这样的控制器代码
///
/// 验证微信服务器配置
///
///
public IActionResult Check()
{
WechatApiClient wechatApiClient = SourceCodeWebPlugInService.GetWechatApiClient();
//得到当前请求的方法
String curMethod = Request.Method.ToLower();
LogHelper.WriteLog(#34;请求方法:{curMethod},url:{RequestHelper.Url()}");
if (curMethod == "get")
{
//如果是get方法只有订阅号过来,其他都是Post
//得到订阅号服务提交的url参数
string signature = Request.Get("signature");
string timestamp = Request.Get("timestamp");
string nonce = Request.Get("nonce");
string echostr = Request.Get("echostr");
LogHelper.WriteLog("订阅号请求的url" + RequestHelper.Url());
try
{
bool isCheck = wechatApiClient.VerifyEventSignatureForEcho(timestamp, nonce, signature);
if (isCheck)
{
return Content(echostr);
}
}
catch (Exception ex)
{
LogHelper.WriteLog("公众号服务器验证异常" + ex.Message);
}
}
else
{
//对消息等进行回复
}
return Content("无响应");
}
//如果是get方法只有订阅号过来,其他都是Post
//得到订阅号服务提交的url参数
http://www.xxxx.com/mp/check?signature=39c6aa7beeefecc47d2457425b5b1e56ba3fdf&echostr=66071ee623693343322 tamp=1661119432&nonce=1443728737
https://developers.weixin.qq.com/doc/offiaccount/Basic_Information/Access_Overview.html
页面更新:2024-05-17
本站资料均由网友自行发布提供,仅用于学习交流。如有版权问题,请与我联系,QQ:4156828
© CopyRight 2008-2024 All Rights Reserved. Powered By bs178.com 闽ICP备11008920号-3
闽公网安备35020302034844号