Skip to content

Commit 4bb93de

Browse files
vainbackdev-gale
andauthored
【新版商家转账】更新 (#453)
* 微信支付 商家转账 新版本更新 * 微信支付 商家转账 新版本更新 * 微信支付 商家转账 回调通知 新版本更新 --------- Co-authored-by: Vainback <[email protected]>
1 parent 79cbfe0 commit 4bb93de

File tree

6 files changed

+386
-3
lines changed

6 files changed

+386
-3
lines changed

Diff for: README.md

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ func main() {
4949
* #### [支付宝支付](https://github.com/go-pay/gopay/blob/main/doc/alipay.md)
5050
* #### [微信支付(V3版)](https://github.com/go-pay/gopay/blob/main/doc/wechat_v3.md)
5151
* 微信商家转账产品升级,目前了解下来老接口暂不受影响,后续gopay会尽快增加新版的商家转账接口,各位用到的关注一下:https://developers.weixin.qq.com/community/pay/doc/000a060bb4c13095b6b27cc1b6ac01
52+
* 【fork】`已更新`
5253
* #### [微信支付(V2版,不推荐)](https://github.com/go-pay/gopay/blob/main/doc/wechat_v2.md)
5354
* #### [QQ支付](https://github.com/go-pay/gopay/blob/main/doc/qq.md)
5455
* #### [通联支付](https://github.com/go-pay/gopay/blob/main/doc/allinpay.md)

Diff for: wechat/v3/constant.go

+10
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,16 @@ const (
248248
v3PartnerTransferMerchantQuery = "/v3/partner-transfer/batches/out-batch-no/%s" // out_batch_no 商家批次单号查询批次单 GET
249249
v3PartnerTransferMerchantDetail = "/v3/partner-transfer/batches/out-batch-no/%s/details/out-detail-no/%s" // out_batch_no、out_detail_no 商家明细单号查询明细单 GET
250250

251+
// 转账 - 新版本
252+
V3TransferBills = "/v3/fund-app/mch-transfer/transfer-bills" // 发起商家转账 POST
253+
V3TransferBillsCancel = "/v3/fund-app/mch-transfer/transfer-bills/out-bill-no/%s/cancel" // 撤销转账 POST
254+
V3TransferBillsMerchantQuery = "/v3/fund-app/mch-transfer/transfer-bills/out-bill-no/%s" // 商户单号查询转账单 GET
255+
V3TransferBillsQuery = "/v3/fund-app/mch-transfer/transfer-bills/transfer-bill-no/%s" // 微信单号查询转账单 GET
256+
V3TransferElecsignMerchant = "/v3/fund-app/mch-transfer/elecsign/out-bill-no" // 商户单号申请电子回单 POST
257+
V3TransferElecsignMerchantQuery = "/v3/fund-app/mch-transfer/elecsign/out-bill-no/%s" // 商户单号查询电子回单 GET
258+
V3TransferElecsign = "/v3/fund-app/mch-transfer/elecsign/transfer-bill-no" // 微信单号申请电子回单 POST
259+
V3TransferElecsignQuery = "/v3/fund-app/mch-transfer/elecsign/transfer-bill-no/%s" // 微信单号查询电子回单 GET
260+
251261
// 平台收付通(余额查询)
252262
v3MerchantBalance = "/v3/merchant/fund/balance/%s" // account_type 查询账户实时余额 GET
253263
v3MerchantDayBalance = "/v3/merchant/fund/dayendbalance/%s" // account_type 查询账户日终余额 GET

Diff for: wechat/v3/encrypt_decrypt.go

+14
Original file line numberDiff line numberDiff line change
@@ -321,3 +321,17 @@ func V3DecryptTransferBatchNotifyCipherText(ciphertext, nonce, additional, apiV3
321321
}
322322
return result, nil
323323
}
324+
325+
// 解密 商家转账批次回调通知 回调中的加密信息
326+
func V3DecryptTransferBillsNotifyCipherText(ciphertext, nonce, additional, apiV3Key string) (result *V3DecryptTransferBillsResult, err error) {
327+
cipherBytes, _ := base64.StdEncoding.DecodeString(ciphertext)
328+
decrypt, err := aes.GCMDecrypt(cipherBytes, []byte(nonce), []byte(additional), []byte(apiV3Key))
329+
if err != nil {
330+
return nil, fmt.Errorf("aes.GCMDecrypt, err:%w", err)
331+
}
332+
result = &V3DecryptTransferBillsResult{}
333+
if err = json.Unmarshal(decrypt, result); err != nil {
334+
return nil, fmt.Errorf("json.Unmarshal(%s), err:%w", string(decrypt), err)
335+
}
336+
return result, nil
337+
}

Diff for: wechat/v3/model_transfer_bills.go

+143
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
package wechat
2+
3+
// 发起转账 Rsp
4+
type TransferBillsRsp struct {
5+
Code int `json:"-"`
6+
SignInfo *SignInfo `json:"-"`
7+
Response *TransferBills `json:"response,omitempty"`
8+
Error string `json:"-"`
9+
}
10+
11+
// 发起撤销转账 Rsp
12+
type TransferBillsCancelRsp struct {
13+
Code int `json:"-"`
14+
SignInfo *SignInfo `json:"-"`
15+
Response *TransferBillsCancel `json:"response,omitempty"`
16+
Error string `json:"-"`
17+
}
18+
19+
// 商户单号查询转账单 Rsp
20+
type TransferBillsQueryRsp struct {
21+
Code int `json:"-"`
22+
SignInfo *SignInfo `json:"-"`
23+
Response *TransferBillsQuery `json:"response,omitempty"`
24+
Error string `json:"-"`
25+
}
26+
27+
// 微信单号查询转账单 Rsp
28+
type TransferBillsMerchantQueryRsp struct {
29+
Code int `json:"-"`
30+
SignInfo *SignInfo `json:"-"`
31+
Response *TransferBillsMerchantQuery `json:"response,omitempty"`
32+
Error string `json:"-"`
33+
}
34+
35+
// 商户单号申请电子回单 Rsp
36+
type TransferElecsignMerchantRsp struct {
37+
Code int `json:"-"`
38+
SignInfo *SignInfo `json:"-"`
39+
Response *TransferElecsignMerchant `json:"response,omitempty"`
40+
Error string `json:"-"`
41+
}
42+
43+
// 商户单号查询电子回单 Rsp
44+
type TransferElecsignMerchantQueryRsp struct {
45+
Code int `json:"-"`
46+
SignInfo *SignInfo `json:"-"`
47+
Response *TransferElecsignMerchantQuery `json:"response,omitempty"`
48+
Error string `json:"-"`
49+
}
50+
51+
// 微信单号申请电子回单 Rsp
52+
type TransferElecsignRsp struct {
53+
Code int `json:"-"`
54+
SignInfo *SignInfo `json:"-"`
55+
Response *TransferElecsign `json:"response,omitempty"`
56+
Error string `json:"-"`
57+
}
58+
59+
// 微信单号申请电子回单 Rsp
60+
type TransferElecsignQueryRsp struct {
61+
Code int `json:"-"`
62+
SignInfo *SignInfo `json:"-"`
63+
Response *TransferElecsignQuery `json:"response,omitempty"`
64+
Error string `json:"-"`
65+
}
66+
67+
// =========================================================分割=========================================================
68+
69+
type TransferBills struct {
70+
OutBillNo string `json:"out_bill_no"`
71+
TransferBillNo string `json:"transfer_bill_no"`
72+
CreateTime string `json:"create_time"`
73+
State string `json:"state"`
74+
FailReason string `json:"fail_reason"`
75+
PackageInfo string `json:"package_info"`
76+
}
77+
78+
type TransferBillsCancel struct {
79+
OutBillNo string `json:"out_bill_no"`
80+
TransferBillNo string `json:"transfer_bill_no"`
81+
State string `json:"state"`
82+
UpdateTime string `json:"update_time"`
83+
}
84+
85+
type TransferBillsMerchantQuery struct {
86+
MchID string `json:"mch_id"`
87+
OutBillNo string `json:"out_bill_no"`
88+
TransferBillNo string `json:"transfer_bill_no"`
89+
Appid string `json:"appid"`
90+
State string `json:"state"`
91+
TransferAmount int `json:"transfer_amount"`
92+
TransferRemark string `json:"transfer_remark"`
93+
FailReason string `json:"fail_reason"`
94+
Openid string `json:"openid"`
95+
UserName string `json:"user_name"`
96+
CreateTime string `json:"create_time"`
97+
UpdateTime string `json:"update_time"`
98+
}
99+
100+
type TransferBillsQuery struct {
101+
MchID string `json:"mch_id"`
102+
OutBillNo string `json:"out_bill_no"`
103+
TransferBillNo string `json:"transfer_bill_no"`
104+
Appid string `json:"appid"`
105+
State string `json:"state"`
106+
TransferAmount int `json:"transfer_amount"`
107+
TransferRemark string `json:"transfer_remark"`
108+
FailReason string `json:"fail_reason"`
109+
Openid string `json:"openid"`
110+
UserName string `json:"user_name"`
111+
CreateTime string `json:"create_time"`
112+
UpdateTime string `json:"update_time"`
113+
}
114+
115+
type TransferElecsignMerchant struct {
116+
State string `json:"state"`
117+
CreateTime string `json:"create_time"`
118+
}
119+
120+
type TransferElecsignMerchantQuery struct {
121+
State string `json:"state"`
122+
CreateTime string `json:"create_time"`
123+
UpdateTime string `json:"update_time"`
124+
HashType string `json:"hash_type"`
125+
HashValue string `json:"hash_value"`
126+
DownloadURL string `json:"download_url"`
127+
FailReason string `json:"fail_reason"`
128+
}
129+
130+
type TransferElecsign struct {
131+
State string `json:"state"`
132+
CreateTime string `json:"create_time"`
133+
}
134+
135+
type TransferElecsignQuery struct {
136+
State string `json:"state"`
137+
CreateTime string `json:"create_time"`
138+
UpdateTime string `json:"update_time"`
139+
HashType string `json:"hash_type"`
140+
HashValue string `json:"hash_value"`
141+
DownloadURL string `json:"download_url"`
142+
FailReason string `json:"fail_reason"`
143+
}

Diff for: wechat/v3/notify.go

+18-3
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@ import (
44
"crypto/rsa"
55
"errors"
66
"fmt"
7-
"io"
8-
"net/http"
9-
107
"github.com/go-pay/gopay"
118
"github.com/go-pay/util/js"
129
"github.com/go-pay/xlog"
10+
"io"
11+
"net/http"
1312
)
1413

1514
type Resource struct {
@@ -290,6 +289,22 @@ type V3DecryptTransferBatchResult struct {
290289
CloseReason string `json:"close_reason,omitempty"`
291290
}
292291

292+
// 商家转账新版本回调通知 解密结果
293+
type V3DecryptTransferBillsResult struct {
294+
ID string `json:"id"`
295+
CreateTime string `json:"create_time"`
296+
EventType string `json:"event_type"`
297+
ResourceType string `json:"resource_type"`
298+
Resource struct {
299+
Algorithm string `json:"algorithm"`
300+
Ciphertext string `json:"ciphertext"`
301+
AssociatedData string `json:"associated_data"`
302+
OriginalType string `json:"original_type"`
303+
Nonce string `json:"nonce"`
304+
} `json:"resource"`
305+
Summary string `json:"summary"`
306+
}
307+
293308
// =====================================================================================================================
294309

295310
type V3NotifyReq struct {

0 commit comments

Comments
 (0)