mirror of
http://git.coreshop.cn/jianweie/coreshoppro.git
synced 2025-12-06 17:43:26 +08:00
【优化】优化微信公众号服务器配置远程校验可能存在校验失败的问题。
This commit is contained in:
@@ -84,18 +84,33 @@ namespace CoreCms.Net.Web.Controllers.WeChat
|
||||
// 验证服务器推送
|
||||
// 文档:https://developers.weixin.qq.com/doc/offiaccount/Basic_Information/Access_Overview.html
|
||||
|
||||
NLogUtil.WriteFileLog(LogLevel.Info, LogType.WeChat, "GET接收到微信推送的数据", JsonConvert.SerializeObject(new
|
||||
var getModel = new
|
||||
{
|
||||
timestamp,
|
||||
nonce,
|
||||
signature,
|
||||
echoString
|
||||
}));
|
||||
};
|
||||
|
||||
var client = _weChatApiHttpClientFactory.CreateWeXinClient();
|
||||
var valid = client.VerifyEventSignatureForEcho(callbackTimestamp: timestamp, callbackNonce: nonce, callbackSignature: signature);
|
||||
|
||||
return Content(!valid ? "fail" : echoString);
|
||||
//NLogUtil.WriteFileLog(LogLevel.Info, LogType.WeChat, "GET接收到微信推送的数据", JsonConvert.SerializeObject(getModel));
|
||||
|
||||
//var client = _weChatApiHttpClientFactory.CreateWeXinClient();
|
||||
//var valid = client.VerifyEventSignatureForEcho(callbackTimestamp: timestamp, callbackNonce: nonce, callbackSignature: signature);
|
||||
|
||||
//return Content(!valid ? "fail" : echoString);
|
||||
|
||||
if (!CheckSignature.Check(signature, timestamp, nonce, _weChatOptions.WeiXinToken))
|
||||
{
|
||||
NLogUtil.WriteFileLog(LogLevel.Error, LogType.WeChat, "GET接收到微信推送的数据(签名错误)", JsonConvert.SerializeObject(getModel));
|
||||
return Content("fail");
|
||||
}
|
||||
else
|
||||
{
|
||||
NLogUtil.WriteFileLog(LogLevel.Info, LogType.WeChat, "GET接收到微信推送的数据(签名成功)", JsonConvert.SerializeObject(getModel));
|
||||
return Content(echoString);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user