Commit 61769241 authored by 吴春's avatar 吴春

1

parent 9778b549
...@@ -291,5 +291,34 @@ namespace Mall.Common.Pay.WeChatPat ...@@ -291,5 +291,34 @@ namespace Mall.Common.Pay.WeChatPat
} }
return wx; return wx;
} }
/// <summary>
/// 验证微信签名
/// * 将token、timestamp、nonce三个参数进行字典序排序
/// * 将三个参数字符串拼接成一个字符串进行sha1加密
/// * 开发者获得加密后的字符串可与signature对比,标识该请求来源于微信。
/// </summary>
/// <param name="signature"></param>
/// <param name="timestamp"></param>
/// <param name="nonce"></param>
/// <param name="_token"></param>
/// <returns></returns>
[Obsolete]
public static bool CheckSignature(string signature, string timestamp, string nonce, string _token)
{
return false;
//var vs = new[] { timestamp, nonce, _token }.OrderBy(s => s);
//var str = string.Join("", vs);
//var tmpStr = FormsAuthentication.HashPasswordForStoringInConfigFile(str, "SHA1");
//tmpStr = tmpStr.ToLower();
//Plugin.LogHelper.Write("tmpStr:" + tmpStr + ",_token:" + _token);
//if (tmpStr == null)
//{
// return false;
//}
//return tmpStr.Equals(signature, StringComparison.CurrentCultureIgnoreCase);
}
} }
} }
...@@ -539,10 +539,13 @@ namespace Mall.WebApi.Controllers.AppletWeChat ...@@ -539,10 +539,13 @@ namespace Mall.WebApi.Controllers.AppletWeChat
/// <returns></returns> /// <returns></returns>
[HttpPost] [HttpPost]
[HttpGet] [HttpGet]
public void EventMessageCall(int MallBaseId, int TenantId, string signature, string echostr, string timestamp, string nonce, string openid, string encrypt_type, string msg_signature) public string EventMessageCall(int MallBaseId, int TenantId, string signature, string echostr, string timestamp, string nonce, string openid, string encrypt_type, string msg_signature)
{ {
LogHelper.WriteInfo("我进来了参数如下[MallBaseId:" + MallBaseId+ ",TenantId:"+ TenantId + ",TenantId:" + signature + ",signature:" + signature + ",echostr:" + echostr + ",timestamp:" + timestamp + ",nonce:" + nonce + ",openid:" + openid + ",encrypt_type:" + encrypt_type + ",msg_signature:" + msg_signature);
var req = new RequestHandler();
try try
{ {
int qrCodeType = 0; int qrCodeType = 0;
int userId = 0; int userId = 0;
string textpl = ""; string textpl = "";
...@@ -551,35 +554,42 @@ namespace Mall.WebApi.Controllers.AppletWeChat ...@@ -551,35 +554,42 @@ namespace Mall.WebApi.Controllers.AppletWeChat
string sAppID = "wxaeb077c07ed6f30d"; string sAppID = "wxaeb077c07ed6f30d";
string sEncodingAESKey = "9FgR0wMXxe6wXBB5hwgpn2mZM6sQMi3E3Vk5sxrXEAL"; string sEncodingAESKey = "9FgR0wMXxe6wXBB5hwgpn2mZM6sQMi3E3Vk5sxrXEAL";
var request = _accessor.HttpContext.Request; var request = _accessor.HttpContext.Request;
LogHelper.Write("我是回调方法:EventMessageCall" + "请求方式:" + request.Method);
if (request.Method == "GET")
{
//WXBizMsgCrypt.CheckSignature(signature, timestamp, nonce, sToken);
}
// var inputStream = request.Body; // var inputStream = request.Body;
var str = new StreamReader(request.Body); var str = new StreamReader(request.Body);
string postStr = str.ReadToEnd(); string postStr = str.ReadToEnd();
LogHelper.Write("我是返回信息:" + postStr); LogHelper.Write("我是返回信息:" + postStr);
lock (_lock) lock (_lock)
{ {
WechatMessage wx = WXBizMsgCrypt.GetWxMessage(postStr, timestamp, nonce, signature, encrypt_type, msg_signature, openid); if (!string.IsNullOrWhiteSpace(postStr))
if (!string.IsNullOrWhiteSpace(wx.EventKey))// 用户未关注时,进行关注后的事件推送;事件KEY值,qrscene_为前缀,后面为二维码的参数值
{ {
textpl = ReceivedText(wx.FromUserName, wx.ToUserName, content); WechatMessage wx = WXBizMsgCrypt.GetWxMessage(postStr, timestamp, nonce, signature, encrypt_type, msg_signature, openid);
if (encrypt_type.ToLower() == "aes".ToLower())//加密模式需要先解密 if (!string.IsNullOrWhiteSpace(wx.MsgType))// 用户未关注时,进行关注后的事件推送;事件KEY值,qrscene_为前缀,后面为二维码的参数值
{ {
var ret = new WXBizMsgCrypt(sToken, sEncodingAESKey, sAppID); textpl = ReceivedText(wx.FromUserName, wx.ToUserName, content);
int r = ret.EncryptMsg(textpl, timestamp, nonce, ref textpl); if (encrypt_type.ToLower() == "aes".ToLower())//加密模式需要先解密
if (r != 0)
{ {
LogHelper.WriteInfo("GetWxMessage_消息加密失败:"); var ret = new WXBizMsgCrypt(sToken, sEncodingAESKey, sAppID);
textpl = ""; int r = ret.EncryptMsg(textpl, timestamp, nonce, ref textpl);
if (r != 0)
{
LogHelper.WriteInfo("GetWxMessage_消息加密失败:");
textpl = "";
}
} }
} }
} }
} }
} }
catch (Exception ex) catch (Exception ex)
{ {
LogHelper.Write(ex.ToString()); LogHelper.Write(ex.ToString());
} }
return echostr ?? "echostr is null";
} }
/// <summary> /// <summary>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment