Skip to content

Commit

Permalink
v1.5.71 (#226)
Browse files Browse the repository at this point in the history
* 新增微信 银行组件(服务商)相关接口
* v1.5.71
  • Loading branch information
iGoogle-ink authored Feb 9, 2022
1 parent bf69ae1 commit 75bd082
Show file tree
Hide file tree
Showing 12 changed files with 323 additions and 9 deletions.
2 changes: 1 addition & 1 deletion alipay/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ func (a *Client) doAliPay(ctx context.Context, bm gopay.BodyMap, method string,
if aat != util.NULL {
pubBody.Set("app_auth_token", aat)
}
if method == "alipay.user.info.share" {
if len(authToken) > 0 {
pubBody.Set("auth_token", authToken[0])
}
if bodyStr != util.NULL {
Expand Down
4 changes: 2 additions & 2 deletions alipay/member_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,9 +394,9 @@ func (a *Client) UserCertdocCertverifyPreconsult(ctx context.Context, bm gopay.B

// alipay.user.certdoc.certverify.consult(实名证件信息比对验证咨询)
// 文档地址:https://opendocs.alipay.com/apis/api_2/alipay.user.certdoc.certverify.consult
func (a *Client) UserCertdocCertverifyConsult(ctx context.Context, bm gopay.BodyMap) (aliRsp *UserCertdocCertverifyConsultRsp, err error) {
func (a *Client) UserCertdocCertverifyConsult(ctx context.Context, bm gopay.BodyMap, authToken string) (aliRsp *UserCertdocCertverifyConsultRsp, err error) {
var bs []byte
if bs, err = a.doAliPay(ctx, bm, "alipay.user.certdoc.certverify.consult"); err != nil {
if bs, err = a.doAliPay(ctx, bm, "alipay.user.certdoc.certverify.consult", authToken); err != nil {
return nil, err
}
aliRsp = new(UserCertdocCertverifyConsultRsp)
Expand Down
2 changes: 1 addition & 1 deletion alipay/member_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ func TestUserCertdocCertverifyConsult(t *testing.T) {
bm := make(gopay.BodyMap)
bm.Set("verify_id", "671ffcda5447bc87e9ed2f669eb143d4")
// 发起请求
aliRsp, err := client.UserCertdocCertverifyConsult(ctx, bm)
aliRsp, err := client.UserCertdocCertverifyConsult(ctx, bm, "auth_token")
if err != nil {
xlog.Error(err)
return
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.70"
Version = "1.5.71"
)

type DebugSwitch int8
7 changes: 7 additions & 0 deletions doc/wechat_v3.md
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,13 @@ wechat.V3DecryptScoreNotifyCipherText()
* 查询退款ByNo:`client.V3EcommerceRefundQueryByNo()`
* 垫付退款回补:`client.V3EcommerceRefundAdvance()`
* 查询垫付回补结果:`client.V3EcommerceRefundAdvanceResult()`
* <font color='#07C160' size='4'>银行组件(服务商)</font>
* 获取对私银行卡号开户银行:`client.V3BankSearchBank()`
* 查询支持个人业务的银行列表:`client.V3BankSearchPersonalList()`
* 查询支持对公业务的银行列表:`client.V3BankSearchCorporateList()`
* 查询省份列表:`client.V3BankSearchProvinceList()`
* 查询城市列表:`client.V3BankSearchCityList()`
* 查询支行列表:`client.V3BankSearchBranchList()`


### 微信v3公共 API
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ module github.com/go-pay/gopay

go 1.16

require golang.org/x/crypto v0.0.0-20211202192323-5770296d904e
require golang.org/x/crypto v0.0.0-20220208233918-bba287dce954
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
golang.org/x/crypto v0.0.0-20211202192323-5770296d904e h1:MUP6MR3rJ7Gk9LEia0LP2ytiH6MuCfs7qYz+47jGdD8=
golang.org/x/crypto v0.0.0-20211202192323-5770296d904e/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.0.0-20220208233918-bba287dce954 h1:BkypuErRT9A9I/iljuaG3/zdMjd/J6m8tKKJQtGfSdA=
golang.org/x/crypto v0.0.0-20220208233918-bba287dce954/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand Down
4 changes: 3 additions & 1 deletion release_note.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
版本号:Release 1.5.70
版本号:Release 1.5.71
修改记录:
(1) 微信V2:去除所有微信小程序、公众号相关接口,请使用 wechat-sdk
(2) 支付宝:client.UserCertdocCertverifyConsult() 方法,增加 authToken 参数
(2) 微信V3:新增 银行组件(服务商) 相关接口,详情查看v3文档最下方的接口列表

版本号:Release 1.5.69
修改记录:
Expand Down
175 changes: 175 additions & 0 deletions wechat/v3/bank.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
package wechat

import (
"context"
"encoding/json"
"fmt"
"net/http"

"github.com/go-pay/gopay/pkg/util"
)

// 获取对私银行卡号开户银行
// 注意:accountNo 需此方法加密:client.V3EncryptText()
// Code = 0 is success
// 服务商文档:https://pay.weixin.qq.com/wiki/doc/apiv3_partner/Offline/apis/chapter11_2_1.shtml
func (c *ClientV3) V3BankSearchBank(ctx context.Context, accountNo string) (wxRsp *BankSearchBankRsp, err error) {
uri := v3BankSearchBank + "?account_number=" + accountNo
authorization, err := c.authorization(MethodGet, uri, nil)
if err != nil {
return nil, err
}
res, si, bs, err := c.doProdGet(ctx, uri, authorization)
if err != nil {
return nil, err
}
wxRsp = &BankSearchBankRsp{Code: Success, SignInfo: si}
wxRsp.Response = new(BankSearchBank)
if err = json.Unmarshal(bs, wxRsp.Response); err != nil {
return nil, fmt.Errorf("json.Unmarshal(%s):%w", string(bs), err)
}
if res.StatusCode != http.StatusOK {
wxRsp.Code = res.StatusCode
wxRsp.Error = string(bs)
return wxRsp, nil
}
return wxRsp, c.verifySyncSign(si)
}

// 查询支持个人业务的银行列表
// Code = 0 is success
// 服务商文档:https://pay.weixin.qq.com/wiki/doc/apiv3_partner/Offline/apis/chapter11_2_2.shtml
func (c *ClientV3) V3BankSearchPersonalList(ctx context.Context, limit, offset int) (wxRsp *BankSearchPersonalListRsp, err error) {
if limit == 0 {
limit = 20
}
uri := v3BankSearchPersonalList + "&limit=" + util.Int2String(limit) + "&offset=" + util.Int2String(offset)
authorization, err := c.authorization(MethodGet, uri, nil)
if err != nil {
return nil, err
}
res, si, bs, err := c.doProdGet(ctx, uri, authorization)
if err != nil {
return nil, err
}
wxRsp = &BankSearchPersonalListRsp{Code: Success, SignInfo: si}
wxRsp.Response = new(BankSearchList)
if err = json.Unmarshal(bs, wxRsp.Response); err != nil {
return nil, fmt.Errorf("json.Unmarshal(%s):%w", string(bs), err)
}
if res.StatusCode != http.StatusOK {
wxRsp.Code = res.StatusCode
wxRsp.Error = string(bs)
return wxRsp, nil
}
return wxRsp, c.verifySyncSign(si)
}

// 查询支持对公业务的银行列表
// Code = 0 is success
// 服务商文档:https://pay.weixin.qq.com/wiki/doc/apiv3_partner/Offline/apis/chapter11_2_3.shtml
func (c *ClientV3) V3BankSearchCorporateList(ctx context.Context, limit, offset int) (wxRsp *BankSearchCorporateListRsp, err error) {
if limit == 0 {
limit = 20
}
uri := v3BankSearchCorporateList + "&limit=" + util.Int2String(limit) + "&offset=" + util.Int2String(offset)
authorization, err := c.authorization(MethodGet, uri, nil)
if err != nil {
return nil, err
}
res, si, bs, err := c.doProdGet(ctx, uri, authorization)
if err != nil {
return nil, err
}
wxRsp = &BankSearchCorporateListRsp{Code: Success, SignInfo: si}
wxRsp.Response = new(BankSearchList)
if err = json.Unmarshal(bs, wxRsp.Response); err != nil {
return nil, fmt.Errorf("json.Unmarshal(%s):%w", string(bs), err)
}
if res.StatusCode != http.StatusOK {
wxRsp.Code = res.StatusCode
wxRsp.Error = string(bs)
return wxRsp, nil
}
return wxRsp, c.verifySyncSign(si)
}

// 查询省份列表
// Code = 0 is success
// 服务商文档:https://pay.weixin.qq.com/wiki/doc/apiv3_partner/Offline/apis/chapter11_2_4.shtml
func (c *ClientV3) V3BankSearchProvinceList(ctx context.Context) (wxRsp *BankSearchProvinceListRsp, err error) {
authorization, err := c.authorization(MethodGet, v3BankSearchProvinceList, nil)
if err != nil {
return nil, err
}
res, si, bs, err := c.doProdGet(ctx, v3BankSearchProvinceList, authorization)
if err != nil {
return nil, err
}
wxRsp = &BankSearchProvinceListRsp{Code: Success, SignInfo: si}
wxRsp.Response = new(BankSearchProvince)
if err = json.Unmarshal(bs, wxRsp.Response); err != nil {
return nil, fmt.Errorf("json.Unmarshal(%s):%w", string(bs), err)
}
if res.StatusCode != http.StatusOK {
wxRsp.Code = res.StatusCode
wxRsp.Error = string(bs)
return wxRsp, nil
}
return wxRsp, c.verifySyncSign(si)
}

// 查询城市列表
// Code = 0 is success
// 服务商文档:https://pay.weixin.qq.com/wiki/doc/apiv3_partner/Offline/apis/chapter11_2_5.shtml
func (c *ClientV3) V3BankSearchCityList(ctx context.Context, provinceCode int) (wxRsp *BankSearchCityListRsp, err error) {
url := fmt.Sprintf(v3BankSearchCityList, provinceCode)
authorization, err := c.authorization(MethodGet, url, nil)
if err != nil {
return nil, err
}
res, si, bs, err := c.doProdGet(ctx, url, authorization)
if err != nil {
return nil, err
}
wxRsp = &BankSearchCityListRsp{Code: Success, SignInfo: si}
wxRsp.Response = new(BankSearchCity)
if err = json.Unmarshal(bs, wxRsp.Response); err != nil {
return nil, fmt.Errorf("json.Unmarshal(%s):%w", string(bs), err)
}
if res.StatusCode != http.StatusOK {
wxRsp.Code = res.StatusCode
wxRsp.Error = string(bs)
return wxRsp, nil
}
return wxRsp, c.verifySyncSign(si)
}

// 查询支行列表
// Code = 0 is success
// 服务商文档:https://pay.weixin.qq.com/wiki/doc/apiv3_partner/Offline/apis/chapter11_2_6.shtml
func (c *ClientV3) V3BankSearchBranchList(ctx context.Context, bankAliasCode string, cityCode, limit, offset int) (wxRsp *BankSearchBranchListRsp, err error) {
if limit == 0 {
limit = 20
}
uri := fmt.Sprintf(v3BankSearchBranchList, bankAliasCode) + "?city_code=" + util.Int2String(cityCode) + "&limit=" + util.Int2String(limit) + "&offset=" + util.Int2String(offset)
authorization, err := c.authorization(MethodGet, uri, nil)
if err != nil {
return nil, err
}
res, si, bs, err := c.doProdGet(ctx, uri, authorization)
if err != nil {
return nil, err
}
wxRsp = &BankSearchBranchListRsp{Code: Success, SignInfo: si}
wxRsp.Response = new(BankSearchBranch)
if err = json.Unmarshal(bs, wxRsp.Response); err != nil {
return nil, fmt.Errorf("json.Unmarshal(%s):%w", string(bs), err)
}
if res.StatusCode != http.StatusOK {
wxRsp.Code = res.StatusCode
wxRsp.Error = string(bs)
return wxRsp, nil
}
return wxRsp, c.verifySyncSign(si)
}
16 changes: 16 additions & 0 deletions wechat/v3/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -527,4 +527,20 @@ func TestV3Withdraw(t *testing.T) {
return
}
xlog.Debugf("wxRsp: %#v", wxRsp)
xlog.Debugf("wxRsp.Response: %#v", wxRsp.Response)
}

func TestV3BankSearchBank(t *testing.T) {
encryptText, err := client.V3EncryptText("6213123456781234")
if err != nil {
xlog.Error(err)
return
}
wxRsp, err := client.V3BankSearchBank(ctx, encryptText)
if err != nil {
xlog.Error(err)
return
}
xlog.Debugf("wxRsp: %#v", wxRsp)
xlog.Debugf("wxRsp.Response: %#v", wxRsp.Response)
}
8 changes: 8 additions & 0 deletions wechat/v3/constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,14 @@ const (
v3CommerceRefundAdvance = "/v3/ecommerce/refunds/%s/return-advance" // refund_id 垫付退款回补 POST
v3CommerceRefundAdvanceResult = "/v3/ecommerce/refunds/%s/return-advance" // refund_id 查询垫付回补结果 GET

// 银行组件(服务商)
v3BankSearchBank = "/v3/capital/capitallhh/banks/search-banks-by-bank-account" // 获取对私银行卡号开户银行 GET
v3BankSearchPersonalList = "/v3/capital/capitallhh/banks/personal-banking" // 查询支持个人业务的银行列表 GET
v3BankSearchCorporateList = "/v3/capital/capitallhh/banks/corporate-banking" // 查询支持对公业务的银行列表 GET
v3BankSearchProvinceList = "/v3/capital/capitallhh/areas/provinces" // 查询省份列表 GET
v3BankSearchCityList = "/v3/capital/capitallhh/areas/provinces/%d/cities" // province_code 查询城市列表 GET
v3BankSearchBranchList = "/v3/capital/capitallhh/banks/%s/branches" // bank_alias_code 查询支行列表 GET

// 特约商户进件申请单状态
ApplyStateEditing = "APPLYMENT_STATE_EDITTING" // 编辑中
ApplyStateAuditing = "APPLYMENT_STATE_AUDITING" // 审核中
Expand Down
Loading

0 comments on commit 75bd082

Please sign in to comment.