验证签名,接入微信公众平台:不能直接返回String,直接返回String微信服务器不接受。
// GET: api/checkSignature/5
public HttpResponseMessage Get(string signature , string timestamp , string nonce , string echostr)
{
string TOKEN = "微信公众平台设置的TOKEN";
var response = new HttpResponseMessage(HttpStatusCode.OK);
string[] ArrTmp = { TOKEN, timestamp, nonce };
string result = "";
Array.Sort(ArrTmp);
string tmpStr = string.Join("", ArrTmp);
string sign = SignHelper.Sha1Sign(tmpStr);
Log.WorkInfo("sign:" + sign);
Log.WorkInfo("signature:" + signature);
if (sign.Equals(signature))
{
result = echostr;
}
else
{
result = "signature fail";
}
response.Content = new StringContent(result, System.Text.Encoding.UTF8, "text/plain");
return response;

最低0.47元/天 解锁文章
320

被折叠的 条评论
为什么被折叠?



