Przeglądaj źródła

change param name

Jerry 7 lat temu
rodzic
commit
803e90cb7c
5 zmienionych plików z 28 dodań i 28 usunięć
  1. 4 4
      README.md
  2. 9 9
      wechat_client.go
  3. 2 2
      wechat_client_test.go
  4. 7 7
      wechat_params.go
  5. 6 6
      wechat_servier_api.go

+ 4 - 4
README.md

@@ -150,7 +150,7 @@ return c.String(http.StatusOK, rsp.ToXmlString())
 //初始化微信客户端
 //    appId:应用ID
 //    mchID:商户ID
-//    secretKey:Key
+//    apiKey:API秘钥
 //    isProd:是否是正式环境
 client := gopay.NewWeChatClient("wxd678efh567hg6787", "1230000109", "192006250b4c09247ec02edce69f6a2d", false)
 
@@ -197,7 +197,7 @@ fmt.Println("MwebUrl:", wxRsp.MwebUrl)
 //初始化微信客户端
 //    appId:应用ID
 //    mchID:商户ID
-//    secretKey:Key
+//    apiKey:API秘钥
 //    isProd:是否是正式环境
 client := gopay.NewWeChatClient("wxd678efh567hg6787", "1230000109", "192006250b4c09247ec02edce69f6a2d", false)
 
@@ -227,7 +227,7 @@ fmt.Println("Response:", wxRsp)
 //初始化微信客户端
 //    appId:应用ID
 //    mchID:商户ID
-//    secretKey:Key
+//    apiKey:API秘钥
 //    isProd:是否是正式环境
 client := gopay.NewWeChatClient("wxd678efh567hg6787", "1230000109", "192006250b4c09247ec02edce69f6a2d", false)
 
@@ -278,7 +278,7 @@ fmt.Println("Response:", wxRsp)
 //初始化微信客户端
 //    appId:应用ID
 //    mchID:商户ID
-//    secretKey:Key
+//    apiKey:API秘钥
 //    isProd:是否是正式环境
 client := gopay.NewWeChatClient("wxd678efh567hg6787", "1230000109", "192006250b4c09247ec02edce69f6a2d", false)
 

+ 9 - 9
wechat_client.go

@@ -9,22 +9,22 @@ import (
 )
 
 type weChatClient struct {
-	AppId     string
-	MchId     string
-	secretKey string
-	isProd    bool
+	AppId  string
+	MchId  string
+	apiKey string
+	isProd bool
 }
 
 //初始化微信客户端 ok
 //    appId:应用ID
 //    MchID:商户ID
-//    secretKey:Key
+//    apiKey:API秘钥
 //    isProd:是否是正式环境
-func NewWeChatClient(appId, mchId, secretKey string, isProd bool) *weChatClient {
+func NewWeChatClient(appId, mchId, apiKey string, isProd bool) *weChatClient {
 	client := new(weChatClient)
 	client.AppId = appId
 	client.MchId = mchId
-	client.secretKey = secretKey
+	client.apiKey = apiKey
 	client.isProd = isProd
 	return client
 }
@@ -347,7 +347,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.secretKey, body.Get("sign_type"))
+		key, err := getSanBoxSign(this.MchId, body.Get("nonce_str"), this.apiKey, body.Get("sign_type"))
 		if err != nil {
 			return nil, err
 		}
@@ -355,7 +355,7 @@ func (this *weChatClient) doWeChat(body BodyMap, url string, tlsConfig ...*tls.C
 	} else {
 		//正式环境
 		//本地计算Sign
-		sign = getLocalSign(this.secretKey, body.Get("sign_type"), body)
+		sign = getLocalSign(this.apiKey, body.Get("sign_type"), body)
 	}
 	body.Set("sign", sign)
 	reqXML := generateXml(body)

+ 2 - 2
wechat_client_test.go

@@ -16,7 +16,7 @@ func TestWeChatClient_UnifiedOrder(t *testing.T) {
 	//初始化微信客户端
 	//    appId:应用ID
 	//    MchID:商户ID
-	//    secretKey:Key
+	//    apiKey:API秘钥
 	//    isProd:是否是正式环境
 	client := NewWeChatClient(AppID, MchID, secretKey, false)
 
@@ -53,7 +53,7 @@ func TestWeChatClient_QueryOrder(t *testing.T) {
 	//初始化微信客户端
 	//    appId:应用ID
 	//    MchID:商户ID
-	//    secretKey:Key
+	//    apiKey:API秘钥
 	//    isProd:是否是正式环境
 	client := NewWeChatClient(AppID, MchID, secretKey, false)
 

+ 7 - 7
wechat_params.go

@@ -14,8 +14,8 @@ import (
 )
 
 //本地通过支付参数计算Sign值
-func getLocalSign(secretKey string, signType string, body BodyMap) (sign string) {
-	signStr := sortSignParams(secretKey, body)
+func getLocalSign(apiKey string, signType string, body BodyMap) (sign string) {
+	signStr := sortSignParams(apiKey, body)
 	//fmt.Println("signStr:", signStr)
 	var hashSign []byte
 	if signType == SignType_MD5 {
@@ -23,7 +23,7 @@ func getLocalSign(secretKey string, signType string, body BodyMap) (sign string)
 		hash.Write([]byte(signStr))
 		hashSign = hash.Sum(nil)
 	} else {
-		hash := hmac.New(sha256.New, []byte(secretKey))
+		hash := hmac.New(sha256.New, []byte(apiKey))
 		hash.Write([]byte(signStr))
 		hashSign = hash.Sum(nil)
 	}
@@ -32,7 +32,7 @@ func getLocalSign(secretKey string, signType string, body BodyMap) (sign string)
 }
 
 //获取根据Key排序后的请求参数字符串
-func sortSignParams(secretKey string, body BodyMap) string {
+func sortSignParams(apiKey string, body BodyMap) string {
 	keyList := make([]string, 0)
 	for k := range body {
 		keyList = append(keyList, k)
@@ -49,18 +49,18 @@ func sortSignParams(secretKey string, body BodyMap) string {
 		buffer.WriteString("&")
 	}
 	buffer.WriteString("key=")
-	buffer.WriteString(secretKey)
+	buffer.WriteString(apiKey)
 	return buffer.String()
 }
 
 //从微信提供的接口获取:SandboxSignKey
-func getSanBoxSign(mchId, nonceStr, secretKey, signType string) (key string, err error) {
+func getSanBoxSign(mchId, nonceStr, apiKey, signType string) (key string, err error) {
 	body := make(BodyMap)
 	body.Set("mch_id", mchId)
 	body.Set("nonce_str", nonceStr)
 
 	//计算沙箱参数Sign
-	sanboxSign := getLocalSign(secretKey, signType, body)
+	sanboxSign := getLocalSign(apiKey, signType, body)
 	//沙箱环境:获取key后,重新计算Sign
 	key, err = getSanBoxSignKey(mchId, nonceStr, sanboxSign)
 	if err != nil {

+ 6 - 6
wechat_servier_api.go

@@ -29,7 +29,7 @@ func HttpAgent() (agent *gorequest.SuperAgent) {
 }
 
 //JSAPI支付,支付参数后,再次计算出小程序用的paySign
-func GetMiniPaySign(appId, nonceStr, prepayId, signType, timeStamp, secretKey string) (paySign string) {
+func GetMiniPaySign(appId, nonceStr, prepayId, signType, timeStamp, apiKey string) (paySign string) {
 	buffer := new(bytes.Buffer)
 	buffer.WriteString("appId=")
 	buffer.WriteString(appId)
@@ -47,7 +47,7 @@ func GetMiniPaySign(appId, nonceStr, prepayId, signType, timeStamp, secretKey st
 	buffer.WriteString(timeStamp)
 
 	buffer.WriteString("&key=")
-	buffer.WriteString(secretKey)
+	buffer.WriteString(apiKey)
 
 	signStr := buffer.String()
 
@@ -57,7 +57,7 @@ func GetMiniPaySign(appId, nonceStr, prepayId, signType, timeStamp, secretKey st
 		hash.Write([]byte(signStr))
 		hashSign = hash.Sum(nil)
 	} else {
-		hash := hmac.New(sha256.New, []byte(secretKey))
+		hash := hmac.New(sha256.New, []byte(apiKey))
 		hash.Write([]byte(signStr))
 		hashSign = hash.Sum(nil)
 	}
@@ -66,7 +66,7 @@ func GetMiniPaySign(appId, nonceStr, prepayId, signType, timeStamp, secretKey st
 }
 
 //JSAPI支付,支付参数后,再次计算出微信内H5支付需要用的paySign
-func GetH5PaySign(appId, nonceStr, prepayId, signType, timeStamp, secretKey string) (paySign string) {
+func GetH5PaySign(appId, nonceStr, prepayId, signType, timeStamp, apiKey string) (paySign string) {
 	buffer := new(bytes.Buffer)
 	buffer.WriteString("appId=")
 	buffer.WriteString(appId)
@@ -84,7 +84,7 @@ func GetH5PaySign(appId, nonceStr, prepayId, signType, timeStamp, secretKey stri
 	buffer.WriteString(timeStamp)
 
 	buffer.WriteString("&key=")
-	buffer.WriteString(secretKey)
+	buffer.WriteString(apiKey)
 
 	signStr := buffer.String()
 
@@ -94,7 +94,7 @@ func GetH5PaySign(appId, nonceStr, prepayId, signType, timeStamp, secretKey stri
 		hash.Write([]byte(signStr))
 		hashSign = hash.Sum(nil)
 	} else {
-		hash := hmac.New(sha256.New, []byte(secretKey))
+		hash := hmac.New(sha256.New, []byte(apiKey))
 		hash.Write([]byte(signStr))
 		hashSign = hash.Sum(nil)
 	}