Skip to content

Commit

Permalink
Merge pull request smartwalle#8 from wusphinx/master
Browse files Browse the repository at this point in the history
format
  • Loading branch information
smartwalle authored May 17, 2017
2 parents 4a647ab + c2c1621 commit 98753fd
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 30 deletions.
39 changes: 35 additions & 4 deletions alipay_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ import (
"fmt"
)

var publicKey = []byte(`-----BEGIN PUBLIC KEY-----
var (
appID = "2016073100129537"
partnerID = "2088102169227503"

publicKey = []byte(`-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAv8dXxi8wNAOqBNOh8Dv5
rh0BTb5KNgk62jDaS536Z1cDqq2JmpBYkBnzJXHAXEgBwPXgX8bGruMMjZKW8P4u
v3Rvj8Am9ewWwUK2U7m2ZB3Oo9MWtyYoiLGX1IA4FFenXzpPgm0WyzaeLX4yJ8j+
Expand All @@ -15,7 +19,7 @@ uRFnKlZuFoEKPWyMGYtbvK9AWIfC8ubn30O5F9kfLMIHwAHCh0UipPSbKDwQ2BnW
swIDAQAB
-----END PUBLIC KEY-----`)

var privateKey = []byte(`-----BEGIN RSA PRIVATE KEY-----
privateKey = []byte(`-----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCAQEAv8dXxi8wNAOqBNOh8Dv5rh0BTb5KNgk62jDaS536Z1cDqq2J
mpBYkBnzJXHAXEgBwPXgX8bGruMMjZKW8P4uv3Rvj8Am9ewWwUK2U7m2ZB3Oo9MW
tyYoiLGX1IA4FFenXzpPgm0WyzaeLX4yJ8j+hVrRbgwbZzb9Aq0MyepnK5PVoSPL
Expand Down Expand Up @@ -43,8 +47,7 @@ Uzd+FwKBgHW9Nur4eTxK1nIOZyGgCqL1duYsJQcPWyIcRMTSjOoQZ5ZUhQZTw1Hd
vTlWbWwZHVDP85dioLE9mfo5+Hh3SmHDi3TaVXjxeJsUgHkRgOX7
-----END RSA PRIVATE KEY-----
`)

var appID = "2016073100129537"
)

var partnerID = "2088102169227503"

Expand All @@ -63,3 +66,31 @@ func TestSign(t *testing.T) {
var url, _ = client.TradeWapPay(p)
fmt.Println(url)
}

func TestAliPayTradeQuery(t *testing.T) {
client := New(appID, partnerID, publicKey, privateKey, false)

type arg struct {
outTradeNo string
wanted error
name string
}

testCaes := []arg{
{"1111111", nil, "query success"},
//TODO:add more test case
}

for _, tc := range testCaes {
req := AliPayTradeQuery{
OutTradeNo: tc.outTradeNo,
}
resp, err := client.TradeQuery(req)
if err != tc.wanted {
t.Errorf("%s input:%s wanted:%v get:%v", tc.name, tc.outTradeNo, tc.wanted, err)
} else {
t.Log(resp)
}
}

}
52 changes: 26 additions & 26 deletions trade_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,34 +28,34 @@ func (this AliPayTradeQuery) ExtJSONParamValue() string {

type AliPayTradeQueryResponse struct {
AliPayTradeQuery struct {
Code string `json:"code"`
Msg string `json:"msg"`
SubCode string `json:"sub_code"`
SubMsg string `json:"sub_msg"`
BuyerLogonId string `json:"buyer_logon_id"` // 买家支付宝账号
BuyerPayAmount string `json:"buyer_pay_amount"` // 买家实付金额,单位为元,两位小数。
BuyerUserId string `json:"buyer_user_id"` // 买家在支付宝的用户id
InvoiceAmount string `json:"invoice_amount"` // 交易中用户支付的可开具发票的金额,单位为元,两位小数。
Openid string `json:"open_id"` // 买家支付宝用户号,该字段将废弃,不要使用
OutTradeNo string `json:"out_trade_no"` // 商家订单号
PointAmount string `json:"point_amount"` // 积分支付的金额,单位为元,两位小数。
ReceiptAmount string `json:"receipt_amount"` // 实收金额,单位为元,两位小数
SendPayDate string `json:"send_pay_date"` // 本次交易打款给卖家的时间
TotalAmount string `json:"total_amount"` // 交易的订单金额
TradeNo string `json:"trade_no"` // 支付宝交易号
TradeStatus string `json:"trade_status"` // 交易状态
AliPayStoreId string `json:"alipay_store_id"` // 支付宝店铺编号
StoreId string `json:"store_id"` // 商户门店编号
TerminalId string `json:"terminal_id"` // 商户机具终端编号
StoreName string `json:"store_name"` // 请求交易支付中的商户店铺的名称
DiscountGoodsDetail string `json:"discount_goods_detail"` // 本次交易支付所使用的单品券优惠的商品优惠信息
IndustrySepcDetail string `json:"industry_sepc_detail"` // 行业特殊信息(例如在医保卡支付业务中,向用户返回医疗信息)。
Code string `json:"code"`
Msg string `json:"msg"`
SubCode string `json:"sub_code"`
SubMsg string `json:"sub_msg"`
BuyerLogonId string `json:"buyer_logon_id"` // 买家支付宝账号
BuyerPayAmount float64 `json:"buyer_pay_amount,string"` // 买家实付金额,单位为元,两位小数。
BuyerUserId string `json:"buyer_user_id"` // 买家在支付宝的用户id
InvoiceAmount float64 `json:"invoice_amount,string"` // 交易中用户支付的可开具发票的金额,单位为元,两位小数。
Openid string `json:"open_id"` // 买家支付宝用户号,该字段将废弃,不要使用
OutTradeNo string `json:"out_trade_no"` // 商家订单号
PointAmount float64 `json:"point_amount,string"` // 积分支付的金额,单位为元,两位小数。
ReceiptAmount float64 `json:"receipt_amount,string"` // 实收金额,单位为元,两位小数
SendPayDate string `json:"send_pay_date"` // 本次交易打款给卖家的时间
TotalAmount float64 `json:"total_amount,string"` // 交易的订单金额
TradeNo string `json:"trade_no"` // 支付宝交易号
TradeStatus string `json:"trade_status"` // 交易状态
AliPayStoreId string `json:"alipay_store_id"` // 支付宝店铺编号
StoreId string `json:"store_id"` // 商户门店编号
TerminalId string `json:"terminal_id"` // 商户机具终端编号
StoreName string `json:"store_name"` // 请求交易支付中的商户店铺的名称
DiscountGoodsDetail string `json:"discount_goods_detail"` // 本次交易支付所使用的单品券优惠的商品优惠信息
IndustrySepcDetail string `json:"industry_sepc_detail"` // 行业特殊信息(例如在医保卡支付业务中,向用户返回医疗信息)。
FundBillList []struct {
FundChannel string `json:"fund_channel"` // 交易使用的资金渠道,详见 支付渠道列表
Amount string `json:"amount"` // 该支付工具类型所使用的金额
RealAmount string `json:"real_amount"` // 渠道实际付款金额
FundChannel string `json:"fund_channel"` // 交易使用的资金渠道,详见 支付渠道列表
Amount string `json:"amount"` // 该支付工具类型所使用的金额
RealAmount float64 `json:"real_amount,string"` // 渠道实际付款金额
} `json:"fund_bill_list"` // 交易支付使用的资金渠道
voucher_detail_list []VoucherDetail `json:"voucher_detail_list"` // 本交易支付时使用的所有优惠券信息
VoucherDetailList []VoucherDetail `json:"voucher_detail_list"` // 本交易支付时使用的所有优惠券信息
} `json:"alipay_trade_query_response"`
Sign string `json:"sign"`
}
Expand Down

0 comments on commit 98753fd

Please sign in to comment.