forked from xiaojiaoyu100/wxpay
-
Notifications
You must be signed in to change notification settings - Fork 0
/
transferinfo.go
67 lines (57 loc) · 2.21 KB
/
transferinfo.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
package wxpay
import "encoding/xml"
// https://pay.weixin.qq.com/wiki/doc/api/tools/mch_pay.php?chapter=14_3
const (
transferInfoURL = "https://api.mch.weixin.qq.com/mmpaymkttransfers/gettransferinfo"
)
const (
transferStatusSuccess = "SUCCESS"
transferStatusFail = "FAILED"
transferStatusProcessing = "PROCESSING"
)
// TransferInfoRequest 查询企业付款参数
type TransferInfoRequest struct {
XMLName xml.Name `xml:"xml"`
AppID string `xml:"appid,omitempty"`
MchID string `xml:"mch_id,omitempty"`
NonceStr string `xml:"nonce_str,omitempty"`
Sign string `xml:"sign,omitempty"`
PartnerTradeNo string `xml:"partner_trade_no,omitempty"` // 商户订单号
}
// TransferInfoResponse 企业付款响应
type TransferInfoResponse struct {
Meta
AppID string `xml:"appid"`
MchID string `xml:"mch_id"`
PartnerTradeNo string `xml:"partner_trade_no"` // 商户订单号
DetailId string `xml:"detail_id"` // 付款单号
Status string `xml:"status"` // 转账状态
Reason string `xml:"reason"` // 失败原因
OpenID string `xml:"openid"` // 收款用户openId
TransferName string `xml:"transfer_name"` // 收款用户姓名
PaymentAmount string `xml:"payment_amount"` // 收款金额
TransferTime string `xml:"transfer_time"` // 转账时间
PaymentTime string `xml:"payment_time"` // 付款成功时间
Remark string `xml:"desc"` // 企业付款备注
}
// GetTransferInfo 企业付款查询
func (c *Client) GetTransferInfo(request *TransferInfoRequest) (*TransferInfoResponse, error) {
request.MchID = c.mchID
request.NonceStr = nonceStr()
request.Sign = signStruct(request, c.apiKey)
var response TransferInfoResponse
_, err := c.request(transferInfoURL, request, &response)
if err != nil {
return nil, err
}
return &response, nil
}
func (resp *TransferInfoResponse) PaidSuccess() bool {
return resp.Status == transferStatusSuccess
}
func (resp *TransferInfoResponse) PaidFail() bool {
return resp.Status == transferStatusFail
}
func (resp *TransferInfoResponse) PayProcessing() bool {
return resp.Status == transferStatusProcessing
}