-
Notifications
You must be signed in to change notification settings - Fork 156
/
client.go
65 lines (51 loc) · 1.85 KB
/
client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package bill
import (
"context"
"github.com/ArtisanCloud/PowerLibs/v3/object"
"github.com/ArtisanCloud/PowerWeChat/v3/src/kernel/power"
"github.com/ArtisanCloud/PowerWeChat/v3/src/payment/bill/response"
payment "github.com/ArtisanCloud/PowerWeChat/v3/src/payment/kernel"
"net/http"
)
type Client struct {
*payment.BaseClient
}
func NewClient(app *payment.ApplicationPaymentInterface) (*Client, error) {
baseClient, err := payment.NewBaseClient(app)
if err != nil {
return nil, err
}
return &Client{
baseClient,
}, nil
}
// Get Trade Bill.
// https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_1_6.shtml
func (comp *Client) GetTradeBill(ctx context.Context, date string, billType string, tarType string) (*response.ResponseBillGet, error) {
result := &response.ResponseBillGet{}
params := &object.StringMap{
"bill_date": date,
"bill_type": billType,
"tar_type": tarType,
}
endpoint := comp.Wrap("/v3/bill/tradebill")
_, err := comp.Request(ctx, endpoint, params, http.MethodPost, &object.HashMap{}, false, nil, result)
return result, err
}
// Get Flow Bill.
// https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_1_7.shtml
func (comp *Client) GetFlowBill(ctx context.Context, date string, accountType string, tarType string) (*response.ResponseBillGet, error) {
result := &response.ResponseBillGet{}
params := &object.StringMap{
"bill_date": date,
"account_type": accountType,
"tar_type": tarType,
}
endpoint := comp.Wrap("/v3/bill/fundflowbill")
_, err := comp.Request(ctx, endpoint, params, http.MethodPost, &object.HashMap{}, false, nil, result)
return result, err
}
// https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_1_8.shtml
func (comp *Client) DownloadBill(ctx context.Context, requestDownload *power.RequestDownload, filePath string) (int64, error) {
return comp.StreamDownload(ctx, requestDownload, filePath)
}