mike 6 лет назад
Родитель
Сommit
ba037dbc51
2 измененных файлов с 76 добавлено и 0 удалено
  1. 42 0
      alipay/client.go
  2. 34 0
      alipay/model.go

+ 42 - 0
alipay/client.go

@@ -610,6 +610,48 @@ func (a *Client) UserInfoAuth(bm gopay.BodyMap) (aliRsp *UserInfoAuthResponse, e
 	return aliRsp, nil
 }
 
+// alipay.data.bill.balance.query(支付宝商家账户当前余额查询)
+// https://docs.open.alipay.com/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 nil, fmt.Errorf(`{"code":"%s","msg":"%s","sub_code":"%s","sub_msg":"%s"}`, info.Code, info.Msg, info.SubCode, info.SubMsg)
+	}
+	aliRsp.SignData = getSignData(bs)
+	return aliRsp, nil
+}
+
+// alipay.data.dataservice.bill.downloadurl.query(查询对账单下载地址)
+// https://docs.open.alipay.com/api_15/alipay.data.bill.balance.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 nil, fmt.Errorf(`{"code":"%s","msg":"%s","sub_code":"%s","sub_msg":"%s"}`, info.Code, info.Msg, info.SubCode, info.SubMsg)
+	}
+	aliRsp.SignData = getSignData(bs)
+	return aliRsp, nil
+}
+
 // 向支付宝发送请求
 func (a *Client) doAliPay(bm gopay.BodyMap, method string) (bs []byte, err error) {
 	var (

+ 34 - 0
alipay/model.go

@@ -642,3 +642,37 @@ type MonitorHeartbeatSynResponse struct {
 	SignData     string `json:"-"`
 	Sign         string `json:"sign"`
 }
+
+// ===================================================
+type DataBillBalanceQueryResponse struct {
+	Response     *dataBillBalanceQueryResponse `json:"alipay_data_bill_balance_query,omitempty"`
+	AlipayCertSn string                    `json:"alipay_cert_sn,omitempty"`
+	SignData     string                    `json:"-"`
+	Sign         string                    `json:"sign"`
+}
+
+type dataBillBalanceQueryResponse struct {
+	Code            string `json:"code,omitempty"`
+	Msg             string `json:"msg,omitempty"`
+	SubCode         string `json:"sub_code,omitempty"`
+	SubMsg          string `json:"sub_msg,omitempty"`
+	TotaleAmount    string `json:"total_amount,omitempty"`
+	AvailableAmount string `json:"available_amount,omitempty"`
+	FreezeAmount    string `json:"freeze_amount,omitempty"`
+}
+
+// ===================================================
+type DataBillDownloadUrlQueryResponse struct {
+	Response     *dataBillDownloadUrlQueryResponse `json:"alipay_data_dataservice_bill_downloadurl_query_response,omitempty"`
+	AlipayCertSn string                    `json:"alipay_cert_sn,omitempty"`
+	SignData     string                    `json:"-"`
+	Sign         string                    `json:"sign"`
+}
+
+type dataBillDownloadUrlQueryResponse struct {
+	Code            string `json:"code,omitempty"`
+	Msg             string `json:"msg,omitempty"`
+	SubCode         string `json:"sub_code,omitempty"`
+	SubMsg          string `json:"sub_msg,omitempty"`
+	BillDownloadUrl string `json:"bill_download_url,omitempty"`
+}