Jerry 6 years ago
parent
commit
ec5f690e7d
6 changed files with 21 additions and 20 deletions
  1. 1 1
      alipay_client_test.go
  2. 9 0
      util.go
  3. 3 1
      wechat_client.go
  4. 7 9
      wechat_client_test.go
  5. 1 2
      wechat_params.go
  6. 0 7
      wechat_servier_api.go

+ 1 - 1
alipay_client_test.go

@@ -151,7 +151,7 @@ func TestAliPayClient_AliPayTradeWapPay(t *testing.T) {
 	//请求参数
 	body := make(BodyMap)
 	body.Set("subject", "手机网站测试支付")
-	body.Set("out_trade_no", "GZ201901301040355706100470")
+	body.Set("out_trade_no", "GZ201901301040355706100477")
 	body.Set("quit_url", "https://www.gopay.ink")
 	body.Set("total_amount", "100.00")
 	body.Set("product_code", "QUICK_WAP_WAY")

+ 9 - 0
util.go

@@ -1,6 +1,8 @@
 package gopay
 
 import (
+	"crypto/tls"
+	"github.com/parnurzeal/gorequest"
 	"math/rand"
 	"reflect"
 	"strconv"
@@ -61,6 +63,13 @@ func (bm BodyMap) Remove(key string) {
 	delete(bm, key)
 }
 
+//HttpAgent
+func HttpAgent() (agent *gorequest.SuperAgent) {
+	agent = gorequest.New()
+	agent.TLSClientConfig(&tls.Config{InsecureSkipVerify: true})
+	return
+}
+
 //获取随机字符串
 //    length:字符串长度
 func GetRandomString(length int) string {

+ 3 - 1
wechat_client.go

@@ -79,6 +79,7 @@ func (this *weChatClient) UnifiedOrder(body BodyMap) (wxRsp *WeChatUnifiedOrderR
 	}
 
 	wxRsp = new(WeChatUnifiedOrderResponse)
+	//fmt.Println("bytes:", string(bytes))
 	err = xml.Unmarshal(bytes, wxRsp)
 	if err != nil {
 		return nil, err
@@ -347,7 +348,7 @@ func (this *weChatClient) doWeChat(body BodyMap, url string, tlsConfig ...*tls.C
 		//沙箱环境
 		body.Set("sign_type", SignType_MD5)
 		//从微信接口获取SanBoxSignKey
-		key, err := getSanBoxSign(this.MchId, body.Get("nonce_str"), this.apiKey, body.Get("sign_type"))
+		key, err := getSanBoxSign(this.MchId, body.Get("nonce_str"), this.apiKey, SignType_MD5)
 		if err != nil {
 			return nil, err
 		}
@@ -359,6 +360,7 @@ func (this *weChatClient) doWeChat(body BodyMap, url string, tlsConfig ...*tls.C
 	}
 	body.Set("sign", sign)
 	reqXML := generateXml(body)
+	//fmt.Println("reqXML:",reqXML)
 	//===============发起请求===================
 	agent := gorequest.New()
 

+ 7 - 9
wechat_client_test.go

@@ -5,10 +5,8 @@ import (
 	"encoding/hex"
 	"fmt"
 	"log"
-	"strconv"
 	"strings"
 	"testing"
-	"time"
 )
 
 func TestWeChatClient_UnifiedOrder(t *testing.T) {
@@ -26,8 +24,8 @@ func TestWeChatClient_UnifiedOrder(t *testing.T) {
 	number := GetRandomString(32)
 	fmt.Println("out_trade_no:", number)
 	body.Set("out_trade_no", number)
-	body.Set("total_fee", 10)
-	body.Set("spbill_create_ip", "124.77.173.62")
+	body.Set("total_fee", 1)
+	body.Set("spbill_create_ip", "127.0.0.1")
 	body.Set("notify_url", "http://www.gopay.ink")
 	body.Set("trade_type", TradeType_JsApi)
 	body.Set("device_info", "WEB")
@@ -42,11 +40,11 @@ func TestWeChatClient_UnifiedOrder(t *testing.T) {
 		return
 	}
 	fmt.Println("wxRsp:", *wxRsp)
-	timeStamp := strconv.FormatInt(time.Now().Unix(), 10)
-	//获取小程序需要的paySign
-	pac := "prepay_id=" + wxRsp.PrepayId
-	paySign := GetMiniPaySign(AppID, wxRsp.NonceStr, pac, SignType_MD5, timeStamp, ApiKey_iguiyu)
-	fmt.Println("paySign:", paySign)
+	//timeStamp := strconv.FormatInt(time.Now().Unix(), 10)
+	////获取小程序需要的paySign
+	//pac := "prepay_id=" + wxRsp.PrepayId
+	//paySign := GetMiniPaySign(AppID, wxRsp.NonceStr, pac, SignType_MD5, timeStamp, ApiKey_iguiyu)
+	//fmt.Println("paySign:", paySign)
 }
 
 func TestWeChatClient_QueryOrder(t *testing.T) {

+ 1 - 2
wechat_params.go

@@ -8,7 +8,6 @@ import (
 	"encoding/hex"
 	"encoding/xml"
 	"errors"
-	"github.com/parnurzeal/gorequest"
 	"sort"
 	"strings"
 )
@@ -78,7 +77,7 @@ func getSanBoxSignKey(mchId, nonceStr, sign string) (key string, err error) {
 
 	reqXml := generateXml(reqs)
 	//fmt.Println("req:::", reqXml)
-	_, byteList, errorList := gorequest.New().
+	_, byteList, errorList := HttpAgent().
 		Post(wxURL_SanBox_GetSignKey).
 		Type("xml").
 		SendString(reqXml).EndBytes()

+ 0 - 7
wechat_servier_api.go

@@ -12,7 +12,6 @@ import (
 	"crypto/hmac"
 	"crypto/md5"
 	"crypto/sha256"
-	"crypto/tls"
 	"encoding/base64"
 	"encoding/hex"
 	"encoding/json"
@@ -24,12 +23,6 @@ import (
 	"strings"
 )
 
-func HttpAgent() (agent *gorequest.SuperAgent) {
-	agent = gorequest.New()
-	agent.TLSClientConfig(&tls.Config{InsecureSkipVerify: true})
-	return
-}
-
 //解析支付完成后的Notify信息
 func ParseNotifyResult(req *http.Request) (notifyRsp *WeChatNotifyRequest, err error) {
 	notifyRsp = new(WeChatNotifyRequest)