Skip to content

Commit

Permalink
添加电脑网站支付接口
Browse files Browse the repository at this point in the history
  • Loading branch information
smartwalle committed Jun 23, 2017
1 parent 38e9492 commit ecc8f1a
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 27 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ AliPay SDK for Golang
* **手机网站支付接口**

alipay.trade.wap.pay

* **电脑网站支付**

alipay.trade.page.pay

* **统一收单线下交易查询**

Expand Down
36 changes: 36 additions & 0 deletions trade.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,41 @@
package alipay

import (
"strings"
"net/url"
"net/http"
"fmt"
"io/ioutil"
)

// TradePagePay https://doc.open.alipay.com/doc2/detail.htm?treeId=270&articleId=105901&docType=1
func (this *AliPay) TradePagePay(param AliPayTradePagePay) (url *url.URL, err error) {
var buf = strings.NewReader(this.URLValues(param).Encode())

req, err := http.NewRequest("POST", this.apiDomain, buf)
if err != nil {
return nil, err
}
req.Header.Set("Content-Type", "application/x-www-form-urlencoded;charset=utf-8")

rep, err := this.client.Do(req)
if err != nil {
return nil, err
}
defer rep.Body.Close()

data, err := ioutil.ReadAll(rep.Body)
fmt.Println(string(data))



if err != nil {
return nil, err
}
url = rep.Request.URL
return url, err
}

// TradeQuery https://doc.open.alipay.com/doc2/apiDetail.htm?apiId=757&docType=4
func (this *AliPay) TradeQuery(param AliPayTradeQuery) (results *AliPayTradeQueryResponse, err error) {
err = this.doRequest("POST", param, &results)
Expand Down
13 changes: 13 additions & 0 deletions trade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,16 @@ func TestAliPay_TradeAppPay(t *testing.T) {
p.ProductCode = "p_1010101"
fmt.Println(client.TradeAppPay(p))
}


func TestAliPay_TradePagePay(t *testing.T) {
fmt.Println("========== TradePagePay ==========")
var p = AliPayTradePagePay{}
p.NotifyURL = "http://203.86.24.181:3000/alipay"
p.ReturnURL = "http://203.86.24.181:3000"
p.Subject = "修正了中文的 Bug"
p.OutTradeNo = "trade_no_2017062301"
p.TotalAmount = "10.00"
p.ProductCode = "FAST_INSTANT_TRADE_PAY"
fmt.Println(client.TradePagePay(p))
}
66 changes: 58 additions & 8 deletions trade_type.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,55 @@
package alipay

import "encoding/json"

////////////////////////////////////////////////////////////////////////////////
// https://doc.open.alipay.com/doc2/detail.htm?treeId=270&articleId=105901&docType=1
type AliPayTradePagePay struct {
NotifyURL string `json:"-"`
ReturnURL string `json:"-"`

// biz content,这四个参数是必须的
Subject string `json:"subject"` // 订单标题
OutTradeNo string `json:"out_trade_no"` // 商户订单号,64个字符以内、可包含字母、数字、下划线;需保证在商户端不重复
TotalAmount string `json:"total_amount"` // 订单总金额,单位为元,精确到小数点后两位,取值范围[0.01,100000000]
ProductCode string `json:"product_code"` // 销售产品码,与支付宝签约的产品码名称。 注:目前仅支持FAST_INSTANT_TRADE_PAY

Body string `json:"body,omitempty"` // 订单描述
GoodsDetail string `json:"goods_detail,omitempty"` // 订单包含的商品列表信息,Json格式,详见商品明细说明
PassbackParams string `json:"passback_params,omitempty"` // 公用回传参数,如果请求时传递了该参数,则返回给商户时会回传该参数。支付宝只会在异步通知时将该参数原样返回。本参数必须进行UrlEncode之后才可以发送给支付宝
ExtendParams string `json:"extend_params,omitempty"` // 业务扩展参数,详见业务扩展参数说明
GoodsType string `json:"goods_type,omitempty"` // 商品主类型:0—虚拟类商品,1—实物类商品(默认) 注:虚拟类商品不支持使用花呗渠道
TimeoutExpress string `json:"timeout_express,omitempty"` // 该笔订单允许的最晚付款时间,逾期将关闭交易。取值范围:1m~15d。m-分钟,h-小时,d-天,1c-当天(1c-当天的情况下,无论交易何时创建,都在0点关闭)。 该参数数值不接受小数点, 如 1.5h,可转换为 90m
EnablePayChannels string `json:"enable_pay_channels,omitempty"` // 可用渠道,用户只能在指定渠道范围内支付 当有多个渠道时用“,”分隔 注:与disable_pay_channels互斥
DisablePayChannels string `json:"disable_pay_channels,omitempty"` // 禁用渠道,用户不可用指定渠道支付 当有多个渠道时用“,”分隔 注:与enable_pay_channels互斥
AuthToken string `json:"auth_token,omitempty"` // 针对用户授权接口,获取用户相关数据时,用于标识用户授权关系
QRPayMode string `json:"qr_pay_mode,omitempty"` // PC扫码支付的方式,支持前置模式和跳转模式。
QRCodeWidth string `json:"qrcode_width,omitempty"` // 商户自定义二维码宽度 注:qr_pay_mode=4时该参数生效
}

func (this AliPayTradePagePay) APIName() string {
return "alipay.trade.page.pay"
}

func (this AliPayTradePagePay) Params() map[string]string {
var m = make(map[string]string)
m["notify_url"] = this.NotifyURL
m["return_url"] = this.ReturnURL
return m
}

func (this AliPayTradePagePay) ExtJSONParamName() string {
return "biz_content"
}

func (this AliPayTradePagePay) ExtJSONParamValue() string {
var bytes, err = json.Marshal(this)
if err != nil {
return ""
}
return string(bytes)
}

////////////////////////////////////////////////////////////////////////////////
// https://doc.open.alipay.com/docs/api.htm?spm=a219a.7395905.0.0.t3A8tQ&docType=4&apiId=757
type AliPayTradeQuery struct {
Expand Down Expand Up @@ -411,13 +461,13 @@ func (this *AliPayTradePayResponse) IsSuccess() bool {
type AliPayTradeAppPay struct {
NotifyURL string `json:"-"` // 可选

Body string `json:"body"` // 可选 对一笔交易的具体描述信息。如果是多种商品,请将商品描述字符串累加传给body。
Subject string `json:"subject"` // 必须 商品的标题/交易标题/订单标题/订单关键字等。
OutTradeNo string `json:"out_trade_no"` // 必须 商户网站唯一订单号
TimeoutExpress string `json:"timeout_express"` // 可选 该笔订单允许的最晚付款时间,逾期将关闭交易。取值范围:1m~15d。m-分钟,h-小时,d-天,1c-当天(1c-当天的情况下,无论交易何时创建,都在0点关闭)。 该参数数值不接受小数点, 如 1.5h,可转换为 90m。
TotalAmount string `json:"total_amount"` // 必须 订单总金额,单位为元,精确到小数点后两位,取值范围[0.01,100000000]
SellerId string `json:"seller_id"` // 可选 收款支付宝用户ID。 如果该值为空,则默认为商户签约账号对应的支付宝用户ID
ProductCode string `json:"product_code"` // 必须 销售产品码,商家和支付宝签约的产品码
Body string `json:"body"` // 可选 对一笔交易的具体描述信息。如果是多种商品,请将商品描述字符串累加传给body。
Subject string `json:"subject"` // 必须 商品的标题/交易标题/订单标题/订单关键字等。
OutTradeNo string `json:"out_trade_no"` // 必须 商户网站唯一订单号
TimeoutExpress string `json:"timeout_express"` // 可选 该笔订单允许的最晚付款时间,逾期将关闭交易。取值范围:1m~15d。m-分钟,h-小时,d-天,1c-当天(1c-当天的情况下,无论交易何时创建,都在0点关闭)。 该参数数值不接受小数点, 如 1.5h,可转换为 90m。
TotalAmount string `json:"total_amount"` // 必须 订单总金额,单位为元,精确到小数点后两位,取值范围[0.01,100000000]
SellerId string `json:"seller_id"` // 可选 收款支付宝用户ID。 如果该值为空,则默认为商户签约账号对应的支付宝用户ID
ProductCode string `json:"product_code"` // 必须 销售产品码,商家和支付宝签约的产品码
//GoodsType string `json:"goods_type"` // 可选 商品主类型:0—虚拟类商品,1—实物类商品 注:虚拟类商品不支持使用花呗渠道
//PassbackParams string `json:"passback_params"` // 可选 公用回传参数,如果请求时传递了该参数,则返回给商户时会回传该参数。支付宝会在异步通知时将该参数原样返回。本参数必须进行UrlEncode之后才可以发送给支付宝
//PromoParams string `json:"promo_params"` // 可选 优惠参数 注:仅与支付宝协商后可用
Expand All @@ -443,4 +493,4 @@ func (this AliPayTradeAppPay) ExtJSONParamName() string {

func (this AliPayTradeAppPay) ExtJSONParamValue() string {
return marshal(this)
}
}
4 changes: 2 additions & 2 deletions wap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ func TestAliPay_TradeWapPay(t *testing.T) {
p.NotifyURL = "http://203.86.24.181:3000/alipay"
p.ReturnURL = "http://203.86.24.181:3000"
p.Subject = "修正了中文的 Bug"
p.OutTradeNo = "trade_no_12341"
p.OutTradeNo = "trade_no_2017062302"
p.TotalAmount = "10.00"
p.ProductCode = "eeeeee"
p.ProductCode = "QUICK_WAP_WAY"

var url, _ = client.TradeWapPay(p)
fmt.Println(url)
Expand Down
34 changes: 17 additions & 17 deletions wap_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@ type AliPayTradeWapPay struct {
ReturnURL string `json:"-"`

// biz content,这四个参数是必须的
Subject string `json:"subject"`
OutTradeNo string `json:"out_trade_no"`
TotalAmount string `json:"total_amount"`
ProductCode string `json:"product_code"`

Body string `json:"body,omitempty"`
TimeoutExpress string `json:"timeout_express,omitempty"`
SellerId string `json:"seller_id,omitempty"`
AuthToken string `json:"auth_token,omitempty"`
GoodsType string `json:"goods_type,omitempty"`
PassbackParams string `json:"passback_params,omitempty"`
PromoParams string `json:"promo_params,omitempty"`
ExtendParams string `json:"extend_params,omitempty"`
EnablePayChannels string `json:"enable_pay_channels,omitempty"`
DisablePayChannels string `json:"disable_pay_channels,omitempty"`
StoreId string `json:"store_id,omitempty"`
Subject string `json:"subject"` // 商品的标题/交易标题/订单标题/订单关键字等。
OutTradeNo string `json:"out_trade_no"` // 商户网站唯一订单号
TotalAmount string `json:"total_amount"` // 订单总金额,单位为元,精确到小数点后两位,取值范围[0.01,100000000]
ProductCode string `json:"product_code"` // 销售产品码,商家和支付宝签约的产品码。该产品请填写固定值:QUICK_WAP_WAY

Body string `json:"body,omitempty"` // 对一笔交易的具体描述信息。如果是多种商品,请将商品描述字符串累加传给body。
TimeoutExpress string `json:"timeout_express,omitempty"` // 该笔订单允许的最晚付款时间,逾期将关闭交易。取值范围:1m~15d。m-分钟,h-小时,d-天,1c-当天(1c-当天的情况下,无论交易何时创建,都在0点关闭)。 该参数数值不接受小数点, 如 1.5h,可转换为 90m。
SellerId string `json:"seller_id,omitempty"` // 收款支付宝用户ID。 如果该值为空,则默认为商户签约账号对应的支付宝用户ID
AuthToken string `json:"auth_token,omitempty"` // 针对用户授权接口,获取用户相关数据时,用于标识用户授权关系
GoodsType string `json:"goods_type,omitempty"` // 商品主类型:0—虚拟类商品,1—实物类商品 注:虚拟类商品不支持使用花呗渠道
PassbackParams string `json:"passback_params,omitempty"` // 公用回传参数,如果请求时传递了该参数,则返回给商户时会回传该参数。支付宝会在异步通知时将该参数原样返回。本参数必须进行UrlEncode之后才可以发送给支付宝
PromoParams string `json:"promo_params,omitempty"` // 优惠参数 注:仅与支付宝协商后可用
ExtendParams string `json:"extend_params,omitempty"` // 业务扩展参数,详见下面的“业务扩展参数说明”
EnablePayChannels string `json:"enable_pay_channels,omitempty"` // 可用渠道,用户只能在指定渠道范围内支付 当有多个渠道时用“,”分隔 注:与disable_pay_channels互斥
DisablePayChannels string `json:"disable_pay_channels,omitempty"` // 禁用渠道,用户不可用指定渠道支付 当有多个渠道时用“,”分隔 注:与enable_pay_channels互斥
StoreId string `json:"store_id,omitempty"` // 商户门店编号。该参数用于请求参数中以区分各门店,非必传项。
}

func (this AliPayTradeWapPay) APIName() string {
Expand All @@ -49,4 +49,4 @@ func (this AliPayTradeWapPay) ExtJSONParamValue() string {
return ""
}
return string(bytes)
}
}

0 comments on commit ecc8f1a

Please sign in to comment.