Commit 73d671c3 authored by 黄奎's avatar 黄奎

页面修改

parent 844518af
......@@ -34,63 +34,85 @@ namespace Mall.WebApi.Controllers.Adapay
[HttpGet]
public string CheckSignature(string echostr, string signature, string timestamp, string nonce)
{
Tencent.WXBizMsgCrypt wxcpt = new Tencent.WXBizMsgCrypt(token, aes, appId);
string sVerifyMsgSig = signature;
string sVerifyTimeStamp = timestamp;
string sVerifyNonce = nonce;
string sVerifyEchoStr = echostr;
string sEchoStr = "";
int ret = wxcpt.VerifySignature(token, sVerifyTimeStamp, sVerifyNonce, sVerifyEchoStr, sVerifyMsgSig);
if (ret != 0)
string query = string.Format("echostr:{0} signature:{1} timestamp:{2} nonce:{3}", echostr, signature, timestamp, nonce);
Common.Plugin.LogHelper.Write("CheckSignature_Query:: " + query);
string[] ArrTmp = { token, timestamp, nonce };
Array.Sort(ArrTmp);
string tmpStr = string.Join("", ArrTmp);
Common.Plugin.LogHelper.Write("CheckSignature_tmpStr:: " + tmpStr);
SHA1 sha;
string hash = "";
try
{
Common.Plugin.LogHelper.Write("验证Url失败:" + ret);
Common.Plugin.LogHelper.Write("CheckSignature_hash:: 11" );
sha = new SHA1CryptoServiceProvider();
Common.Plugin.LogHelper.Write("CheckSignature_hash:: 22");
byte[] dataToHash = Encoding.UTF8.GetBytes(tmpStr);
Common.Plugin.LogHelper.Write("CheckSignature_hash:: 33");
byte[] dataHashed = sha.ComputeHash(dataToHash);
Common.Plugin.LogHelper.Write("CheckSignature_hash:: 44");
hash = BitConverter.ToString(dataHashed).Replace("-", "");
Common.Plugin.LogHelper.Write("CheckSignature_hash:: 55");
hash = hash.ToLower();
}
return sEchoStr;
catch (Exception ex)
{
Common.Plugin.LogHelper.Write(ex, "CheckSignature");
}
/// <summary>
/// 接收客服消息
/// </summary>
/// <returns></returns>
[HttpPost]
public async Task<HttpResponseMessage> wx()
Common.Plugin.LogHelper.Write("CheckSignature_hash:: " + hash);
Common.Plugin.LogHelper.Write("CheckSignature_signature:: " + signature);
if (hash == signature)
{
return echostr;
}
return "";
}
//var content = await Request.Content.ReadAsStringAsync();
HttpResponseMessage responseMessage = new HttpResponseMessage();
return responseMessage;
}
/// <summary>
/// 验证微信签名
/// 接口认证
/// </summary>
private bool CheckSignatureModule(string token, string signature, string timestamp, string nonce)
/// <param name="echostr"></param>
/// <param name="signature"></param>
/// <param name="timestamp"></param>
/// <param name="nonce"></param>
/// <returns></returns>
[HttpPost]
public string CheckSignature(string signature, string timestamp, string nonce)
{
string query = string.Format("echostr1:signature:{1} timestamp:{2} nonce:{3}", signature, timestamp, nonce);
Common.Plugin.LogHelper.Write("CheckSignature_Query1:: " + query);
string[] ArrTmp = { token, timestamp, nonce };
Array.Sort(ArrTmp);
string tmpStr = string.Join("", ArrTmp);
var data = SHA1.Create().ComputeHash(Encoding.UTF8.GetBytes(tmpStr));
Common.Plugin.LogHelper.Write("data:" + data);
var sb = new StringBuilder();
foreach (var t in data)
Common.Plugin.LogHelper.Write("CheckSignature_tmpStr:: " + tmpStr);
SHA1 sha;
string hash = "";
try
{
sb.Append(t.ToString("X2"));
Common.Plugin.LogHelper.Write("CheckSignature_hash:: 11");
sha = new SHA1CryptoServiceProvider();
Common.Plugin.LogHelper.Write("CheckSignature_hash:: 22");
byte[] dataToHash = Encoding.UTF8.GetBytes(tmpStr);
Common.Plugin.LogHelper.Write("CheckSignature_hash:: 33");
byte[] dataHashed = sha.ComputeHash(dataToHash);
Common.Plugin.LogHelper.Write("CheckSignature_hash:: 44");
hash = BitConverter.ToString(dataHashed).Replace("-", "");
Common.Plugin.LogHelper.Write("CheckSignature_hash:: 55");
hash = hash.ToLower();
}
tmpStr = sb.ToString();
tmpStr = tmpStr.ToLower();
if (tmpStr == signature)
catch (Exception ex)
{
return true;
Common.Plugin.LogHelper.Write(ex, "CheckSignature");
}
else
Common.Plugin.LogHelper.Write("CheckSignature_hash:: " + hash);
Common.Plugin.LogHelper.Write("CheckSignature_signature:: " + signature);
if (hash == signature)
{
return false;
return echostr;
}
return "";
}
}
}
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