mirror of
http://git.coreshop.cn/jianweie/coreshoppro.git
synced 2025-12-06 18: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
|
// 文档: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,
|
timestamp,
|
||||||
nonce,
|
nonce,
|
||||||
signature,
|
signature,
|
||||||
echoString
|
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>
|
/// <summary>
|
||||||
@@ -271,7 +286,7 @@ namespace CoreCms.Net.Web.Controllers.WeChat
|
|||||||
var userInfo = await _weChatUserInfoServices.QueryByClauseAsync(p => p.openid == eventModel.FromUserName);
|
var userInfo = await _weChatUserInfoServices.QueryByClauseAsync(p => p.openid == eventModel.FromUserName);
|
||||||
if (userInfo == null)
|
if (userInfo == null)
|
||||||
{
|
{
|
||||||
|
|
||||||
userInfo = new Model.Entities.CoreCmsUserWeChatInfo()
|
userInfo = new Model.Entities.CoreCmsUserWeChatInfo()
|
||||||
{
|
{
|
||||||
isSubscribe = response.IsSubscribed,
|
isSubscribe = response.IsSubscribed,
|
||||||
|
|||||||
Reference in New Issue
Block a user