110,539
社区成员
发帖
与我相关
我的任务
分享
Notify aliNotify = new Notify();
bool verifyResult = aliNotify.Verify(sPara, Request.Form["notify_id"], Request.Form["sign"]);
/// <summary>
/// 验证消息是否是支付宝发出的合法消息
/// </summary>
/// <param name="inputPara">通知返回参数数组</param>
/// <param name="notify_id">通知验证ID</param>
/// <param name="sign">支付宝生成的签名结果</param>
/// <returns>验证结果</returns>
public bool Verify(SortedDictionary<string, string> inputPara, string notify_id, string sign)
{
//获取返回时的签名验证结果
bool isSign = GetSignVeryfy(inputPara, sign);
//获取是否是支付宝服务器发来的请求的验证结果
string responseTxt = "true";
if (notify_id != null && notify_id != "") { responseTxt = GetResponseTxt(notify_id); }
else { responseTxt = "false"; }
//判断responsetTxt是否为true,isSign是否为true
//responsetTxt的结果不是true,与服务器设置问题、合作身份者ID、notify_id一分钟失效有关
//isSign不是true,与安全校验码、请求时的参数格式(如:带自定义参数等)、编码格式有关
if (responseTxt == "true" && isSign)//验证成功
{
return true;
}
else//验证失败
{
return false;
}
}