欧美一级特黄大片做受成人-亚洲成人一区二区电影-激情熟女一区二区三区-日韩专区欧美专区国产专区

怎么在.net項(xiàng)目中接入支付寶的支付接口-創(chuàng)新互聯(lián)

今天就跟大家聊聊有關(guān)怎么在.net項(xiàng)目中接入支付寶的支付接口,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結(jié)了以下內(nèi)容,希望大家根據(jù)這篇文章可以有所收獲。

創(chuàng)新互聯(lián)云計(jì)算的互聯(lián)網(wǎng)服務(wù)提供商,擁有超過13年的服務(wù)器租用、服務(wù)器機(jī)柜租賃、云服務(wù)器、虛擬主機(jī)、網(wǎng)站系統(tǒng)開發(fā)經(jīng)驗(yàn),已先后獲得國家工業(yè)和信息化部頒發(fā)的互聯(lián)網(wǎng)數(shù)據(jù)中心業(yè)務(wù)許可證。專業(yè)提供云主機(jī)、虛擬主機(jī)、域名與空間、VPS主機(jī)、云服務(wù)器、香港云服務(wù)器、免備案服務(wù)器等。

引用命名空間


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 = "**";  //開發(fā)者的應(yīng)用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 我就沒有列出來了,獲取的方法需要自己去支付寶平臺完成一些操作進(jìn)行獲取

在用戶點(diǎn)擊網(wǎng)站付款時,我們需要喚醒支付寶,來進(jìn)行支付

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;
    }

具體發(fā)送給支付寶的參數(shù),自行去查看

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

這個SetNotifyUrl的地址必須要外網(wǎng)可以訪問,支付寶的請求才能進(jìn)來

買家支付成功,商家修改訂單狀態(tài)和數(shù)據(jù)庫的操作,都在異步請求中執(zhí)行

同步請求

public ActionResult AlipayPayResult()
    {
      ViewBag.result = "success";
      return View("PayResult");
    }
 /// <summary>
    /// 驗(yàn)證通知數(shù)據(jù)的正確性
    /// </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>
    /// 驗(yàn)簽
    /// </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請求過來的參數(shù)傳化為SortedDictionary
      if (sPara.Count > 0)
      {
        AlipayTradeWayPayServer pay = new AlipayTradeWayPayServer();
        Boolean VerifyResult = pay.Verify(sPara);//驗(yàn)簽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);
            //實(shí)收金額
            //decimal receipt_amount = Request.Form["receipt_amount"].ConvertType(Decimal.Zero);
            //交易狀態(tài)
            string trade_status = Request.Form["trade_status"];
            //賣家支付寶賬號
            string seller_id = Request.Form["seller_id"];

            //商品描述
            string body = Request.Form["body"];
            //交易創(chuàng)建時間
            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("驗(yàn)證參數(shù)開始");
            Boolean DataValidity = pay.CheckInform(out_trade_no, total_amount, seller_id, appid);//商家判斷參數(shù)時候是否匹配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"));//修改訂單
                //注意:
                //退款日期超過可退款期限后(如三個月可退款),支付寶系統(tǒng)發(fā)送該交易狀態(tài)通知
              }
              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"));//修改訂單
                //注意:
                //付款完成后,支付寶系統(tǒng)發(fā)送該交易狀態(tài)通知
              }
              else
              {

              }

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

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

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

看完上述內(nèi)容,你們對怎么在.net項(xiàng)目中接入支付寶的支付接口有進(jìn)一步的了解嗎?如果還想了解更多知識或者相關(guān)內(nèi)容,請關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝大家的支持。

本文名稱:怎么在.net項(xiàng)目中接入支付寶的支付接口-創(chuàng)新互聯(lián)
網(wǎng)頁地址:http://aaarwkj.com/article4/gijoe.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站維護(hù)、外貿(mào)網(wǎng)站建設(shè)、域名注冊、搜索引擎優(yōu)化、外貿(mào)建站、軟件開發(fā)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

h5響應(yīng)式網(wǎng)站建設(shè)
91国产精品视频在线| 国产老熟女高潮精品视频网站免费 | 亚洲成人高清av在线| 亚洲激情人妻小说网| 久久人妻制服乱码中文字幕| 日韩av一区二区国产| 持续侵犯人妻中文字幕| 国产女人高潮流白丝视频| 激情内射日本一区二区三区 | 婷婷不卡中文字幕三区| 亚洲欧美日韩成人在线| 亚洲精品中的亚洲精品| 国产日韩精品免费在线| 国产精品久久99真精品| 欧美夫妻成人性生活视频| 国产午夜激情自拍视频| 亚洲精品中的亚洲精品| 亚洲ve中文字幕久久一区二区 | 精品国产女同一区二区| 国产成人99亚洲综合精品| 日本中文字幕激情在线| 国产偷自一区二区三区| 日韩欧美一区二区黄色| 久久综合久中文字幕青草| av高清不卡一区二区免费在线| 亚洲高清精品一区二区| 手机黄色av免费在线网址| 亚洲综合av伊人久久| 亚洲av日韩欧美精品| 国产伦一区二区三区三州| 日韩亚洲一区在线观看| 久久91亚洲精品久久91| 日本成人一区二区在线播放| 中午字幕人妻少妇久久| 亚洲av男人的天堂看| 色哟哟网站一区二区精品久久| 97久久久人妻精品一区| 国产精品夜色一区二区三区不卡| 女性裸体无遮挡啪啪网站| 亚洲中文字幕伦理在线| 美国一级黄片在线观看|