調用支付寶支付(C#)
//支付寶支付
public string AliPay(string OrderID, string Total) //OrderID訂單號,Total訂單總金額
{
// 支付寶網關
string Url = "https://openapi.alipay.com/gateway.do";
string APPID = "2016080180820878";
//開發者應用私鑰,由支付寶密鑰生成工具生成 商戶應用私鑰 螞蟻金服後臺商戶應用公鑰與支付寶密鑰生成工具商戶應用公鑰匹配一致
string APP_PRIVATE_KEY = "開發者應用私鑰";
//參數返回格式,只支持json
string FORMAT = "json";
//請求和簽名使用的字符編碼格式,支持GBK和UTF-8
string CHARSET = "UTF-8";
//支付寶公鑰,由支付寶生成到螞蟻金服復制
string zhifubao_public_key = "支付寶公鑰";
DefaultAopClient client = new DefaultAopClient(Url, APPID, APP_PRIVATE_KEY, FORMAT, "1.0", "RSA2", zhifubao_public_key, CHARSET, false);
// 外部訂單號,商戶網站訂單系統中唯一的訂單號
string out_trade_no = OrderID.Trim();
// 訂單名稱
string subject = "訂單" + OrderID + "支付";
// 付款金額
string total_amout = Total.Trim().ToString();
// 商品描述
string body = "訂單" + OrderID + "支付";
// 支付中途退出返回商戶網站地址
string quit_url = "url";
#region -----API日誌----
Maticsoft.BLL.Shop_Apilog Bll_Api = new Maticsoft.BLL.Shop_Apilog();
Maticsoft.Model.Shop_Apilog Api = new Maticsoft.Model.Shop_Apilog();
Api.ApiName = "https://openapi.alipay.com/gateway.do";
Api.ReTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff");
Api.Method = "支付寶支付"+OrderID;
#endregion
// 組裝業務參數model
AlipayTradeWapPayModel model = new AlipayTradeWapPayModel();
model.Body = body;
model.Subject = subject;
model.TotalAmount = total_amout;
model.OutTradeNo = out_trade_no;
model.ProductCode = "QUICK_WAP_WAY";
model.QuitUrl = quit_url;
AlipayTradeWapPayRequest request = new AlipayTradeWapPayRequest();
// 設置支付完成同步回調地址
request.SetReturnUrl("回調地址");
// 設置支付完成異步通知接收地址
request.SetNotifyUrl("異步通知接收地址");
// 將業務model載入到request
request.SetBizModel(model);
AlipayTradeWapPayResponse response = null;
try
{
response = client.pageExecute(request, null, "post");
Api.ApiInfo = response.Body;
Bll_Api.Add(Api);
return response.Body;
}
catch (Exception exp)
{
throw exp;
}
}
具體請看支付寶開發文檔:https://openhome.alipay.com/developmentDocument.htm
調用支付寶支付(C#)