推薦兩文:1、支付寶購買流程 2、支付寶賣家流程
支付寶接口提供最新的ASP、ASP.NET、PHP、JSP等目前網(wǎng)絡(luò)上最流行的源碼包文件,程序員可以下載后按本文介紹更改參數(shù)和布置即可!而本文拿ASP.NET(C#)詳細(xì)介紹。
------------------------------------------------------------------------------------- 摘自:支付寶官方
點(diǎn)擊下載 實(shí)物商品交易服務(wù)集成技術(shù)文檔和服務(wù)介紹 按照文檔中的提示進(jìn)行集成操作。
四種不同語言的支付寶接口程序,下載地址是:(直接點(diǎn)擊下載)
asp實(shí)物物品交易接口
aspx.net實(shí)物物品交易接口(utf-8)
aspx.net實(shí)物物品交易接口(gbk)
jsp實(shí)物物品交易接口(gbk)
jsp實(shí)物物品交易接口(utf-8)
php實(shí)物物品交易接口(鏈接到論壇其他帖子)
將service改成create_digital_goods_trade_p,費(fèi)用,通知返回地址等即可實(shí)現(xiàn)實(shí)物交易,詳細(xì)參數(shù)請自行設(shè)定
將service改成trade_create_by_buyer,修改物流方式以及費(fèi)用等即可實(shí)現(xiàn)實(shí)物交易,詳細(xì)參數(shù)請自行設(shè)定
將service改成create_donate_trade_p,total_fee費(fèi)用等即可實(shí)捐贈(zèng)項(xiàng)目,詳細(xì)參數(shù)請自行 設(shè)定
提醒:如需簽約使用支付寶收款接口及權(quán)限,歡迎聯(lián)系您的客戶經(jīng)理或點(diǎn)此申請。
---------------------------------------------------------------------------------------
其中,如果產(chǎn)品多了,建議使用訂單號(hào)做為主題(subject)。推薦大家詳細(xì)查看原碼,細(xì)心設(shè)置其參數(shù),才會(huì)運(yùn)行正常,請?jiān)徶Ц秾殲榱税踩苋臋z測 :)
Default.aspx 為提交頁面,相當(dāng)與購物車提交后生成定單后,向支付寶發(fā)送的頁面
alipay_Notify.aspx是接收支付寶通知的URL地址,
alipay_Return.aspx是支付完成后跳轉(zhuǎn)的URL地址。
代碼段:
HTML Code
%@ Page language="c#" Codebehind="Default.aspx.cs" AutoEventWireup="false" Inherits="shiwuUTF_8aspx03._Default" %>
!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
HTML>
HEAD>
title>Default/title>
meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
meta content="C#" name="CODE_LANGUAGE">
meta content="JavaScript" name="vs_defaultClientScript">
meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
/HEAD>
body MS_POSITIONING="GridLayout">
form id="Form1" method="post" runat="server">
div style="TEXT-ALIGN: center">span style="FONT-SIZE: 9pt; FONT-FAMILY: 宋體">支付網(wǎng)關(guān):/span>asp:textbox id="T_gateway" runat="server" Text="https://www.alipay.com/cooperate/gateway.do?"
Width="350px">/asp:textbox>br>
span style="FONT-SIZE: 9pt; FONT-FAMILY: 宋體">服務(wù)參數(shù):asp:dropdownlist id="T_service" runat="server" Width="357px">
asp:ListItem>trade_create_by_buyer/asp:ListItem>
/asp:dropdownlist>/span>br>
span style="FONT-SIZE: 9pt; FONT-FAMILY: 宋體">合作商: /span>
asp:textbox id="T_partner" runat="server" Text="必須,支付寶中心獲得" Width="350px">/asp:textbox>br>
span style="FONT-SIZE: 9pt; FONT-FAMILY: 宋體">加密協(xié)議:/span>asp:textbox id="T_sign_type" runat="server" Text="MD5" Width="350px">/asp:textbox>br>
span style="FONT-SIZE: 9pt; FONT-FAMILY: 宋體">商品名稱:/span>asp:textbox id="T_subject" runat="server" Text="bbs.jishu.me" Width="350px">/asp:textbox>br>
span style="FONT-SIZE: 9pt; FONT-FAMILY: 宋體">商品描述:/span>asp:textbox id="T_body" runat="server" Text="aaa" Width="350px">技術(shù)迷/asp:textbox>br>
span style="FONT-SIZE: 9pt; FONT-FAMILY: 宋體">支付類型:/span>asp:textbox id="T_payment_type" runat="server" Text="1" Width="350px">/asp:textbox>br>
span style="FONT-SIZE: 9pt; FONT-FAMILY: 宋體">單 價(jià) : /span>asp:textbox id="T_total_fee" runat="server" Text="0.01" Width="350px">/asp:textbox>br>
span style="FONT-SIZE: 9pt; FONT-FAMILY: 宋體">數(shù) 量 : /span>asp:textbox id="TextBox1" runat="server" Text="1" Width="350px">/asp:textbox>br>
span style="FONT-SIZE: 9pt; FONT-FAMILY: 宋體">平 郵 : /span>asp:textbox id="TextBox2" runat="server" Text="8" Width="350px">/asp:textbox>br>
span style="FONT-SIZE: 9pt; FONT-FAMILY: 宋體">快 遞 : /span>asp:textbox id="TextBox3" runat="server" Text="15" Width="350px">/asp:textbox>br>
span style="FONT-SIZE: 9pt; FONT-FAMILY: 宋體">展示地址:/span>asp:textbox id="T_show_url" runat="server" Text="" Width="350px">http://bbs.jishu.me/asp:textbox>br>
span style="FONT-SIZE: 9pt; FONT-FAMILY: 宋體">賣家賬號(hào):/span>asp:textbox id="T_seller_email" runat="server" Text="bobby96333@gmail.com" Width="350px">/asp:textbox>br>
span style="FONT-SIZE: 9pt; FONT-FAMILY: 宋體">安全校驗(yàn)碼:/span>asp:textbox id="T_key" runat="server" Text="注:商家簽約后在支付寶會(huì)員中心里面可以獲得" Width="350px">/asp:textbox>br>
span style="FONT-SIZE: 9pt; FONT-FAMILY: 宋體">重定下地址:/span>asp:textbox id="T_return_url" runat="server" Text="http://60.191.43.90/temp/Alipay_Return.aspx"
Width="350px">http://bbs.jishu.me/alipay/Alipay_Return.aspx/asp:textbox>br>
span style="FONT-SIZE: 9pt; FONT-FAMILY: 宋體">服務(wù)器通知地址:/span>asp:textbox id="T_notify_url" runat="server" Text="http://60.191.43.90/temp/Alipay_Notify.aspx"
Width="350px">http://bbs.jishu.me/alipay/Alipay_Notify.aspx/asp:textbox>br>
span style="FONT-SIZE: 9pt; FONT-FAMILY: 宋體">服務(wù)器編碼:/span>asp:textbox id="T_inputchatset" runat="server" Text="utf-8" Width="350px">/asp:textbox>br>
span style="FONT-SIZE: 9pt; FONT-FAMILY: 宋體">
asp:button id="Button1" runat="server" Text="支付寶付款">/asp:button> /span>/div>
/form>
/body>
/HTML>
C# Code
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Configuration;
using System.Web.Security;
using shiwuUTF_8aspx03.App_Code;
namespace shiwuUTF_8aspx03
{
/// summary>
/// _Default 的摘要說明。
/// /summary>
public class _Default : System.Web.UI.Page
{
#region 頁面控件
protected System.Web.UI.WebControls.TextBox T_gateway;
protected System.Web.UI.WebControls.DropDownList T_service;
protected System.Web.UI.WebControls.TextBox T_partner;
protected System.Web.UI.WebControls.TextBox T_sign_type;
protected System.Web.UI.WebControls.TextBox T_subject;
protected System.Web.UI.WebControls.TextBox T_body;
protected System.Web.UI.WebControls.TextBox T_payment_type;
protected System.Web.UI.WebControls.TextBox T_total_fee;
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.TextBox TextBox2;
protected System.Web.UI.WebControls.TextBox TextBox3;
protected System.Web.UI.WebControls.TextBox T_show_url;
protected System.Web.UI.WebControls.TextBox T_seller_email;
protected System.Web.UI.WebControls.TextBox T_key;
protected System.Web.UI.WebControls.TextBox T_return_url;
protected System.Web.UI.WebControls.TextBox T_notify_url;
protected System.Web.UI.WebControls.TextBox T_inputchatset;
protected System.Web.UI.WebControls.Button Button1;
#endregion
private void Page_Load(object sender, System.EventArgs e)
{
// 在此處放置用戶代碼以初始化頁面
#region 可以在此處設(shè)置接值,也可以把Button1_Click里的代碼發(fā)在這里,然后立即跳轉(zhuǎn)
if(!IsPostBack)
{
}
#endregion
}
#region Web 窗體設(shè)計(jì)器生成的代碼
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 該調(diào)用是 ASP.NET Web 窗體設(shè)計(jì)器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// summary>
/// 設(shè)計(jì)器支持所需的方法 - 不要使用代碼編輯器修改
/// 此方法的內(nèi)容。
/// /summary>
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
#region 支付按鈕事件
private void Button1_Click(object sender, System.EventArgs e)
{
//按支付時(shí)間構(gòu)造訂單號(hào);
System.DateTime currentTime=new System.DateTime();
//取時(shí)間
currentTime=System.DateTime.Now;
string out_trade_no = currentTime.ToString("g");
//去訂單號(hào)里的-
out_trade_no = out_trade_no.Replace("-", "");
//去訂單號(hào)里的:
out_trade_no = out_trade_no.Replace(":", "");
//去訂單號(hào)里的空格
out_trade_no = out_trade_no.Replace(" ", "");
//業(yè)務(wù)參數(shù)賦值;
string gateway = T_gateway.Text; //默認(rèn)值不要改支付接口https://www.alipay.com/cooperate/gateway.do?
/*create_flower_direct_pay_by_user鮮花接口
create_digital_goods_trade_p虛擬接口
create_direct_pay_by_user即時(shí)到帳接口*/
string service = T_service.SelectedItem.Text;//trade_create_by_buyer實(shí)物接口,也可以設(shè)置為其他值
string partner = T_partner.Text; //partner 合作伙伴ID 保留字段
string sign_type = T_sign_type.Text; //MD5類型加密
string subject = T_subject.Text; //subject 商品名稱
string body = T_body.Text; //body 商品描述
string payment_type = T_payment_type.Text; //支付類型:1為商品購買,2為服務(wù)購買,3為網(wǎng)絡(luò)拍賣,4為捐贈(zèng),5為郵費(fèi)補(bǔ)償,6為獎(jiǎng)金,15為鮮花購買
string price = T_total_fee.Text; //單價(jià)可以在Page_Load事件里設(shè)置接值
string quantity = TextBox1.Text; //商品數(shù)量
string show_url =Server.UrlEncode( T_show_url.Text); //商品展示地址
string seller_email = T_seller_email.Text; //賣家支付寶賬號(hào)
string key = T_key.Text; //partner賬戶的支付寶安全校驗(yàn)碼
string return_url = T_return_url.Text; //服務(wù)器通知返回接口,通過get方式接受支付完成后的返回信息
string notify_url =T_notify_url.Text; //服務(wù)器通知返回接口,通過post方式接受支付完成后的返回信息
string _input_charset = T_inputchatset.Text; //頁面編碼方式,有utf-8和gbk,此處是utf-8
//物流類型:VIRTUAL為虛擬物品,POST為平郵,EMS為EMS快遞,
string logistics_type = "POST";
string logistics_fee = TextBox2.Text;
string logistics_payment = "BUYER_PAY";
string logistics_type_1 = "EXPRESS";
string logistics_fee_1 = TextBox3.Text;
string logistics_payment_1 = "BUYER_PAY";
AliPay ap = new AliPay();
string aliay_url=ap.CreatUrl(
gateway,
service,
partner,
sign_type,
out_trade_no,
subject,
body,
payment_type,
price,
show_url,
seller_email,
key,
return_url,
_input_charset,
notify_url,
logistics_type,
logistics_fee,
logistics_payment,
logistics_type_1,
logistics_fee_1,
logistics_payment_1,
quantity
);
Response.Redirect(aliay_url);
}
#endregion
}
}
提示:請多查看備注,并進(jìn)行定義。比如快遞和平郵選擇由“l(fā)ogistics_type”參數(shù)設(shè)置。
您可能感興趣的文章:- php支付寶在線支付接口開發(fā)教程
- php支付寶接口用法分析
- ThinkPHP實(shí)現(xiàn)支付寶接口功能實(shí)例
- php支付寶手機(jī)網(wǎng)頁支付類實(shí)例
- PHP實(shí)現(xiàn)QQ、微信和支付寶三合一收款碼實(shí)例代碼
- PHP 接入支付寶即時(shí)到賬功能
- php app支付寶回調(diào)(異步通知)詳解
- PHP后臺(tái)微信支付和支付寶支付開發(fā)
- 純PHP代碼實(shí)現(xiàn)支付寶批量付款
- PHP實(shí)現(xiàn)支付寶即時(shí)到賬功能
- PHP實(shí)現(xiàn)RSA簽名生成訂單功能【支付寶示例】
- PHP實(shí)現(xiàn)的支付寶支付功能示例