国产99久久精品_欧美日本韩国一区二区_激情小说综合网_欧美一级二级视频_午夜av电影_日本久久精品视频

最新文章專題視頻專題問答1問答10問答100問答1000問答2000關鍵字專題1關鍵字專題50關鍵字專題500關鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關鍵字專題關鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
當前位置: 首頁 - 科技 - 知識百科 - 正文

.net接入支付寶的支付接口

來源:懂視網 責編:小采 時間:2020-11-27 22:35:45
文檔

.net接入支付寶的支付接口

.net接入支付寶的支付接口:H5手機網站接入支付寶的支付接口,推薦使用支付寶提供的SDK來快速開發 我使用的是SDK開發 引用命名空間 using Aop.Api; using Aop.Api.Request; using Aop.Api.Response; using Aop.Api.Util; 首頁需要定義一些常量 static st
推薦度:
導讀.net接入支付寶的支付接口:H5手機網站接入支付寶的支付接口,推薦使用支付寶提供的SDK來快速開發 我使用的是SDK開發 引用命名空間 using Aop.Api; using Aop.Api.Request; using Aop.Api.Response; using Aop.Api.Util; 首頁需要定義一些常量 static st

H5手機網站接入支付寶的支付接口,推薦使用支付寶提供的SDK來快速開發

我使用的是SDK開發

引用命名空間

using Aop.Api;
using Aop.Api.Request;
using Aop.Api.Response;
using Aop.Api.Util;

首頁需要定義一些常量

 static string serverUrl = "https://openapi.alipaydev.com/gateway.do";
 static string app_id = "**"; //開發者的應用ID
 static string format = "JSON";
 static string charset = "utf-8";
 static string sign_type = "RSA2"; //簽名格式
 static string version = "1.0";
 string UID = "2088102169707816";//賣家支付寶賬戶號
 //商戶私鑰
 static string merchant_private_key = "***";
 //支付寶公鑰
 static string alipay_public_key = "***";

這里的app_id,merchant_private_key,alipay_public_key 我就沒有列出來了,獲取的方法需要自己去支付寶平臺完成一些操作進行獲取

在用戶點擊網站付款時,我們需要喚醒支付寶,來進行支付

public string H5RequestPayWay(OrderPO order)
 {
 IAopClient client = new DefaultAopClient(serverUrl, app_id, merchant_private_key, format, version, sign_type, alipay_public_key, charset, false);
 AlipayTradeWapPayRequest request = new AlipayTradeWapPayRequest();
 string address= "http://m." + PathLogic1.RootDomain;
 request.SetReturnUrl(address+ "/WebPay/AlipayPayResult");//同步請求
 request.SetNotifyUrl(address + "/WebPay/AsyncPay");//異步請求
 var lstDetail = Context.Data.OrderDetail.Where(x => x.OrderNo == order.OrderNo).ToSelectList(x=>new { x.SkuName});
 StringBuilder sb = new StringBuilder();
 for (int i = 0; i < lstDetail.Count(); i++)
 {
 sb.Append(lstDetail[i].SkuName + ",");
 }
 request.BizContent = "{" +
 "\"body\":\""+sb.ToString().Substring(0,sb.Length-1)+"\"," +
 "\"subject\":\"袋鼠巴巴商品支付\"," +
 "\"out_trade_no\":\""+order.OrderNo+"\"," +
 "\"timeout_express\":\"90m\"," +
 "\"total_amount\":"+(order.TotalAmount.Value+order.TotalFreight.Value)+"," +
 "\"product_code\":\"QUICK_WAP_PAY\"" +
 " }";

 AlipayTradeWapPayResponse response = client.pageExecute(request);
 return response.Body;
 }

具體發送給支付寶的參數,自行去查看

執行方法后,買家輸入自己的支付寶賬號密碼進行支付,支付成功的結果,支付寶會以post的方式異步請求你的SetNotifyUrl的地址

這個SetNotifyUrl的地址必須要外網可以訪問,支付寶的請求才能進來

買家支付成功,商家修改訂單狀態和數據庫的操作,都在異步請求中執行

同步請求

public ActionResult AlipayPayResult()
 {
 ViewBag.result = "success";
 return View("PayResult");
 }

 /// <summary>
 /// 驗證通知數據的正確性
 /// </summary>
 /// <param name="out_trade_no"></param>
 /// <param name="total_amount"></param>
 /// <param name="seller_id"></param>
 /// <returns></returns> 
private SortedDictionary<string, string> GetRequestPost()
 {
 int i = 0;
 SortedDictionary<string, string> sArray = new SortedDictionary<string, string>();
 NameValueCollection coll;
 //Load Form variables into NameValueCollection variable.
 coll = Request.Form;

 // Get names of all forms into a string array.
 String[] requestItem = coll.AllKeys;

 for (i = 0; i < requestItem.Length; i++)
 {
 sArray.Add(requestItem[i], Request.Form[requestItem[i]]);
 }

 return sArray;
 }
 /// <summary>
 /// 驗簽
 /// </summary>
 /// <param name="inputPara"></param>
 /// <returns></returns>
 public Boolean Verify(SortedDictionary<string, string> inputPara)
 {
 Dictionary<string, string> sPara = new Dictionary<string, string>(); 
 Boolean verifyResult = AlipaySignature.RSACheckV1(inputPara, alipay_public_key, charset,sign_type,false);
 return verifyResult;
 }

異步請求:

 [HttpPost]
 public void AsyncPay()
 {
 SortedDictionary<string, string> sPara = GetRequestPost();//將post請求過來的參數傳化為SortedDictionary
 if (sPara.Count > 0)
 {
 AlipayTradeWayPayServer pay = new AlipayTradeWayPayServer();
 Boolean VerifyResult = pay.Verify(sPara);//驗簽if (VerifyResult)
 {
 try
 {
 //商戶訂單號
 string out_trade_no = Request.Form["out_trade_no"];
 //支付寶交易號
 string trade_no = Request.Form["trade_no"];
 //支付金額
 decimal total_amount = Request.Form["total_amount"].ConvertType(Decimal.Zero);
 //實收金額
 //decimal receipt_amount = Request.Form["receipt_amount"].ConvertType(Decimal.Zero);
 //交易狀態
 string trade_status = Request.Form["trade_status"];
 //賣家支付寶賬號
 string seller_id = Request.Form["seller_id"];

 //商品描述
 string body = Request.Form["body"];
 //交易創建時間
 DateTime gmt_create = DateTime.Parse(Request.Form["gmt_create"]);
 //交易付款時間
 DateTime gmt_payment = DateTime.Parse(Request.Form["gmt_payment"]);
 string appid = Request.Form["app_id"];
 WriteError("驗證參數開始");
 Boolean DataValidity = pay.CheckInform(out_trade_no, total_amount, seller_id, appid);//商家判斷參數時候是否匹配if (DataValidity)
 {
 if (Request.Form["trade_status"] == "TRADE_FINISHED")
 {
 AlipayWayPayPO model = CreateAlipayWayPay(out_trade_no, trade_no, trade_status, gmt_create, gmt_payment);
 pay.PaySuccess(out_trade_no, model, Server.MapPath("~/" + DateTime.Today.ToString("yyMMdd") + ".txt"));//修改訂單
 //注意:
 //退款日期超過可退款期限后(如三個月可退款),支付寶系統發送該交易狀態通知
 }
 else if (Request.Form["trade_status"] == "TRADE_SUCCESS")
 {
 AlipayWayPayPO model = CreateAlipayWayPay(out_trade_no, trade_no, trade_status, gmt_create, gmt_payment);
 pay.PaySuccess(out_trade_no, model, Server.MapPath("~/" + DateTime.Today.ToString("yyMMdd") + ".txt"));//修改訂單
 //注意:
 //付款完成后,支付寶系統發送該交易狀態通知
 }
 else
 {

 }

 //——請根據您的業務邏輯來編寫程序(以上代碼僅作參考)——

 Response.Write("success"); //請不要修改或刪除

 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
 }
 }
 catch (Exception ex)
 {
 
 }
 }
 else//驗證失敗
 {
 Response.Write("fail");
 }
 }
 else
 {
 Response.Write("無通知參數");
 }
 }

聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

文檔

.net接入支付寶的支付接口

.net接入支付寶的支付接口:H5手機網站接入支付寶的支付接口,推薦使用支付寶提供的SDK來快速開發 我使用的是SDK開發 引用命名空間 using Aop.Api; using Aop.Api.Request; using Aop.Api.Response; using Aop.Api.Util; 首頁需要定義一些常量 static st
推薦度:
標簽: 支付 支付寶 API
  • 熱門焦點

最新推薦

猜你喜歡

熱門推薦

專題
Top
主站蜘蛛池模板: 一道本在线播放 | 欧美性xxxxxx爱| 98成人网 | 黑丝草逼 | 欧洲亚洲欧美国产日本高清 | 91精品国产高清久久久久久91 | 一级毛片免费毛片一级毛片免费 | 夜精品a一区二区三区 | 亚洲一区二区三区久久精品 | 日本1区2区 | 日本一区二区三区精品视频 | 国产精品国产三级国产普通话一 | 国产日韩欧美精品 | 在线观看免费精品国产 | 国产欧美日本在线 | 国产精品免费精品自在线观看 | 国产精品高清视亚洲一区二区 | 成人区精品一区二区毛片不卡 | 九草伊人 | 国产精品久久久久9999 | 亚洲欧美日韩中文字幕在线不卡 | 久久精品亚洲一区二区三区浴池 | 成人午夜精品久久久久久久小说 | 国产激情一级毛片久久久 | 久久久久久亚洲精品不卡 | 欧美在线一区二区 | 国产亚洲一欧美一区二区三区 | 免费在线一级毛片 | 99久久综合国产精品免费 | 国产日韩欧美精品一区二区三区 | 国产小视频在线免费观看 | 亚洲精品毛片久久久久久久 | 国产精品专区第二 | 亚洲欧美日韩精品高清 | 国产精品1区2区3区在线播放 | 亚洲国产综合专区在线电影 | 最近中文字幕无日本电影 | 日韩欧美第一页 | 欧美一级色图 | 国产资源在线播放 | 亚洲欧美另类自拍第一页 |