Jerry 6 лет назад
Родитель
Сommit
317c5fed26
2 измененных файлов с 10 добавлено и 3 удалено
  1. 9 2
      alipay_client.go
  2. 1 1
      alipay_client_test.go

+ 9 - 2
alipay_client.go

@@ -3,7 +3,9 @@ package gopay
 import (
 	"encoding/json"
 	"errors"
+	"fmt"
 	"github.com/parnurzeal/gorequest"
+	"golang.org/x/text/encoding/simplifiedchinese"
 	"log"
 	"time"
 )
@@ -76,12 +78,17 @@ func (this *aliPayClient) AliPayTradePay(body BodyMap) (aliRsp *AliPayTradePayRe
 		return nil, err
 	}
 
-	//log.Println("string::::", string(bytes))
+	convertBytes, _ := simplifiedchinese.GBK.NewDecoder().Bytes(bytes)
+	//log.Println("convertBytes::::", string(convertBytes))
 	aliRsp = new(AliPayTradePayResponse)
-	err = json.Unmarshal(bytes, aliRsp)
+	err = json.Unmarshal(convertBytes, aliRsp)
 	if err != nil {
 		return nil, err
 	}
+	if aliRsp.AlipayTradePayResponse.Code != "10000" {
+		info := aliRsp.AlipayTradePayResponse
+		return nil, fmt.Errorf("code:%v,msg:%v,sub_code:%v,sub_msg:%v.", info.Code, info.Msg, info.SubCode, info.SubMsg)
+	}
 	return aliRsp, nil
 }
 

+ 1 - 1
alipay_client_test.go

@@ -22,7 +22,7 @@ func TestAliPayClient_AliPayTradePay(t *testing.T) {
 	body := make(BodyMap)
 	body.Set("subject", "条码支付")
 	body.Set("scene", "bar_code")
-	body.Set("auth_code", "285860185283886370")
+	body.Set("auth_code", "285860185283886375")
 	body.Set("out_trade_no", "GYWX201901301040355706100456")
 	body.Set("total_amount", "10.00")
 	body.Set("timeout_express", "2m")