新版支付宝开放平台 手机网页支付 整个流程
来源:互联网 发布:阿里云域名无法使用 编辑:程序博客网 时间:2024/04/29 22:37
新版支付宝开放平台 手机网页支付 整个流程
在支付宝签约如下产品
然后,使用支付宝最新的签名工具生成商户的私钥和公钥
值得注意的是,如果是.net c# 请选择PKCS1,我只采用1024密钥长度。
然后来到支付宝的账号管理中心:
在如图的开放平台密钥页所示处,将上述软件生成的商户公钥设置到应用公钥处,然后设置授权回调地址,设置完后,点开查看并保存支付宝公钥,用于加密及验签。
基它地方不要设置,不要动。
下载最新的.net 支付宝SDK,引入工程
然后,在自己工程中配置支付宝参数 :
发起支付:
IAopClient client = new DefaultAopClient(AlipayConfig.Alipay_Server, AlipayConfig.APPID, AlipayConfig.APP_PRIVATE_KEY, "json", "1.0", "RSA", AlipayConfig.ALIPAY_PUBLIC_KEY, AlipayConfig.CHARSET, false);AlipayTradeWapPayRequest request = new AlipayTradeWapPayRequest();request.SetNotifyUrl(AlipayConfig.Asynchronous_Notice_Location_Alipay);request.SetReturnUrl(AlipayConfig.Synchronous_Notice_Location_Alipay);string desc = "商城充值";string subject = "hahahaha";string out_trade_no = payDetail.Id.ToString();string total_amount = payDetail.Price.ToString("F2");request.BizContent = "{" +" \"body\":\" " + desc + "\"," +" \"subject\":\"" + subject + "\"," +" \"out_trade_no\":\"" + out_trade_no + "\"," +" \"timeout_express\":\"90m\"," +" \"total_amount\":+"+ total_amount + "," +" \"product_code\":\"QUICK_WAP_WAY\"" +" }";AlipayTradeWapPayResponse response = client.pageExecute(request);string form = response.Body;form = form.Replace("<script>document.forms['alipaysubmit'].submit();</script>", "");form = form.Replace("<form id='alipaysubmit' name='alipaysubmit' action='https://openapi.alipay.com/gateway.do?charset=UTF-8' method='POST'>", "<form id='alipaysubmit' name='alipaysubmit' action='https://openapi.alipay.com/gateway.do?charset=UTF-8' method='POST' style='display:none;'>");ViewBag.Content = form;
然后在页面上调用表单提交:function check() { var ua = window.navigator.userAgent.toLowerCase(); if (ua.match(/MicroMessenger/i) == 'micromessenger') { alert('请点击右上角菜单,在浏览器中打开本页面完成支付。'); } else { document.forms['alipaysubmit'].submit(); } }
然后,异步通知页验签:public Dictionary<string, string> GetRequestPost(HttpRequestBase request) { int i = 0; Dictionary<string, string> sArray = new Dictionary<string, string>(); System.Collections.Specialized.NameValueCollection coll; coll = request.Form; String[] requestItem = coll.AllKeys; for (i = 0; i < requestItem.Length; i++) { sArray.Add(requestItem[i], request.Form[requestItem[i]]); } return sArray; }try { bool flag = Aop.Api.Util.AlipaySignature.RSACheckV1(GetRequestPost(Request), AlipayConfig.ALIPAY_PUBLIC_KEY, AlipayConfig.CHARSET, "RSA", false); if(flag) { log4net.LogManager.GetLogger("root").Info("支付宝签名验证成功"); //1、商户需要验证该通知数据中的out_trade_no是否为商户系统中创建的订单号, //2、判断total_amount是否确实为该订单的实际金额(即商户订单创建时的金额), //3、校验通知中的seller_id(或者seller_email) 是否为out_trade_no这笔单据的对应的操作方(有的时候,一个商户可能有多个seller_id/seller_email), //4、验证app_id是否为该商户本身。上述1、2、3、4有任何一个验证不通过,则表明本次通知是异常通知,务必忽略。 //在上述验证通过后商户必须根据支付宝不同类型的业务通知,正确的进行不同的业务处理,并且过滤重复的通知结果数据。 //在支付宝的业务通知中,只有交易通知状态为TRADE_SUCCESS或TRADE_FINISHED时,支付宝才会认定为买家付款成功。 //商户订单号 string out_trade_no = Request.Form["out_trade_no"] ; log4net.LogManager.GetLogger("root").Info("商户订单号" + out_trade_no); string app_id = Request.Form["app_id"]; log4net.LogManager.GetLogger("root").Info("app_id:" + app_id); if (app_id != AlipayConfig.APPID) { log4net.LogManager.GetLogger("root").Info("app_id != AlipayConfig.APPID" ); return Content("fail"); } string trade_no = Request.Form["trade_no"] ; log4net.LogManager.GetLogger("root").Info("支付宝交易号" + trade_no); //交易状态 string trade_status = Request.Form["trade_status"] ; log4net.LogManager.GetLogger("root").Info("交易状态" + trade_status); string gmt_payment= Request.Form["gmt_payment"] ; log4net.LogManager.GetLogger("root").Info("交易支付时间:" + gmt_payment); string total_amount= Request.Form["total_amount"] ; log4net.LogManager.GetLogger("root").Info("交易金额:" + total_amount); decimal money=total_amount.ParseTo<decimal>(0); if (Request.Form["trade_status"] == "TRADE_FINISHED" || Request.Form["trade_status"] == "TRADE_SUCCESS") { DealPay_Alipay(out_trade_no, trade_no, gmt_payment, money); return Content("success"); } else { return Content("fail"); } //——请根据您的业务逻辑来编写程序(以上代码仅作参考)—— } } catch (CustomerException ex) { log4net.LogManager.GetLogger("root").Info("ex:" + ex.Message); return Content("fail"); } catch (Exception ex) { log4net.LogManager.GetLogger("root").Info("ex:" + ex.Message + ex.InnerException.Message + ex.StackTrace); return Content("fail"); } return Content("fail");
同步通知页:if (!String.IsNullOrEmpty(Request.Form["trade_no"]) || !String.IsNullOrEmpty(Request.QueryString["trade_no"])) { return View(); } else { return RedirectToAction("AlipayFail"); }
阅读全文
1 0
- 新版支付宝开放平台 手机网页支付 整个流程
- 新版支付宝手机支付流程_C#版
- 支付宝手机网页支付
- 新版支付宝支付
- 新版支付宝手机网站支付、支付宝pc支付、支付宝无密退款实现
- 支付宝三(手机网页支付)
- 支付宝手机网页唤醒app支付
- 支付宝手机网页唤醒app支付
- java 集成手机网页支付流程
- PHP APP支付 --支付宝开放平台(蚂蚁金服)
- 支付宝开放平台C++方式接入
- 支付宝开放平台Android端使用方法
- 支付宝支付--手机支付
- 支付宝宣布新版客户端开放公测
- 支付宝网页支付
- 支付宝网页支付
- 支付宝支付网页
- 支付宝支付流程
- AdrenoProfiler对opengles的性能分析
- androidstudio 连接打印机
- 图解CommonJS、AMD、CMD规范
- ufw 端口
- Maven
- 新版支付宝开放平台 手机网页支付 整个流程
- 使用Adreno Profiler分析android游戏
- 常用的git指令
- 《Python数据分析与挖掘实战》上机实验1—电力窃漏电用户自动识别
- PrestoException:Error{message='Duplicate entry '2017-01-01' for key date异常解决记录
- JS基本类型与引用类型知多少
- Android:ExpandableTextView 的扩展
- WebService简单介绍
- cookie 和session 的区别详解