Skip to content

Commit

Permalink
v1.4.4
Browse files Browse the repository at this point in the history
  • Loading branch information
iGoogle-ink committed Nov 16, 2019
1 parent 3f1b42f commit 8c6f9a5
Show file tree
Hide file tree
Showing 10 changed files with 186 additions and 139 deletions.
27 changes: 21 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@
* gopay.AliPaySystemOauthToken() => 换取授权访问令牌(得到access_token,user_id等信息)
* gopay.FormatPrivateKey() => 格式化应用私钥
* gopay.FormatAliPayPublicKey() => 格式化支付宝公钥
* gopay.ParseAliPayNotifyResult() => 解析并返回支付宝支付异步通知的参数
* gopay.ParseAliPayNotifyResult() => 解析支付宝支付异步通知的参数到Struct
* gopay.ParseAliPayNotifyResultToBodyMap() => 解析支付宝支付异步通知的参数到BodyMap
* gopay.VerifyAliPaySign() => 支付宝同步返回参数验签或异步通知参数验签
* gopay.DecryptAliPayOpenDataToStruct() => 支付宝小程序敏感加密数据解析到结构体

Expand Down Expand Up @@ -145,28 +146,42 @@ QQ群:

---

## 1、初始化GoPay客户端并做配置(所有https请求,已忽略https双向认证:InsecureSkipVerify: true)
## 1、初始化GoPay客户端并做配置(HTTP请求均设置tls.Config{InsecureSkipVerify: true})

* #### 微信客户端,如无需更改Appid、Mchid和ApiKey,推荐在 init()方法中初始化,全局适用
* #### 微信客户端,如无需更改Appid、Mchid和ApiKey等参数,可在init()方法中初始化,全局适用

微信官方文档:[官方文档](https://pay.weixin.qq.com/wiki/doc/api/index.html)
```go
//初始化微信客户端
// 初始化微信客户端
// appId:应用ID
// mchId:商户ID
// apiKey:API秘钥值
// isProd:是否是正式环境
client := gopay.NewWeChatClient("wxdaa2ab9ef87b5497", mchId, apiKey, false)

//设置国家:不设置默认 中国国内
// 设置国家:不设置默认 中国国内
// gopay.China:中国国内
// gopay.China2:中国国内备用
// gopay.SoutheastAsia:东南亚
// gopay.Other:其他国家
client.SetCountry(gopay.China)

// 添加微信证书 Byte 数组
// certFile:apiclient_cert.pem byte数组
// keyFile:apiclient_key.pem byte数组
// pkcs12File:apiclient_cert.p12 byte数组
client.AddCertFileByte()

// 添加微信证书 Path 路径
// certFilePath:apiclient_cert.pem 路径
// keyFilePath:apiclient_key.pem 路径
// pkcs12FilePath:apiclient_cert.p12 路径
// 返回err
client.AddCertFilePath()

```

* #### 支付宝,如无需更改Appid和PrivateKey,推荐在 init()方法中初始化,全局适用
* #### 支付宝,如无需更改Appid和PrivateKey等参数,可在init()方法中初始化,全局适用

支付宝官方文档:[官方文档](https://docs.open.alipay.com/catalog)

Expand Down
2 changes: 2 additions & 0 deletions alipay_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"strings"
"sync"
"time"

"github.com/parnurzeal/gorequest"
Expand All @@ -22,6 +23,7 @@ type AliPayClient struct {
AppAuthToken string
AuthToken string
IsProd bool
mu sync.RWMutex
}

// 初始化支付宝客户端
Expand Down
16 changes: 16 additions & 0 deletions alipay_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,58 +39,74 @@ type OpenApiRoyaltyDetailInfoPojo struct {
// 设置 应用公钥证书SN
// appCertSN:应用公钥证书SN,通过 gopay.GetCertSN() 获取
func (a *AliPayClient) SetAppCertSN(appCertSN string) (client *AliPayClient) {
a.mu.Lock()
a.AppCertSN = appCertSN
a.mu.Unlock()
return a
}

// 设置 支付宝根证书SN
// alipayRootCertSN:支付宝根证书SN,通过 gopay.GetCertSN() 获取
func (a *AliPayClient) SetAliPayRootCertSN(alipayRootCertSN string) (client *AliPayClient) {
a.mu.Lock()
a.AlipayRootCertSN = alipayRootCertSN
a.mu.Unlock()
return a
}

// 设置支付后的ReturnUrl
func (a *AliPayClient) SetReturnUrl(url string) (client *AliPayClient) {
a.mu.Lock()
a.ReturnUrl = url
a.mu.Unlock()
return a
}

// 设置支付宝服务器主动通知商户服务器里指定的页面http/https路径。
func (a *AliPayClient) SetNotifyUrl(url string) (client *AliPayClient) {
a.mu.Lock()
a.NotifyUrl = url
a.mu.Unlock()
return a
}

// 设置编码格式,如utf-8,gbk,gb2312等,默认推荐使用 utf-8
func (a *AliPayClient) SetCharset(charset string) (client *AliPayClient) {
a.mu.Lock()
if charset == null {
a.Charset = "utf-8"
} else {
a.Charset = charset
}
a.mu.Unlock()
return a
}

// 设置签名算法类型,目前支持RSA2和RSA,默认推荐使用 RSA2
func (a *AliPayClient) SetSignType(signType string) (client *AliPayClient) {
a.mu.Lock()
if signType == null {
a.SignType = "RSA2"
} else {
a.SignType = signType
}
a.mu.Unlock()
return a
}

// 设置应用授权
func (a *AliPayClient) SetAppAuthToken(appAuthToken string) (client *AliPayClient) {
a.mu.Lock()
a.AppAuthToken = appAuthToken
a.mu.Unlock()
return a
}

// 设置用户信息授权
func (a *AliPayClient) SetAuthToken(authToken string) (client *AliPayClient) {
a.mu.Lock()
a.AuthToken = authToken
a.mu.Unlock()
return a
}

Expand Down
4 changes: 2 additions & 2 deletions alipay_service_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ var allowSignatureAlgorithm = map[string]bool{
"SHA512-RSAPSS": true,
}

// 解析支付宝支付异步通知的结果到BodyMap
// 解析支付宝支付异步通知的参数到BodyMap
// req:*http.Request
// 返回参数bm:Notify请求的参数
// 返回参数err:错误信息
Expand All @@ -53,7 +53,7 @@ func ParseAliPayNotifyResultToBodyMap(req *http.Request) (bm BodyMap, err error)
return
}

// ParseAliPayNotifyResult 解析支付宝支付完成后的Notify信息
// 解析支付宝支付异步通知的参数到Struct
// req:*http.Request
// 返回参数notifyReq:Notify请求的参数
// 返回参数err:错误信息
Expand Down
2 changes: 1 addition & 1 deletion constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const (
null string = ""
TimeLayout string = "2006-01-02 15:04:05"
DateLayout string = "2006-01-02"
Version string = "1.4.3"
Version string = "1.4.4"
// 微信
// ===========================================================================================

Expand Down
35 changes: 16 additions & 19 deletions examples/wechat/wx_Transfer.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
//==================================
// * Name:Jerry
// * DateTime:2019/8/21 21:02
// * Desc:
//==================================
package wechat

import (
Expand All @@ -12,34 +7,36 @@ import (
)

func Transfer() {
//初始化微信客户端
// 初始化微信客户端
// appId:应用ID
// MchID:商户ID
// ApiKey:Key值
// isProd:是否是正式环境(企业转账到个人账户,默认正式环境)
client := gopay.NewWeChatClient("wxdaa2ab9ef87b5497", "1368139502", "GFDS8j98rewnmgl45wHTt980jg543abc", true)
client := gopay.NewWeChatClient("wxdaa2ab9ef87b5497", "1368139502", "GFDS8j98rewnmgl45wHTt980jg543abc", false)

nonceStr := gopay.GetRandomString(32)
partnerTradeNo := gopay.GetRandomString(32)
err := client.AddCertFilePath("iguiyu_cert/apiclient_cert.pem", "iguiyu_cert/apiclient_key.pem", "iguiyu_cert/apiclient_cert.p12")
if err != nil {
fmt.Println("client.AddCertFilePath err:", err)
return
}

fmt.Println("partnerTradeNo:", partnerTradeNo)
//初始化参数结构体
// 初始化参数结构体
body := make(gopay.BodyMap)
body.Set("nonce_str", nonceStr)
body.Set("partner_trade_no", partnerTradeNo)
body.Set("openid", "oMlss5F06l97UpwtB-8jvZd6Yabc")
body.Set("nonce_str", gopay.GetRandomString(32))
body.Set("partner_trade_no", gopay.GetRandomString(32))
body.Set("openid", "o0Df70H2Q0fY8JXh1aFPIRyOBgu8")
body.Set("check_name", "FORCE_CHECK") // NO_CHECK:不校验真实姓名 , FORCE_CHECK:强校验真实姓名
body.Set("re_user_name", "付明明") //收款用户真实姓名。 如果check_name设置为FORCE_CHECK,则必填用户真实姓名
body.Set("amount", 30) //企业付款金额,单位为分
body.Set("desc", "测试转账") //企业付款备注,必填。注意:备注中的敏感词会被转成字符*
body.Set("re_user_name", "付明明") // 收款用户真实姓名。 如果check_name设置为FORCE_CHECK,则必填用户真实姓名
body.Set("amount", 30) // 企业付款金额,单位为分
body.Set("desc", "测试转账") // 企业付款备注,必填。注意:备注中的敏感词会被转成字符*
body.Set("spbill_create_ip", "127.0.0.1")

//请求申请退款(沙箱环境下,证书路径参数可传空)
// 请求申请退款(沙箱环境下,证书路径参数可传空)
// body:参数Body
// certFilePath:cert证书路径
// keyFilePath:Key证书路径
// pkcs12FilePath:p12证书路径
wxRsp, err := client.Transfer(body, "iguiyu_cert/apiclient_cert.pem", "iguiyu_cert/apiclient_key.pem", "iguiyu_cert/apiclient_cert.p12")
wxRsp, err := client.Transfer(body, "", "", "")
if err != nil {
fmt.Println("Error:", err)
return
Expand Down
12 changes: 12 additions & 0 deletions release_note.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
版本号:Release 1.4.4
发布时间:2019/11/16 15:56
修改记录:
(1) 支付宝:新增公共API方法:gopay.ParseAliPayNotifyResultToBodyMap(),解析支付宝支付异步通知的参数到BodyMap
(2) 支付宝:修改公共API方法:gopay.VerifyAliPaySign(),支付宝异步验签支持传入 BodyMap
(3) 微信:新增Client方法:client.AddCertFileByte(),添加微信证书 Byte 数组
(4) 微信:新增Client方法:client.AddCertFilePath(),添加微信证书 Path 路径
(5) 微信:微信Client需要证书的方法,如已使用client.AddCertFilePath()或client.AddCertFileByte()添加过证书,参数certFilePath、keyFilePath、pkcs12FilePath全传空字符串 "",如方法需单独使用证书,则传证书Path
(6) BodyMap 的Set方法去掉switch判断,直接赋值
(7) WeChatClient、AliPayClient 加锁
(8) 修改部分小问题和部分样式

版本号:Release 1.4.3
发布时间:2019/11/12 01:15
修改记录:
Expand Down
4 changes: 2 additions & 2 deletions util.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ func (bm BodyMap) Get(key string) string {
if v, ok = value.(string); ok {
return v
}
return jsonToString(value)
return convertToString(value)
}

func jsonToString(v interface{}) (str string) {
func convertToString(v interface{}) (str string) {
if v == nil {
return null
}
Expand Down
Loading

0 comments on commit 8c6f9a5

Please sign in to comment.