c# 支付宝新版接口异步通知notify

您所在的位置:网站首页 支付宝接口异常怎么处理 c# 支付宝新版接口异步通知notify

c# 支付宝新版接口异步通知notify

2024-06-23 17:26| 来源: 网络整理| 查看: 265

某商户设置的通知地址为https://api.xx.com/receive_notify.htm,对应接收到通知的示例如下:

https://api.xx.com/receive_notify.htm?total_amount=2.00&buyer_id=2088102116773037&body=大乐透2.1&trade_no=2016071921001003030200089909&refund_fee=0.00¬ify_time=2016-07-19 14:10:49&subject=大乐透2.1&sign_type=RSA2&charset=utf-8¬ify_type=trade_status_sync&out_trade_no=0719141034-6418&gmt_close=2016-07-19 14:10:46&gmt_payment=2016-07-19 14:10:47&trade_status=TRADE_SUCCESS&version=1.0&sign=kPbQIjX+xQc8F0/A6/AocELIjhhZnGbcBN6G4MM/HmfWL4ZiHM6fWl5NQhzXJusaklZ1LFuMo+lHQUELAYeugH8LYFvxnNajOvZhuxNFbN2LhF0l/KL8ANtj8oyPM4NN7Qft2kWJTDJUpQOzCzNnV9hDxh5AaT9FPqRS6ZKxnzM=&gmt_create=2016-07-19 14:10:44&app_id=2015102700040153&seller_id=2088102119685838¬ify_id=4a91b7a78a503640467525113fb7d8bg8e

第一步: 在通知返回参数列表中,除去sign、sign_type两个参数外,凡是通知返回回来的参数皆是待验签的参数。

第二步: 将剩下参数进行url_decode, 然后进行字典排序,组成字符串,得到待签名字符串:

body=大乐透2.1&buyer_id=2088102116773037&charset=utf-8&gmt_close=2016-07-19 14:10:46&gmt_payment=2016-07-19 14:10:47¬ify_time=2016-07-19 14:10:49¬ify_type=trade_status_sync&out_trade_no=0719141034-6418&refund_fee=0.00&subject=大乐透2.1&total_amount=2.00&trade_no=2016071921001003030200089909&trade_status=TRADE_SUCCESS&version=1.0

第三步: 将签名参数(sign)使用base64解码为字节码串。

第四步: 使用RSA的验签方法,通过签名字符串、签名参数(经过base64解码)及支付宝公钥验证签名。

第五步:需要严格按照如下描述校验通知数据的正确性。

SDK自带的验证签名方法,字典排序支持得.NET 3.5以上的版本,所以如果使用的是.NET 2.0版本的需要自己处理签名字符串:

protected void Page_Load(object sender, EventArgs e) { Dictionary sArray = GetRequestPost(); if (sArray.Count != 0) { sArray.Remove("sign");//除去"sign"参数 sArray.Remove("sign_type");//除去"sign_type"参数 List lst = new List(sArray); //倒叙排列:只需要把变量s2 和 s1 互换就行了 例: return s1.Value.CompareTo(s2.Value); //进行排序 目前是顺序 lst.Sort(delegate(KeyValuePair s1, KeyValuePair s2) { return s2.Value.CompareTo(s1.Value); }); string signContent = string.Empty; string sign = Request.Form["sign"]; foreach (KeyValuePair kvp in lst) { signContent += kvp.Key + "=" + kvp.Value + "&"; } signContent = signContent.ToString().Substring(0, signContent.Length - 1); string publicKeyPem = ""; string out_trade_no = Request.Form["out_trade_no"]; string trade_no = Request.Form["trade_no"]; //调用SDK验签方法 bool signVerified = AlipaySignature.RSACheckContent(signContent, sign, newalipayconfig.alipay_public_key, newalipayconfig.charset, newalipayconfig.sign_type, false); if (signVerified) //验证支付发过来的消息,签名是否正确 { Response.Write("success"); //返回给支付宝消息,成功 } else { v_success.Value = "0"; Response.Write(sign + "


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3