Преглед на файлове

当面付-条码支付-完成

Jerry преди 6 години
родител
ревизия
27e2c63cd4
променени са 4 файла, в които са добавени 33 реда и са изтрити 30 реда
  1. 2 1
      alipay_client.go
  2. 10 9
      alipay_client_test.go
  3. 3 3
      alipay_params.go
  4. 18 17
      alipay_rsp.go

+ 2 - 1
alipay_client.go

@@ -76,6 +76,7 @@ func (this *aliPayClient) AliPayTradePay(body BodyMap) (aliRsp *AliPayTradePayRe
 		return nil, err
 	}
 
+	//log.Println("string::::", string(bytes))
 	aliRsp = new(AliPayTradePayResponse)
 	err = json.Unmarshal(bytes, aliRsp)
 	if err != nil {
@@ -170,7 +171,7 @@ func (this *aliPayClient) doAliPay(body BodyMap, method string) (bytes []byte, e
 		pubBody.Set("return_url", this.ReturnUrl)
 	}
 	if this.Charset == null {
-		pubBody.Set("charset", "utf-8")
+		pubBody.Set("charset", "UTF-8")
 	} else {
 		pubBody.Set("charset", this.Charset)
 	}

+ 10 - 9
alipay_client_test.go

@@ -15,23 +15,24 @@ func TestAliPayClient_AliPayTradePay(t *testing.T) {
 	//    isProd:是否是正式环境
 	client := NewAliPayClient("2016091200494382", privateKey, false)
 	//配置公共参数
-	client.SetCharset("utf-8").
+	client.SetCharset("UTF-8").
 		SetSignType("RSA2").
 		SetNotifyUrl("https://api.iguiyu.com/gy_pay/alipay/notify")
 	//请求参数
 	body := make(BodyMap)
 	body.Set("subject", "条码支付")
 	body.Set("scene", "bar_code")
-	body.Set("auth_code", "282489472673898043")
-	body.Set("out_trade_no", "GYWX201901301040355706100451")
-	body.Set("total_amount", "1.00")
-	//手机APP支付参数请求
+	body.Set("auth_code", "285860185283886370")
+	body.Set("out_trade_no", "GYWX201901301040355706100456")
+	body.Set("total_amount", "10.00")
+	body.Set("timeout_express", "2m")
+	//条码支付
 	aliRsp, err := client.AliPayTradePay(body)
 	if err != nil {
 		fmt.Println("err:", err)
 		return
 	}
-	fmt.Println("aliRsp:", aliRsp)
+	fmt.Println("aliRsp:", *aliRsp)
 }
 
 func TestAliPayClient_AliPayTradeWapPay(t *testing.T) {
@@ -43,7 +44,7 @@ func TestAliPayClient_AliPayTradeWapPay(t *testing.T) {
 	//    isProd:是否是正式环境
 	client := NewAliPayClient("2016091200494382", privateKey, false)
 	//配置公共参数
-	client.SetCharset("utf-8").
+	client.SetCharset("UTF-8").
 		SetSignType("RSA2").
 		//SetReturnUrl("https://www.gopay.ink").
 		SetNotifyUrl("https://api.iguiyu.com/gy_pay/alipay/notify")
@@ -72,7 +73,7 @@ func TestAliPayClient_AliPayTradeAppPay(t *testing.T) {
 	//    isProd:是否是正式环境
 	client := NewAliPayClient("2016091200494382", privateKey, false)
 	//配置公共参数
-	client.SetCharset("utf-8").
+	client.SetCharset("UTF-8").
 		SetSignType("RSA2").
 		SetNotifyUrl("https://api.iguiyu.com/gy_pay/alipay/notify")
 	//请求参数
@@ -97,7 +98,7 @@ func TestAliPayClient_AliPayTradePagePay(t *testing.T) {
 	//    isProd:是否是正式环境
 	client := NewAliPayClient("2016091200494382", privateKey, false)
 	//配置公共参数
-	client.SetCharset("utf-8").
+	client.SetCharset("UTF-8").
 		SetSignType("RSA2").
 		SetNotifyUrl("https://api.iguiyu.com/gy_pay/alipay/notify")
 	//请求参数

+ 3 - 3
alipay_params.go

@@ -25,7 +25,7 @@ import (
 //	Method     string `json:"method"`      //接口名称
 //	Format     string `json:"format"`      //仅支持 JSON
 //	ReturnUrl  string `json:"return_url"`  //HTTP/HTTPS开头字符串
-//	Charset    string `json:"charset"`     //请求使用的编码格式,如utf-8,gbk,gb2312等,推荐使用 utf-8
+//	Charset    string `json:"charset"`     //请求使用的编码格式,如UTF-8,GBK,GB2312等,推荐使用 UTF-8
 //	SignType   string `json:"sign_type"`   //商户生成签名字符串所使用的签名算法类型,目前支持RSA2和RSA,推荐使用 RSA2
 //	Sign       string `json:"sign"`        //商户请求参数的签名串
 //	Timestamp  string `json:"timestamp"`   //发送请求的时间,格式"yyyy-MM-dd HH:mm:ss"
@@ -45,10 +45,10 @@ func (this *aliPayClient) SetNotifyUrl(url string) (client *aliPayClient) {
 	return this
 }
 
-//设置编码格式,如utf-8,gbk,gb2312等,推荐使用 utf-8
+//设置编码格式,如UTF-8,GBK,GB2312等,推荐使用 UTF-8
 func (this *aliPayClient) SetCharset(charset string) (client *aliPayClient) {
 	if charset == null {
-		this.Charset = "utf-8"
+		this.Charset = "UTF-8"
 	} else {
 		this.Charset = charset
 	}

+ 18 - 17
alipay_rsp.go

@@ -42,7 +42,7 @@ type AliPayNotifyRequest struct {
 
 type FundBillListInfo struct {
 	Amount      string `json:"amount"`
-	FundChannel string `json:"fundChannel"`
+	FundChannel string `json:"fund_channel"`
 	BankCode    string `json:"bank_code,omitempty"`
 	RealAmount  string `json:"real_amount,omitempty"`
 }
@@ -62,20 +62,21 @@ type AliPayTradePayResponse struct {
 }
 
 type AlipayTradePayResponseInfo struct {
-	Code           string           `json:"code"`
-	Msg            string           `json:"msg"`
-	SubCode        string           `json:"sub_code"`
-	SubMsg         string           `json:"sub_msg"`
-	TradeNo        string           `json:"trade_no"`
-	OutTradeNo     string           `json:"out_trade_no"`
-	BuyerLogonId   string           `json:"buyer_logon_id"`
-	SettleAmount   string           `json:"settle_amount"`
-	TotalAmount    string           `json:"total_amount"`
-	ReceiptAmount  string           `json:"receipt_amount"`
-	BuyerPayAmount string           `json:"buyer_pay_amount"`
-	PointAmount    string           `json:"point_amount"`
-	InvoiceAmount  string           `json:"invoice_amount"`
-	GmtPayment     string           `json:"gmt_payment"`
-	BuyerUserId    string           `json:"buyer_user_id"`
-	FundBillList   FundBillListInfo `json:"fund_bill_list"`
+	Code           string             `json:"code"`
+	Msg            string             `json:"msg"`
+	SubCode        string             `json:"sub_code"`
+	SubMsg         string             `json:"sub_msg"`
+	TradeNo        string             `json:"trade_no"`
+	OutTradeNo     string             `json:"out_trade_no"`
+	BuyerLogonId   string             `json:"buyer_logon_id"`
+	BuyerPayAmount string             `json:"buyer_pay_amount"`
+	BuyerUserId    string             `json:"buyer_user_id"`
+	BuyerUserType  string             `json:"buyer_user_type"`
+	SettleAmount   string             `json:"settle_amount"`
+	TotalAmount    string             `json:"total_amount"`
+	ReceiptAmount  string             `json:"receipt_amount"`
+	PointAmount    string             `json:"point_amount"`
+	InvoiceAmount  string             `json:"invoice_amount"`
+	GmtPayment     string             `json:"gmt_payment"`
+	FundBillList   []FundBillListInfo `json:"fund_bill_list"`
 }