国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

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

2024-07-10 12:49:09
字體:
來源:轉載
供稿:網友

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;    }            
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 辉县市| 阜新| 体育| 余姚市| 乳源| 论坛| 井研县| 茂名市| 洞头县| 梅州市| 洛浦县| 喀喇沁旗| 夏河县| 隆尧县| 池州市| 敦化市| 许昌县| 双牌县| 东山县| 赤峰市| 鹿泉市| 青海省| 石泉县| 廉江市| 四子王旗| 临洮县| 福海县| 庆元县| 杭锦旗| 临泽县| 黄骅市| 隆安县| 垦利县| 津市市| 乌苏市| 大关县| 五河县| 孟州市| 梅州市| 叙永县| 怀宁县|