|
| 1 | +package wechat |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "encoding/json" |
| 6 | + "fmt" |
| 7 | + "net/http" |
| 8 | + |
| 9 | + "github.com/go-pay/gopay/pkg/util" |
| 10 | +) |
| 11 | + |
| 12 | +// 获取对私银行卡号开户银行 |
| 13 | +// 注意:accountNo 需此方法加密:client.V3EncryptText() |
| 14 | +// Code = 0 is success |
| 15 | +// 服务商文档:https://pay.weixin.qq.com/wiki/doc/apiv3_partner/Offline/apis/chapter11_2_1.shtml |
| 16 | +func (c *ClientV3) V3BankSearchBank(ctx context.Context, accountNo string) (wxRsp *BankSearchBankRsp, err error) { |
| 17 | + uri := v3BankSearchBank + "?account_number=" + accountNo |
| 18 | + authorization, err := c.authorization(MethodGet, uri, nil) |
| 19 | + if err != nil { |
| 20 | + return nil, err |
| 21 | + } |
| 22 | + res, si, bs, err := c.doProdGet(ctx, uri, authorization) |
| 23 | + if err != nil { |
| 24 | + return nil, err |
| 25 | + } |
| 26 | + wxRsp = &BankSearchBankRsp{Code: Success, SignInfo: si} |
| 27 | + wxRsp.Response = new(BankSearchBank) |
| 28 | + if err = json.Unmarshal(bs, wxRsp.Response); err != nil { |
| 29 | + return nil, fmt.Errorf("json.Unmarshal(%s):%w", string(bs), err) |
| 30 | + } |
| 31 | + if res.StatusCode != http.StatusOK { |
| 32 | + wxRsp.Code = res.StatusCode |
| 33 | + wxRsp.Error = string(bs) |
| 34 | + return wxRsp, nil |
| 35 | + } |
| 36 | + return wxRsp, c.verifySyncSign(si) |
| 37 | +} |
| 38 | + |
| 39 | +// 查询支持个人业务的银行列表 |
| 40 | +// Code = 0 is success |
| 41 | +// 服务商文档:https://pay.weixin.qq.com/wiki/doc/apiv3_partner/Offline/apis/chapter11_2_2.shtml |
| 42 | +func (c *ClientV3) V3BankSearchPersonalList(ctx context.Context, limit, offset int) (wxRsp *BankSearchPersonalListRsp, err error) { |
| 43 | + if limit == 0 { |
| 44 | + limit = 20 |
| 45 | + } |
| 46 | + uri := v3BankSearchPersonalList + "&limit=" + util.Int2String(limit) + "&offset=" + util.Int2String(offset) |
| 47 | + authorization, err := c.authorization(MethodGet, uri, nil) |
| 48 | + if err != nil { |
| 49 | + return nil, err |
| 50 | + } |
| 51 | + res, si, bs, err := c.doProdGet(ctx, uri, authorization) |
| 52 | + if err != nil { |
| 53 | + return nil, err |
| 54 | + } |
| 55 | + wxRsp = &BankSearchPersonalListRsp{Code: Success, SignInfo: si} |
| 56 | + wxRsp.Response = new(BankSearchList) |
| 57 | + if err = json.Unmarshal(bs, wxRsp.Response); err != nil { |
| 58 | + return nil, fmt.Errorf("json.Unmarshal(%s):%w", string(bs), err) |
| 59 | + } |
| 60 | + if res.StatusCode != http.StatusOK { |
| 61 | + wxRsp.Code = res.StatusCode |
| 62 | + wxRsp.Error = string(bs) |
| 63 | + return wxRsp, nil |
| 64 | + } |
| 65 | + return wxRsp, c.verifySyncSign(si) |
| 66 | +} |
| 67 | + |
| 68 | +// 查询支持对公业务的银行列表 |
| 69 | +// Code = 0 is success |
| 70 | +// 服务商文档:https://pay.weixin.qq.com/wiki/doc/apiv3_partner/Offline/apis/chapter11_2_3.shtml |
| 71 | +func (c *ClientV3) V3BankSearchCorporateList(ctx context.Context, limit, offset int) (wxRsp *BankSearchCorporateListRsp, err error) { |
| 72 | + if limit == 0 { |
| 73 | + limit = 20 |
| 74 | + } |
| 75 | + uri := v3BankSearchCorporateList + "&limit=" + util.Int2String(limit) + "&offset=" + util.Int2String(offset) |
| 76 | + authorization, err := c.authorization(MethodGet, uri, nil) |
| 77 | + if err != nil { |
| 78 | + return nil, err |
| 79 | + } |
| 80 | + res, si, bs, err := c.doProdGet(ctx, uri, authorization) |
| 81 | + if err != nil { |
| 82 | + return nil, err |
| 83 | + } |
| 84 | + wxRsp = &BankSearchCorporateListRsp{Code: Success, SignInfo: si} |
| 85 | + wxRsp.Response = new(BankSearchList) |
| 86 | + if err = json.Unmarshal(bs, wxRsp.Response); err != nil { |
| 87 | + return nil, fmt.Errorf("json.Unmarshal(%s):%w", string(bs), err) |
| 88 | + } |
| 89 | + if res.StatusCode != http.StatusOK { |
| 90 | + wxRsp.Code = res.StatusCode |
| 91 | + wxRsp.Error = string(bs) |
| 92 | + return wxRsp, nil |
| 93 | + } |
| 94 | + return wxRsp, c.verifySyncSign(si) |
| 95 | +} |
| 96 | + |
| 97 | +// 查询省份列表 |
| 98 | +// Code = 0 is success |
| 99 | +// 服务商文档:https://pay.weixin.qq.com/wiki/doc/apiv3_partner/Offline/apis/chapter11_2_4.shtml |
| 100 | +func (c *ClientV3) V3BankSearchProvinceList(ctx context.Context) (wxRsp *BankSearchProvinceListRsp, err error) { |
| 101 | + authorization, err := c.authorization(MethodGet, v3BankSearchProvinceList, nil) |
| 102 | + if err != nil { |
| 103 | + return nil, err |
| 104 | + } |
| 105 | + res, si, bs, err := c.doProdGet(ctx, v3BankSearchProvinceList, authorization) |
| 106 | + if err != nil { |
| 107 | + return nil, err |
| 108 | + } |
| 109 | + wxRsp = &BankSearchProvinceListRsp{Code: Success, SignInfo: si} |
| 110 | + wxRsp.Response = new(BankSearchProvince) |
| 111 | + if err = json.Unmarshal(bs, wxRsp.Response); err != nil { |
| 112 | + return nil, fmt.Errorf("json.Unmarshal(%s):%w", string(bs), err) |
| 113 | + } |
| 114 | + if res.StatusCode != http.StatusOK { |
| 115 | + wxRsp.Code = res.StatusCode |
| 116 | + wxRsp.Error = string(bs) |
| 117 | + return wxRsp, nil |
| 118 | + } |
| 119 | + return wxRsp, c.verifySyncSign(si) |
| 120 | +} |
| 121 | + |
| 122 | +// 查询城市列表 |
| 123 | +// Code = 0 is success |
| 124 | +// 服务商文档:https://pay.weixin.qq.com/wiki/doc/apiv3_partner/Offline/apis/chapter11_2_5.shtml |
| 125 | +func (c *ClientV3) V3BankSearchCityList(ctx context.Context, provinceCode int) (wxRsp *BankSearchCityListRsp, err error) { |
| 126 | + url := fmt.Sprintf(v3BankSearchCityList, provinceCode) |
| 127 | + authorization, err := c.authorization(MethodGet, url, nil) |
| 128 | + if err != nil { |
| 129 | + return nil, err |
| 130 | + } |
| 131 | + res, si, bs, err := c.doProdGet(ctx, url, authorization) |
| 132 | + if err != nil { |
| 133 | + return nil, err |
| 134 | + } |
| 135 | + wxRsp = &BankSearchCityListRsp{Code: Success, SignInfo: si} |
| 136 | + wxRsp.Response = new(BankSearchCity) |
| 137 | + if err = json.Unmarshal(bs, wxRsp.Response); err != nil { |
| 138 | + return nil, fmt.Errorf("json.Unmarshal(%s):%w", string(bs), err) |
| 139 | + } |
| 140 | + if res.StatusCode != http.StatusOK { |
| 141 | + wxRsp.Code = res.StatusCode |
| 142 | + wxRsp.Error = string(bs) |
| 143 | + return wxRsp, nil |
| 144 | + } |
| 145 | + return wxRsp, c.verifySyncSign(si) |
| 146 | +} |
| 147 | + |
| 148 | +// 查询支行列表 |
| 149 | +// Code = 0 is success |
| 150 | +// 服务商文档:https://pay.weixin.qq.com/wiki/doc/apiv3_partner/Offline/apis/chapter11_2_6.shtml |
| 151 | +func (c *ClientV3) V3BankSearchBranchList(ctx context.Context, bankAliasCode string, cityCode, limit, offset int) (wxRsp *BankSearchBranchListRsp, err error) { |
| 152 | + if limit == 0 { |
| 153 | + limit = 20 |
| 154 | + } |
| 155 | + uri := fmt.Sprintf(v3BankSearchBranchList, bankAliasCode) + "?city_code=" + util.Int2String(cityCode) + "&limit=" + util.Int2String(limit) + "&offset=" + util.Int2String(offset) |
| 156 | + authorization, err := c.authorization(MethodGet, uri, nil) |
| 157 | + if err != nil { |
| 158 | + return nil, err |
| 159 | + } |
| 160 | + res, si, bs, err := c.doProdGet(ctx, uri, authorization) |
| 161 | + if err != nil { |
| 162 | + return nil, err |
| 163 | + } |
| 164 | + wxRsp = &BankSearchBranchListRsp{Code: Success, SignInfo: si} |
| 165 | + wxRsp.Response = new(BankSearchBranch) |
| 166 | + if err = json.Unmarshal(bs, wxRsp.Response); err != nil { |
| 167 | + return nil, fmt.Errorf("json.Unmarshal(%s):%w", string(bs), err) |
| 168 | + } |
| 169 | + if res.StatusCode != http.StatusOK { |
| 170 | + wxRsp.Code = res.StatusCode |
| 171 | + wxRsp.Error = string(bs) |
| 172 | + return wxRsp, nil |
| 173 | + } |
| 174 | + return wxRsp, c.verifySyncSign(si) |
| 175 | +} |
0 commit comments