溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

C#如何實(shí)現(xiàn)支付寶新版支付請(qǐng)求接口調(diào)用

發(fā)布時(shí)間:2021-08-09 09:43:47 來(lái)源:億速云 閱讀:168 作者:小新 欄目:編程語(yǔ)言

這篇文章主要介紹C#如何實(shí)現(xiàn)支付寶新版支付請(qǐng)求接口調(diào)用,文中介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們一定要看完!

具體內(nèi)容如下

因?yàn)橹Ц秾氁呀?jīng)集成了完整的SDK,所以可以使用SDK直接調(diào)用API,這里獲取SDK源碼。

首先我們需要引用支付寶SDK集成 AopSdk.dll。

添加相關(guān)引用:

using Aop.Api;
using Aop.Api.Domain;
using Aop.Api.Request;
using Aop.Api.Response;

需要用到商戶私鑰,支付寶公鑰,請(qǐng)求地址等公共參數(shù),所以可以新建一個(gè)config文件:

public class newalipayconfig
{
 public newalipayconfig()
 {
 //
 // TODO: 在此處添加構(gòu)造函數(shù)邏輯
 //
 }
 // 應(yīng)用ID,您的APPID
 public static string app_id = "";
 
 // 支付寶網(wǎng)關(guān)
 public static string gatewayUrl = "https://openapi.alipay.com/gateway.do";
 
 // 支付寶公鑰,查看地址:https://openhome.alipay.com/platform/keyManage.htm 對(duì)應(yīng)APPID下的支付寶公鑰。 
 public static string alipay_public_key = "";
      
 // 商戶私鑰,您的原始格式RSA私鑰
 public static string private_key = "";
 
 // 簽名方式
 public static string sign_type = "RSA2";
 
 // 編碼格式
 public static string charset = "UTF-8";
}

支付請(qǐng)求處理頁(yè)面:

DefaultAopClient client = new DefaultAopClient(newalipayconfig.gatewayUrl, newalipayconfig.app_id, newalipayconfig.private_key, "json", version, newalipayconfig.sign_type, newalipayconfig.alipay_public_key, newalipayconfig.charset, false);
 
 if (order != null)
 {
  // 支付中途退出返回商戶網(wǎng)站地址
  string quit_url = "www.alipay.com";
 
  // 組裝業(yè)務(wù)參數(shù)model
  AlipayTradeWapPayModel model = new AlipayTradeWapPayModel();
  model.Body = body; //商品描述
  model.Subject = subject; //商品名稱
  model.TotalAmount = total_amount; ////訂單總金額,單位為元,精確到小數(shù)點(diǎn)后兩位,取值范圍[0.01,100000000]
  model.OutTradeNo = out_trade_no; //商戶網(wǎng)站唯一訂單號(hào)
  model.ProductCode = "QUICK_WAP_WAY";//銷售產(chǎn)品碼,商家和支付寶簽約的產(chǎn)品碼。
  model.QuitUrl = quit_url;
 
  AlipayTradeWapPayRequest request = new AlipayTradeWapPayRequest();
  // 設(shè)置支付完成同步回調(diào)地址
  request.SetReturnUrl(AlipayConfig.Call_back_url);
  // 設(shè)置支付完成異步通知接收地址
  request.SetNotifyUrl(AlipayConfig.Notify_url);
  // 將業(yè)務(wù)model載入到request
  request.SetBizModel(model);
 
  AlipayTradeWapPayResponse response = null;
  try
  {
  response = client.pageExecute(request, null, "post");
  Response.Write(response.Body);
  }
  catch (Exception exp)
  {
  throw exp;
  }
 }

以上是“C#如何實(shí)現(xiàn)支付寶新版支付請(qǐng)求接口調(diào)用”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對(duì)大家有幫助,更多相關(guān)知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI