Jerry 6 سال پیش
والد
کامیت
d9d7e86abf
2فایلهای تغییر یافته به همراه7 افزوده شده و 7 حذف شده
  1. 4 4
      wechat_client_test.go
  2. 3 3
      wechat_params.go

+ 4 - 4
wechat_client_test.go

@@ -97,18 +97,18 @@ func TestWeChatClient_Refund(t *testing.T) {
 	//    MchID:商户ID
 	//    ApiKey:Key值
 	//    isProd:是否是正式环境
-	client := NewWeChatClient(AppID, MchID2, ApiKey2, true)
+	client := NewWeChatClient(AppID, MchID, ApiKey, true)
 
 	//初始化参数结构体
 	body := make(BodyMap)
-	body.Set("out_trade_no", "GYWX201906262222504974571772")
+	body.Set("out_trade_no", "GYWX201906262259301513873050")
 	body.Set("nonce_str", GetRandomString(32))
 	body.Set("sign_type", SignType_MD5)
 	s := GetRandomString(64)
 	fmt.Println("s:", s)
 	body.Set("out_refund_no", s)
-	body.Set("total_fee", 500)
-	body.Set("refund_fee", 500)
+	body.Set("total_fee", 1500)
+	body.Set("refund_fee", 1500)
 
 	//请求申请退款(沙箱环境下,证书路径参数可传空)
 	//    body:参数Body

+ 3 - 3
wechat_params.go

@@ -18,12 +18,12 @@ func getLocalSign(apiKey string, signType string, body BodyMap) (sign string) {
 	signStr := sortWeChatSignParams(apiKey, body)
 	//fmt.Println("signStr:", signStr)
 	var hashSign []byte
-	if signType == SignType_MD5 {
-		hash := md5.New()
+	if signType == SignType_HMAC_SHA256 {
+		hash := hmac.New(sha256.New, []byte(apiKey))
 		hash.Write([]byte(signStr))
 		hashSign = hash.Sum(nil)
 	} else {
-		hash := hmac.New(sha256.New, []byte(apiKey))
+		hash := md5.New()
 		hash.Write([]byte(signStr))
 		hashSign = hash.Sum(nil)
 	}