Skip to content

Commit

Permalink
Wechat/remove method cert param (#133)
Browse files Browse the repository at this point in the history
v1.5.38
  • Loading branch information
iGoogle-ink authored Apr 21, 2021
1 parent 0ad1c27 commit 18c6960
Show file tree
Hide file tree
Showing 16 changed files with 152 additions and 197 deletions.
44 changes: 14 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,7 @@
[![GitHub Release](https://img.shields.io/github/v/release/iGoogle-ink/gopay)](https://github.com/iGoogle-ink/gopay/releases)
[![License](https://img.shields.io/github/license/iGoogle-ink/gopay)](https://www.apache.org/licenses/LICENSE-2.0)

---

## ★招聘广告★:

有意向的请直接加我微信(文档说明处有我的微信二维码)

- 公司:上海商米科技集团股份有限公司
- 要求:3-5年后端工程师(Golang)
- 地点:上海市杨浦区五角场

---
---

# 一、安装

Expand Down Expand Up @@ -301,7 +291,7 @@ client.DebugSwitch = gopay.DebugOff

> 注意:微信支付下单等操作可用沙箱环境测试是否成功,但真正支付时,请使用正式环境 isProd = true,不然会报错。
> 微信证书现已支持二选一:只传 apiclient_cert.pem 和 apiclient_key.pem 或者只传 apiclient_cert.p12
> 微信证书二选一:只传 apiclient_cert.pem 和 apiclient_key.pem 或者只传 apiclient_cert.p12
```go
import (
Expand All @@ -325,19 +315,13 @@ client.DebugSwitch = gopay.DebugOn
// wechat.Other:其他国家
client.SetCountry(wechat.China)

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

// 添加微信证书内容 Content
// certFileContent:apiclient_cert.pem 内容
// keyFileContent:apiclient_key.pem 内容
// pkcs12FileContent:apiclient_cert.p12 内容
// 返回err
client.AddCertFileContent()
// 添加微信pem证书
client.AddCertPemFilePath()
client.AddCertPemFileContent()

// 添加微信pkcs12证书
client.AddCertPkcs12FilePath()
client.AddCertPkcs12FileContent()
```

* #### 支付宝
Expand Down Expand Up @@ -472,13 +456,13 @@ wxRsp, err := client.UnifiedOrder(bm)
wxRsp, err := client.Micropay(bm)
wxRsp, err := client.QueryOrder(bm)
wxRsp, err := client.CloseOrder(bm)
wxRsp, err := client.Reverse(bm, "apiclient_cert.pem", "apiclient_key.pem", "apiclient_cert.p12")
wxRsp, err := client.Refund(bm, "apiclient_cert.pem", "apiclient_key.pem", "apiclient_cert.p12")
wxRsp, err := client.Reverse(bm)
wxRsp, err := client.Refund(bm)
wxRsp, err := client.QueryRefund(bm)
wxRsp, err := client.DownloadBill(bm)
wxRsp, err := client.DownloadFundFlow(bm, "apiclient_cert.pem", "apiclient_key.pem", "apiclient_cert.p12")
wxRsp, err := client.BatchQueryComment(bm, "apiclient_cert.pem", "apiclient_key.pem", "apiclient_cert.p12")
wxRsp, err := client.Transfer(bm, "apiclient_cert.pem", "apiclient_key.pem", "apiclient_cert.p12")
wxRsp, err := client.DownloadFundFlow(bm)
wxRsp, err := client.BatchQueryComment(bm)
wxRsp, err := client.Transfer(bm)
```

* #### 支付宝 client
Expand Down
2 changes: 1 addition & 1 deletion constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const (
OK = "OK"
DebugOff = 0
DebugOn = 1
Version = "1.5.37"
Version = "1.5.38"
)

type DebugSwitch int8
2 changes: 1 addition & 1 deletion examples/wechat/wx_BatchQueryComment.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func BatchQueryComment() {
Set("offset", "0")

// 请求拉取订单评价数据,成功后得到结果,沙箱环境下,证书路径参数可传空
wxRsp, err := client.BatchQueryComment(bm, nil, nil, nil)
wxRsp, err := client.BatchQueryComment(bm)
if err != nil {
xlog.Error(err)
return
Expand Down
2 changes: 1 addition & 1 deletion examples/wechat/wx_DownloadFundFlow.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func DownloadFundFlow() {
Set("account_type", "Basic")

// 请求下载资金账单,成功后得到结果,沙箱环境下,证书路径参数可传空
wxRsp, err := client.DownloadFundFlow(bm, nil, nil, nil)
wxRsp, err := client.DownloadFundFlow(bm)
if err != nil {
xlog.Error(err)
return
Expand Down
2 changes: 1 addition & 1 deletion examples/wechat/wx_Refund.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func Refund() {
// certFilePath:cert证书路径
// keyFilePath:Key证书路径
// pkcs12FilePath:p12证书路径
wxRsp, resBm, err := client.Refund(bm, "iguiyu_cert/apiclient_cert.pem", "iguiyu_cert/apiclient_key.pem", "iguiyu_cert/apiclient_cert.p12")
wxRsp, resBm, err := client.Refund(bm)
if err != nil {
xlog.Error(err)
return
Expand Down
2 changes: 1 addition & 1 deletion examples/wechat/wx_Reverse.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func Reverse() {
Set("sign_type", wechat.SignType_MD5)

//请求撤销订单,成功后得到结果,沙箱环境下,证书路径参数可传空
wxRsp, err := client.Reverse(bm, nil, nil, nil)
wxRsp, err := client.Reverse(bm)
if err != nil {
xlog.Error(err)
return
Expand Down
2 changes: 1 addition & 1 deletion examples/wechat/wx_Transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func Transfer() {
// certFilePath:cert证书路径
// keyFilePath:Key证书路径
// pkcs12FilePath:p12证书路径
wxRsp, err := client.Transfer(bm, nil, nil, nil)
wxRsp, err := client.Transfer(bm)
if err != nil {
xlog.Error(err)
return
Expand Down
5 changes: 5 additions & 0 deletions release_note.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
版本号:Release 1.5.38
修改记录:
(1) 微信:去掉所以微信 client 方法中需要传证书的参数,请统一在初始化client时,添加证书
(2) 微信:使用方法请参考 wechat/client_test.go 下的初始化,以及各个方法使用

版本号:Release 1.5.37
修改记录:
(1) 支付宝:修改 client.FundAuthOrderAppFreeze() 接口返回参数
Expand Down
18 changes: 6 additions & 12 deletions wechat/base_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,9 @@ func (w *Client) CloseOrder(bm gopay.BodyMap) (wxRsp *CloseOrderResponse, err er
}

// 申请退款
// 注意:如已使用client.AddCertFilePath()或client.AddCertFileContent()添加过证书,参数certFilePath、keyFilePath、pkcs12FilePath全传 nil,否则,3证书Path均不可空
// 注意:请在初始化client时,调用 client 添加证书的相关方法添加证书
// 文档地址:https://pay.weixin.qq.com/wiki/doc/api/wxpay_v2/open/chapter3_4.shtml
func (w *Client) Refund(bm gopay.BodyMap, certFilePath, keyFilePath, pkcs12FilePath interface{}) (wxRsp *RefundResponse, resBm gopay.BodyMap, err error) {
if err = checkCertFilePathOrContent(certFilePath, keyFilePath, pkcs12FilePath); err != nil {
return nil, nil, err
}
func (w *Client) Refund(bm gopay.BodyMap) (wxRsp *RefundResponse, resBm gopay.BodyMap, err error) {
err = bm.CheckEmptyError("nonce_str", "out_refund_no", "total_fee", "refund_fee")
if err != nil {
return nil, nil, err
Expand All @@ -130,7 +127,7 @@ func (w *Client) Refund(bm gopay.BodyMap, certFilePath, keyFilePath, pkcs12FileP
tlsConfig *tls.Config
)
if w.IsProd {
if tlsConfig, err = w.addCertConfig(certFilePath, keyFilePath, pkcs12FilePath); err != nil {
if tlsConfig, err = w.addCertConfig(nil, nil, nil); err != nil {
return nil, nil, err
}
bs, err = w.doProdPost(bm, refund, tlsConfig)
Expand Down Expand Up @@ -182,12 +179,9 @@ func (w *Client) QueryRefund(bm gopay.BodyMap) (wxRsp *QueryRefundResponse, resB
}

// 撤销订单
// 注意:如已使用client.AddCertFilePath()或client.AddCertFileContent()添加过证书,参数certFilePath、keyFilePath、pkcs12FilePath全传 nil,否则,3证书Path均不可空
// 注意:请在初始化client时,调用 client 添加证书的相关方法添加证书
// 文档地址:https://pay.weixin.qq.com/wiki/doc/api/wxpay_v2/open/chapter4_3.shtml
func (w *Client) Reverse(bm gopay.BodyMap, certFilePath, keyFilePath, pkcs12FilePath interface{}) (wxRsp *ReverseResponse, err error) {
if err = checkCertFilePathOrContent(certFilePath, keyFilePath, pkcs12FilePath); err != nil {
return nil, err
}
func (w *Client) Reverse(bm gopay.BodyMap) (wxRsp *ReverseResponse, err error) {
err = bm.CheckEmptyError("nonce_str", "out_trade_no")
if err != nil {
return nil, err
Expand All @@ -197,7 +191,7 @@ func (w *Client) Reverse(bm gopay.BodyMap, certFilePath, keyFilePath, pkcs12File
tlsConfig *tls.Config
)
if w.IsProd {
if tlsConfig, err = w.addCertConfig(certFilePath, keyFilePath, pkcs12FilePath); err != nil {
if tlsConfig, err = w.addCertConfig(nil, nil, nil); err != nil {
return nil, err
}
bs, err = w.doProdPost(bm, reverse, tlsConfig)
Expand Down
4 changes: 2 additions & 2 deletions wechat/base_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func TestClient_Refund(t *testing.T) {
// certFilePath:cert证书路径
// keyFilePath:Key证书路径
// pkcs12FilePath:p12证书路径
wxRsp, resBm, err := client.Refund(bm, nil, nil, nil)
wxRsp, resBm, err := client.Refund(bm)
if err != nil {
xlog.Errorf("client.Refund(%+v),error:%+v", bm, err)
return
Expand Down Expand Up @@ -173,7 +173,7 @@ func TestClient_Reverse(t *testing.T) {
Set("sign_type", SignType_MD5)

// 请求撤销订单,成功后得到结果,沙箱环境下,证书路径参数可传nil
wxRsp, err := client.Reverse(bm, nil, nil, nil)
wxRsp, err := client.Reverse(bm)
if err != nil {
xlog.Errorf("client.Reverse(%+v),error:%+v", bm, err)
return
Expand Down
22 changes: 8 additions & 14 deletions wechat/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,10 @@ func (w *Client) DownloadBill(bm gopay.BodyMap) (wxRsp string, err error) {
}

// 下载资金账单(正式)
// 注意:如已使用client.AddCertFilePath()或client.AddCertFileContent()添加过证书,参数certFilePath、keyFilePath、pkcs12FilePath全传 nil,否则,3证书Path均不可空
// 貌似不支持沙箱环境,因为沙箱环境默认需要用MD5签名,但是此接口仅支持HMAC-SHA256签名
// 注意:请在初始化client时,调用 client 添加证书的相关方法添加证书
// 不支持沙箱环境,因为沙箱环境默认需要用MD5签名,但是此接口仅支持HMAC-SHA256签名
// 文档地址:https://pay.weixin.qq.com/wiki/doc/api/wxpay_v2/open/chapter3_7.shtml
func (w *Client) DownloadFundFlow(bm gopay.BodyMap, certFilePath, keyFilePath, pkcs12FilePath interface{}) (wxRsp string, err error) {
if err = checkCertFilePathOrContent(certFilePath, keyFilePath, pkcs12FilePath); err != nil {
return util.NULL, err
}
func (w *Client) DownloadFundFlow(bm gopay.BodyMap) (wxRsp string, err error) {
err = bm.CheckEmptyError("nonce_str", "bill_date", "account_type")
if err != nil {
return util.NULL, err
Expand All @@ -108,7 +105,7 @@ func (w *Client) DownloadFundFlow(bm gopay.BodyMap, certFilePath, keyFilePath, p
return util.NULL, errors.New("account_type error, please reference: https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_18&index=7")
}
bm.Set("sign_type", SignType_HMAC_SHA256)
tlsConfig, err := w.addCertConfig(certFilePath, keyFilePath, pkcs12FilePath)
tlsConfig, err := w.addCertConfig(nil, nil, nil)
if err != nil {
return util.NULL, err
}
Expand Down Expand Up @@ -149,19 +146,16 @@ func (w *Client) Report(bm gopay.BodyMap) (wxRsp *ReportResponse, err error) {
}

// 拉取订单评价数据(正式)
// 注意:如已使用client.AddCertFilePath()或client.AddCertFileContent()添加过证书,参数certFilePath、keyFilePath、pkcs12FilePath全传 nil,否则,3证书Path均不可空
// 貌似不支持沙箱环境,因为沙箱环境默认需要用MD5签名,但是此接口仅支持HMAC-SHA256签名
// 注意:请在初始化client时,调用 client 添加证书的相关方法添加证书
// 不支持沙箱环境,因为沙箱环境默认需要用MD5签名,但是此接口仅支持HMAC-SHA256签名
// 文档地址:https://pay.weixin.qq.com/wiki/doc/api/wxpay_v2/open/chapter3_11.shtml
func (w *Client) BatchQueryComment(bm gopay.BodyMap, certFilePath, keyFilePath, pkcs12FilePath interface{}) (wxRsp string, err error) {
if err = checkCertFilePathOrContent(certFilePath, keyFilePath, pkcs12FilePath); err != nil {
return util.NULL, err
}
func (w *Client) BatchQueryComment(bm gopay.BodyMap) (wxRsp string, err error) {
err = bm.CheckEmptyError("nonce_str", "begin_time", "end_time", "offset")
if err != nil {
return util.NULL, err
}
bm.Set("sign_type", SignType_HMAC_SHA256)
tlsConfig, err := w.addCertConfig(certFilePath, keyFilePath, pkcs12FilePath)
tlsConfig, err := w.addCertConfig(nil, nil, nil)
if err != nil {
return util.NULL, err
}
Expand Down
17 changes: 10 additions & 7 deletions wechat/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,17 @@ func TestMain(m *testing.M) {
// 设置国家,不设置默认就是 China
client.SetCountry(China)

// 添加证书n内容
//err := client.AddCertFileContent(nil, nil, nil)
// 不使用证书接口,可以不添加证书
// 添加pkcs12内容
//err = client.AddCertPkcs12FilePath("apiclient_cert.p12")
//if err != nil {
// panic(err)
//}

// 添加证书路径
//err := client.AddCertFilePath(nil, nil, nil)
// 或

// 添加pem证书路径
//err := client.AddCertPemFilePath("apiclient_cert.pem", "apiclient_key.pem")
//if err != nil {
// panic(err)
//}
Expand Down Expand Up @@ -71,7 +74,7 @@ func TestClient_GetTransferInfo(t *testing.T) {
// certFilePath:cert证书路径
// keyFilePath:Key证书路径
// pkcs12FilePath:p12证书路径
wxRsp, err := client.GetTransferInfo(bm, nil, nil, nil)
wxRsp, err := client.GetTransferInfo(bm)
if err != nil {
xlog.Errorf("client.GetTransferInfo(%+v),error:%+v", bm, err)
return
Expand Down Expand Up @@ -105,7 +108,7 @@ func TestClient_DownloadFundFlow(t *testing.T) {
Set("account_type", "Basic")

// 请求下载资金账单,成功后得到结果,沙箱环境下,证书路径参数可传nil
wxRsp, err := client.DownloadFundFlow(bm, nil, nil, nil)
wxRsp, err := client.DownloadFundFlow(bm)
if err != nil {
xlog.Errorf("client.DownloadFundFlow(%+v),error:%+v", bm, err)
return
Expand All @@ -123,7 +126,7 @@ func TestClient_BatchQueryComment(t *testing.T) {
Set("offset", "0")

// 请求拉取订单评价数据,成功后得到结果,沙箱环境下,证书路径参数可传nil
wxRsp, err := client.BatchQueryComment(bm, nil, nil, nil)
wxRsp, err := client.BatchQueryComment(bm)
if err != nil {
xlog.Errorf("client.BatchQueryComment(%+v),error:%+v", bm, err)
return
Expand Down
Loading

0 comments on commit 18c6960

Please sign in to comment.