forked from go-pay/gopay
-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_api.go
54 lines (50 loc) · 2.01 KB
/
data_api.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
package alipay
import (
"encoding/json"
"fmt"
"github.com/cedarwu/gopay"
)
// Deprecated
// 支付宝已不再支持
// alipay.data.bill.balance.query(支付宝商家账户当前余额查询)
// 文档地址:https://opendocs.alipay.com/apis/api_15/alipay.data.bill.balance.query
func (a *Client) DataBillBalanceQuery(bm gopay.BodyMap) (aliRsp *DataBillBalanceQueryResponse, err error) {
var bs []byte
if bs, err = a.doAliPay(bm, "alipay.data.bill.balance.query"); err != nil {
return nil, err
}
aliRsp = new(DataBillBalanceQueryResponse)
if err = json.Unmarshal(bs, aliRsp); err != nil {
return nil, err
}
if aliRsp.Response != nil && aliRsp.Response.Code != "10000" {
info := aliRsp.Response
return aliRsp, fmt.Errorf(`{"code":"%s","msg":"%s","sub_code":"%s","sub_msg":"%s"}`, info.Code, info.Msg, info.SubCode, info.SubMsg)
}
signData, signDataErr := a.getSignData(bs, aliRsp.AlipayCertSn)
aliRsp.SignData = signData
return aliRsp, a.autoVerifySignByCert(aliRsp.Sign, signData, signDataErr)
}
// alipay.data.dataservice.bill.downloadurl.query(查询对账单下载地址)
// 文档地址:https://opendocs.alipay.com/apis/api_15/alipay.data.dataservice.bill.downloadurl.query
func (a *Client) DataBillDownloadUrlQuery(bm gopay.BodyMap) (aliRsp *DataBillDownloadUrlQueryResponse, err error) {
err = bm.CheckEmptyError("bill_type", "bill_date")
if err != nil {
return nil, err
}
var bs []byte
if bs, err = a.doAliPay(bm, "alipay.data.dataservice.bill.downloadurl.query"); err != nil {
return nil, err
}
aliRsp = new(DataBillDownloadUrlQueryResponse)
if err = json.Unmarshal(bs, aliRsp); err != nil {
return nil, err
}
if aliRsp.Response != nil && aliRsp.Response.Code != "10000" {
info := aliRsp.Response
return aliRsp, fmt.Errorf(`{"code":"%s","msg":"%s","sub_code":"%s","sub_msg":"%s"}`, info.Code, info.Msg, info.SubCode, info.SubMsg)
}
signData, signDataErr := a.getSignData(bs, aliRsp.AlipayCertSn)
aliRsp.SignData = signData
return aliRsp, a.autoVerifySignByCert(aliRsp.Sign, signData, signDataErr)
}