C#支付寶新版支付請求接口調(diào)用
本文實例為大家分享了C#支付寶新版支付請求接口調(diào)用的具體代碼,供大家參考,具體內(nèi)容如下
因為支付寶已經(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;
需要用到商戶私鑰,支付寶公鑰,請求地址等公共參數(shù),所以可以新建一個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 對應(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";
}
支付請求處理頁面:
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ù)點后兩位,取值范圍[0.01,100000000]
model.OutTradeNo = out_trade_no; //商戶網(wǎng)站唯一訂單號
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;
}
}
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
C#實現(xiàn)根據(jù)指定容器和控件名字獲得控件的方法
這篇文章主要介紹了C#實現(xiàn)根據(jù)指定容器和控件名字獲得控件的方法,其中包括了遍歷與遞歸的應(yīng)用,需要的朋友可以參考下2014-08-08
C#中GraphicsPath的AddString方法用法實例
這篇文章主要介紹了C#中GraphicsPath的AddString方法用法,實例分析了AddString方法添加字符串的相關(guān)使用技巧,需要的朋友可以參考下2015-06-06
C# VTK 移動旋轉(zhuǎn)交互功能實現(xiàn)
對vtk場景中一個或多個選中物體進行移動旋轉(zhuǎn),今天通過本文給大家分享C# VTK 移動旋轉(zhuǎn)交互功能實現(xiàn),感興趣的朋友跟隨小編一起看看吧2024-06-06
C#請求http向網(wǎng)頁發(fā)送接收數(shù)據(jù)的方法
這篇文章主要為大家詳細介紹了C#請求http向網(wǎng)頁發(fā)送數(shù)據(jù)、網(wǎng)頁接收的方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-07-07
C#實現(xiàn)計算兩個坐標點直接距離的方法小結(jié)
這篇文章主要為大家詳細介紹了C#中幾種常見場景下兩個坐標點直接距離的計算方法,文中的示例代碼講解詳細,有需要的可以參考一下2024-04-04

