Skip to content

Commit 0e1d9fe

Browse files
authored
Merge pull request #637 from ArtisanCloud/develop
Develop
2 parents 0fbfc49 + ca1f9a0 commit 0e1d9fe

File tree

5 files changed

+105
-22
lines changed

5 files changed

+105
-22
lines changed

go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/ArtisanCloud/PowerWeChat/v3
22

3-
go 1.23
3+
go 1.23.0
44

55
// replace github.com/ArtisanCloud/PowerLibs/v3 => ../PowerLibs
66

@@ -11,7 +11,7 @@ require (
1111
github.com/ArtisanCloud/PowerSocialite/v3 v3.0.7
1212
github.com/go-playground/assert/v2 v2.0.1
1313
github.com/pkg/errors v0.9.1
14-
github.com/redis/go-redis/v9 v9.6.1
14+
github.com/redis/go-redis/v9 v9.6.3
1515
github.com/stretchr/testify v1.9.0
1616
)
1717

@@ -26,7 +26,7 @@ require (
2626
go.opentelemetry.io/otel/trace v1.4.0 // indirect
2727
go.uber.org/multierr v1.11.0 // indirect
2828
go.uber.org/zap v1.27.0 // indirect
29-
golang.org/x/crypto v0.28.0 // indirect
29+
golang.org/x/crypto v0.35.0 // indirect
3030
gopkg.in/yaml.v2 v2.4.0 // indirect
3131
gopkg.in/yaml.v3 v3.0.1 // indirect
3232
)

go.sum

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
3333
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
3434
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
3535
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
36-
github.com/redis/go-redis/v9 v9.6.1 h1:HHDteefn6ZkTtY5fGUE8tj8uy85AHk6zP7CpzIAM0y4=
37-
github.com/redis/go-redis/v9 v9.6.1/go.mod h1:0C0c6ycQsdpVNQpxb1njEQIqkx5UcsM8FJCQLgE9+RA=
36+
github.com/redis/go-redis/v9 v9.6.3 h1:8Dr5ygF1QFXRxIH/m3Xg9MMG1rS8YCtAgosrsewT6i0=
37+
github.com/redis/go-redis/v9 v9.6.3/go.mod h1:0C0c6ycQsdpVNQpxb1njEQIqkx5UcsM8FJCQLgE9+RA=
3838
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
3939
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
4040
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
@@ -51,10 +51,10 @@ go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
5151
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
5252
go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=
5353
go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
54-
golang.org/x/crypto v0.28.0 h1:GBDwsMXVQi34v5CCYUm2jkJvu4cbtru2U4TN2PSyQnw=
55-
golang.org/x/crypto v0.28.0/go.mod h1:rmgy+3RHxRZMyY0jjAJShp2zgEdOqj2AO7U0pYmeQ7U=
56-
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
57-
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
54+
golang.org/x/crypto v0.35.0 h1:b15kiHdrGCHrP6LvwaQ3c03kgNhhiMgvlhxHQhmg2Xs=
55+
golang.org/x/crypto v0.35.0/go.mod h1:dy7dXNW32cAb/6/PRuTNsix8T+vJAqvuIy5Bli/x0YQ=
56+
golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc=
57+
golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
5858
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
5959
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
6060
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=

src/basicService/media/client.go

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,25 +54,34 @@ func (comp *Client) UploadThumb(ctx context.Context, path string) (*response.Res
5454
// https://developers.weixin.qq.com/doc/offiaccount/Asset_Management/New_temporary_materials.html
5555
func (comp *Client) Upload(ctx context.Context, mediaType string, path string) (*response.ResponseUploadMedia, error) {
5656

57-
_, err := os.Stat(path)
58-
if (err != nil && os.IsExist(err)) && (err != nil && os.IsPermission(err)) {
59-
return nil, errors.New(fmt.Sprintf("File does not exist, or the file is unreadable: \"%s\"", path))
57+
if path == "" {
58+
return nil, errors.New("path is empty")
59+
}
60+
61+
stat, err := os.Stat(path)
62+
if err != nil {
63+
if os.IsNotExist(err) {
64+
return nil, fmt.Errorf("file does not exist: \"%s\"", path)
65+
}
66+
if os.IsPermission(err) {
67+
return nil, fmt.Errorf("permission denied for file: \"%s\"", path)
68+
}
69+
return nil, fmt.Errorf("unable to access file \"%s\": %w", path, err)
70+
}
71+
if stat.IsDir() {
72+
return nil, fmt.Errorf("path is a directory, not a file: \"%s\"", path)
6073
}
6174

6275
if !object.ContainsString(comp.AllowTypes, mediaType) {
6376
return nil, errors.New(fmt.Sprintf("Unsupported media type: '%s'", mediaType))
6477
}
6578

66-
outResponse := &response.ResponseUploadMedia{}
67-
var files *object.HashMap
68-
if path != "" {
69-
files = &object.HashMap{
70-
"media": path,
71-
}
72-
} else {
73-
return nil, errors.New("path is empty")
79+
files := &object.HashMap{
80+
"media": path,
7481
}
7582

83+
outResponse := &response.ResponseUploadMedia{}
84+
7685
_, err = comp.BaseClient.HttpUpload(ctx, "cgi-bin/media/upload", files, nil, &object.StringMap{
7786
"type": mediaType,
7887
}, nil, outResponse)

src/payment/fundApp/client.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package fundApp
22

33
import (
44
"context"
5+
"fmt"
56
"github.com/ArtisanCloud/PowerLibs/v3/object"
67
"github.com/ArtisanCloud/PowerWeChat/v3/src/payment/fundApp/request"
78
"github.com/ArtisanCloud/PowerWeChat/v3/src/payment/fundApp/response"
@@ -40,3 +41,39 @@ func (comp *Client) TransferBills(ctx context.Context, data *request.RequestTran
4041

4142
return result, err
4243
}
44+
45+
// 商户单号查询转账单
46+
// https://pay.weixin.qq.com/doc/v3/merchant/4012716437
47+
func (comp *Client) QueryOutBill(ctx context.Context, outBillNO string) (*response.ResponseQueryOutBill, error) {
48+
49+
result := &response.ResponseQueryOutBill{}
50+
51+
endpoint := comp.Wrap(fmt.Sprintf("/v3/fund-app/mch-transfer/transfer-bills/out-bill-no/%s", outBillNO))
52+
_, err := comp.SafeRequestV3(ctx, endpoint, nil, http.MethodPost, &object.HashMap{}, nil, result)
53+
54+
return result, err
55+
}
56+
57+
// 微信单号查询转账单
58+
// https://pay.weixin.qq.com/doc/v3/merchant/4012716457
59+
func (comp *Client) QueryTransferBill(ctx context.Context, transferBillNO string) (*response.ResponseQueryTransferBill, error) {
60+
61+
result := &response.ResponseQueryTransferBill{}
62+
63+
endpoint := comp.Wrap(fmt.Sprintf("/v3/fund-app/mch-transfer/transfer-bills/transfer-bill-no/%s", transferBillNO))
64+
_, err := comp.SafeRequestV3(ctx, endpoint, nil, http.MethodPost, &object.HashMap{}, nil, result)
65+
66+
return result, err
67+
}
68+
69+
// 撤销转账
70+
// https://pay.weixin.qq.com/doc/v3/merchant/4012716458
71+
func (comp *Client) Cancel(ctx context.Context, outBillNO string) (*response.ResponseCancelBill, error) {
72+
73+
result := &response.ResponseCancelBill{}
74+
75+
endpoint := comp.Wrap(fmt.Sprintf("/v3/fund-app/mch-transfer/transfer-bills/out-bill-no/%s/cancel", outBillNO))
76+
_, err := comp.SafeRequestV3(ctx, endpoint, nil, http.MethodPost, &object.HashMap{}, nil, result)
77+
78+
return result, err
79+
}

src/payment/fundApp/response/responseTransferBills.go

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,47 @@ import (
99

1010
type ResponseTransferBills struct {
1111
response.ResponsePayment
12+
OutBillNo string `json:"out_bill_no"`
13+
TransferBillNo string `json:"transfer_bill_no"`
14+
CreateTime string `json:"create_time"`
15+
State string `json:"state"`
16+
FailReason string `json:"fail_reason"`
17+
PackageInfo string `json:"package_info"`
18+
}
19+
20+
type ResponseCancelBill struct {
21+
OutBillNo string `json:"out_bill_no"`
22+
TransferBillNo string `json:"transfer_bill_no"`
23+
State string `json:"state"`
24+
UpdateTime string `json:"update_time"`
25+
}
26+
27+
type ResponseQueryOutBill struct {
28+
MchId string `json:"mch_id"`
29+
OutBillNo string `json:"out_bill_no"`
30+
TransferBillNo string `json:"transfer_bill_no"`
31+
Appid string `json:"appid"`
32+
State string `json:"state"`
33+
TransferAmount int `json:"transfer_amount"`
34+
TransferRemark string `json:"transfer_remark"`
35+
FailReason string `json:"fail_reason"`
36+
Openid string `json:"openid"`
37+
UserName string `json:"user_name"`
38+
CreateTime string `json:"create_time"`
39+
UpdateTime string `json:"update_time"`
40+
}
41+
42+
type ResponseQueryTransferBill struct {
43+
MchId string `json:"mch_id"`
1244
OutBillNo string `json:"out_bill_no"`
1345
TransferBillNo string `json:"transfer_bill_no"`
14-
CreateTime time.Time `json:"create_time"`
46+
Appid string `json:"appid"`
1547
State string `json:"state"`
48+
TransferAmount int `json:"transfer_amount"`
49+
TransferRemark string `json:"transfer_remark"`
1650
FailReason string `json:"fail_reason"`
17-
PackageInfo string `json:"package_info"`
51+
Openid string `json:"openid"`
52+
UserName string `json:"user_name"`
53+
CreateTime time.Time `json:"create_time"`
54+
UpdateTime time.Time `json:"update_time"`
1855
}

0 commit comments

Comments
 (0)