今天在開發一個支付功能,由於第三方注冊的是 雙向功能接口(即時交易,擔保交易)兩種方式的支付方法

其實這個接口也是跟 即時交易和擔保交易的接口差不多,只是這邊特別注意一點的就是,商戶的密鑰不能有任何的空格
廢話不說,貼上代碼
////////////////////////////////////////////請求參數////////////////////////////////////////////
//支付類型
string payment_type = "1"; //這個是代表買家付款
//必填,不能修改
//服務器異步通知頁面路徑
string notify_url = “”; // 異步通知的接收頁面,(因為有時候萬一用戶在跳轉到支付寶那邊支付完畢后,遇到一些特殊情況沒有返回到制定的商家頁面)
//需http://格式的完整路徑,不能加?id=123這類自定義參數
//頁面跳轉同步通知頁面路徑
string return_url = “”;
//需http://格式的完整路徑,不能加?id=123這類自定義參數,不能寫成http://localhost/
//賣家支付寶帳戶
string seller_email = “**************”;
//必填
//商戶訂單號
string out_trade_no = “2013145201314”;
//商戶網站訂單系統中唯一訂單號,必填
//訂單名稱
string subject = “這是來自一個第三方商城的訂單”;
//必填
//付款金額
string price =“0.01”;// string.Format("{0:f2}", ****);
//必填
//商品數量
string quantity = "1";
//必填,建議默認為1,不改變值,把一次交易看成是一次下訂單而非購買一件商品
//物流費用
string logistics_fee = "0.00";
//必填,即運費
//物流類型
string logistics_type = "EXPRESS";
//必填,三個值可選:EXPRESS(快遞)、POST(平郵)、EMS(EMS)
//物流支付方式
string logistics_payment = "SELLER_PAY";
//必填,兩個值可選:SELLER_PAY(賣家承擔運費)、BUYER_PAY(買家承擔運費)
//訂單描述
string body = code + "|" + type + "|" + num + "|" + md5sign;
//商品展示地址
string show_url ="http://www.****.com";
//需以http://開頭的完整路徑,如:http://www.商戶網站.com/myorder.html
//收貨人姓名
string receive_name = "測試";
//如:張三
//收貨人地址
string receive_address = "測試";
//如:XX省XXX市XXX區XXX路XXX小區XXX棟XXX單元XXX號
//收貨人郵編
string receive_zip = "510555";
//如:123456
//收貨人電話號碼
string receive_phone = "";
//如:0571-88158090
//收貨人手機號碼
string receive_mobile = "";
//如:13312341234
////////////////////////////////////////////////////////////////////////////////////////////////
//把請求參數打包成數組
SortedDictionary<string, string> sParaTemp = new SortedDictionary<string, string>();
sParaTemp.Add("partner", entity.payID);
sParaTemp.Add("_input_charset", Config.Input_charset.ToLower());
sParaTemp.Add("service", "trade_create_by_buyer");
sParaTemp.Add("payment_type", payment_type);
sParaTemp.Add("notify_url", notify_url);
sParaTemp.Add("return_url", return_url);
sParaTemp.Add("seller_email", seller_email);
sParaTemp.Add("out_trade_no", out_trade_no);
sParaTemp.Add("subject", subject);
sParaTemp.Add("price", price);
sParaTemp.Add("quantity", quantity);
sParaTemp.Add("logistics_fee", logistics_fee);
sParaTemp.Add("logistics_type", logistics_type);
sParaTemp.Add("logistics_payment", logistics_payment);
sParaTemp.Add("body", body);
sParaTemp.Add("show_url", show_url);
sParaTemp.Add("receive_name", receive_name);
sParaTemp.Add("receive_address", receive_address);
sParaTemp.Add("receive_zip", receive_zip);
sParaTemp.Add("receive_phone", receive_phone);
sParaTemp.Add("receive_mobile", receive_mobile);
//建立請求
string sHtmlText = Submit.BuildRequest(sParaTemp, "get", "確認"); //這個拼接提交的form的方法里面,組成一個sign
Response.Write(sHtmlText);
#endregion
配置sign的類,支付寶這邊生成form的元素的時候會把這個key的值通過md5加密,然后加到form的表單元素上去。
static Config() { //↓↓↓↓↓↓↓↓↓↓請在這里配置您的基本信息↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ //合作身份者ID,以2088開頭由16位純數字組成的字符串 partner = ""; //交易安全檢驗碼,由數字和字母組成的32位字符串 key = ""; //↑↑↑↑↑↑↑↑↑↑請在這里配置您的基本信息↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑ //字符編碼格式 目前支持 gbk 或 utf-8 input_charset = "utf-8"; //簽名方式,選擇項:RSA、DSA、MD5 sign_type = "MD5"; }
最后貼上一個示例的url
https://mapi.alipay.com/gateway.do?_input_charset=utf-8& body=test& logistics_fee=0.00& logistics_payment=SELLER_PAY& logistics_type=EXPRESS& notify_url={網站地址}& out_trade_no={訂單號}& partner={商家號}& payment_type=1& price=1& quantity=1& receive_address=測試& receive_name=測試& receive_zip=510555& return_url={url}& seller_email={商家號(郵箱)}& service=trade_create_by_buyer& show_url=http://www.xxxx.com& subject=標題& sign=key的md5加密& sign_type=MD5
支付寶雙接口的文件鏈接地址 點擊下載
