-
Notifications
You must be signed in to change notification settings - Fork 3
/
balance.go
78 lines (67 loc) · 1.67 KB
/
balance.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
66
67
68
69
70
71
72
73
74
75
76
77
package weixin_shop_pay
import (
"encoding/json"
"io/ioutil"
"log"
)
// Balance 余额
type Balance struct {
client *Client
}
// SubMch 二级商户余额查询
func (t *Balance) SubMch(p *BalanceSubMch) (*BalanceSubMchResp, error) {
// 发起请求
urlPath := "/v3/ecommerce/fund/balance/" + p.SubMchid
resp, err := tool.GetRequest(t.client.config, urlPath)
if err != nil {
return nil, err
}
// 解析返回参数
respData, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
}
if resp.StatusCode != 200 {
err := t.client.setErrorResponse(respData)
if err != nil {
return nil, err
}
}
// 赋值返回
log.Println(string(respData))
var output BalanceSubMchResp
err = json.Unmarshal(respData, &output)
if err != nil {
return nil, err
}
return &output, nil
}
// urlPath := "/v3/ecommerce/fund/enddaybalance/" + p.SubMchid + "?date=" + p.Date
// SubMchDate二级商户按日期余额查询 https://api.mch.weixin.qq.com/v3/ecommerce/fund/enddaybalance/1222212222?date=2019-08-17
func (t *Balance) SubMchDate(p *BalanceSubMch) (*BalanceSubMchResp, error) {
// 发起请求
urlPath := "/v3/ecommerce/fund/enddaybalance/" + p.SubMchid + "?date=" + p.Date
resp, err := tool.GetRequest(t.client.config, urlPath)
if err != nil {
return nil, err
}
// 解析返回参数
respData, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
}
if resp.StatusCode != 200 {
err := t.client.setErrorResponse(respData)
if err != nil {
return nil, err
}
}
// 赋值返回
log.Println(string(respData))
var output BalanceSubMchResp
err = json.Unmarshal(respData, &output)
if err != nil {
return nil, err
}
return &output, nil
}