-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathstructs.go
331 lines (296 loc) · 9.74 KB
/
structs.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
// Copyright 2020 YBCZ, Inc. All rights reserved.
//
// Use of this source code is governed by a MIT license
// that can be found in the LICENSE file in the root of the source
// tree.
package mch_api
import (
"encoding/json"
"encoding/xml"
"errors"
"fmt"
)
type MchBase struct {
XMLName xml.Name `xml:"xml"`
MchId string `xml:"mch_id,omitempty"`
AppId string `xml:"appid,omitempty"`
NonceStr string `xml:"nonce_str"`
Sign string `xml:"sign"`
SignType string `xml:"sign_type,omitempty"`
}
type MchBaseResponse struct {
XMLName xml.Name `xml:"xml"`
ReturnCode string `xml:"return_code"`
ReturnMsg string `xml:"return_msg"`
ResultCode string `xml:"result_code,omitempty"`
ErrCode string `xml:"err_code,omitempty"`
ErrCodeDes string `xml:"err_code_des,omitempty"`
}
// IsSuccess 是否成功处理
func (m MchBaseResponse) IsSuccess() bool {
return m.ReturnCode == "SUCCESS" && m.ResultCode == "SUCCESS" && (m.ErrCode == "SUCCESS" || m.ErrCode == "")
}
// IsUnCertain 如果出错,是否是微信程序错误
func (m MchBaseResponse) IsUnCertain() bool {
return m.ErrCode == "SYSTEMERROR"
}
// ToError 转为Golang错误
func (m MchBaseResponse) ToError() error {
if m.ErrCodeDes != "" {
return errors.New(fmt.Sprintf("%v %v", m.ErrCode, m.ErrCodeDes))
} else if m.ReturnMsg != "" {
return errors.New(fmt.Sprintf("%v %v", m.ReturnCode, m.ReturnMsg))
} else {
return nil
}
}
// PayUnifiedOrderData `ProfitSharing`设置为"Y"为分账定单标记。
// 不设置,或设置为"N",为普通定单
type PayUnifiedOrderData struct {
MchBase
Openid string `xml:"openid,omitempty"`
DeviceInfo string `xml:"device_info"`
Body string `xml:"body"`
OutTradeNo string `xml:"out_trade_no"`
TotalFee int64 `xml:"total_fee"`
SpBillCreateIp string `xml:"spbill_create_ip"`
NotifyUrl string `xml:"notify_url"`
TradeType string `xml:"trade_type"`
Attach string `xml:"attach"`
ProfitSharing string `xml:"profit_sharing,omitempty"`
}
type PayUnifiedOrderRes struct {
MchBaseResponse
MchBase
PrepayId string `xml:"prepay_id"`
}
// PayNotify 支付成功通知
type PayNotify struct {
MchBaseResponse
MchBase
DeviceInfo string `xml:"device_info"`
OpenId string `xml:"openid"`
IsSubscribe string `xml:"is_subscribe"`
TradeType string `xml:"trade_type"`
BankType string `xml:"bank_type"`
TotalFee int64 `xml:"total_fee"`
SettlementTotalFee int64 `xml:"settlement_total_fee"`
FeeType string `xml:"fee_type"`
CashFee int64 `xml:"cash_fee"`
CashFeeType string `xml:"cash_fee_type"`
CouponFee int64 `xml:"coupon_fee"`
CouponCount int64 `xml:"coupon_count"`
CouponType0 string `xml:"coupon_type_0"`
CouponId0 string `xml:"coupon_id_0"`
CouponFee0 int64 `xml:"coupon_fee_0"`
CouponType1 string `xml:"coupon_type_1"`
CouponId1 string `xml:"coupon_id_1"`
CouponFee1 int64 `xml:"coupon_fee_1"`
CouponType2 string `xml:"coupon_type_2"`
CouponId2 string `xml:"coupon_id_2"`
CouponFee2 int64 `xml:"coupon_fee_2"`
CouponType3 string `xml:"coupon_type_3"`
CouponId3 string `xml:"coupon_id_3"`
CouponFee3 int64 `xml:"coupon_fee_3"`
TransactionId string `xml:"transaction_id"`
OutTradeNo string `xml:"out_trade_no"`
Attach string `xml:"attach"`
TimeEnd string `xml:"time_end"`
}
// PayNotifyRes 回复支付成功通知
type PayNotifyRes MchBaseResponse
type PayOrderQueryData struct {
MchBase
OutTradeNo string `xml:"out_trade_no"`
}
type PayOrderQueryRes PayNotify
type PayRefundData struct {
MchBase
TransactionId string `xml:"transaction_id,omitempty"`
OutTradeNo string `xml:"out_trade_no,omitempty"`
OutRefundNo string `xml:"out_refund_no"`
TotalFee int64 `xml:"total_fee"`
RefundFee int64 `xml:"refund_fee"`
RefundDesc string `xml:"refund_desc,omitempty"`
NotifyUrl string `xml:"notify_url,omitempty"`
}
type PayRefundRes struct {
MchBaseResponse
MchBase
TransactionId string `xml:"transaction_id"`
OutTradeNo string `xml:"out_trade_no"`
OutRefundNo string `xml:"out_refund_no"`
RefundId string `xml:"refund_id"`
RefundFee int64 `xml:"refund_fee"`
TotalFee int64 `xml:"total_fee"`
CashFee int64 `xml:"cash_fee"`
}
// PayProfitSharingReceiver 分账结果中的接收者
type PayProfitSharingReceiver struct {
Type string `json:"type"`
Account string `json:"account"`
Amount int64 `json:"amount"`
Description string `json:"description"`
}
type PayProfitSharingData struct {
MchBase
TransactionId string `xml:"transaction_id"`
OutOrderNo string `xml:"out_order_no"`
Receivers string `xml:"receivers"`
}
func (ppsd *PayProfitSharingData) SerReceivers(list []PayProfitSharingReceiver) (err error) {
raw, err := json.Marshal(list)
if err != nil {
return
}
ppsd.Receivers = string(raw)
return
}
type PayProfitSharingRes struct {
MchBaseResponse
MchBase
TransactionId string `xml:"transaction_id"`
OutOrderNo string `xml:"out_order_no"`
OrderId string `xml:"order_id"`
}
type PayProfitSharingFinishData struct {
MchBase
TransactionId string `xml:"transaction_id"`
OutOrderNo string `xml:"out_order_no"`
Description string `xml:"description"`
}
type PayProfitSharingFinishRes PayProfitSharingRes
type BankPayData struct {
MchBase
PartnerTradeNo string `xml:"partner_trade_no"`
EncBankNo string `xml:"enc_bank_no"`
EncTrueName string `xml:"enc_true_name"`
BankCode string `xml:"bank_code"`
AmountFen int64 `xml:"amount"`
Desc string `xml:"desc"`
}
type BankPayRes struct {
MchBaseResponse
PartnerTradeNo string `xml:"partner_trade_no"`
AmountFen int64 `xml:"amount"`
PaymentNo string `xml:"payment_no"`
CMmsAmt int64 `xml:"cmms_amt"`
}
type BankQueryData struct {
MchBase
PartnerTradeNo string `xml:"partner_trade_no"`
}
type BankQueryRes struct {
MchBaseResponse
PartnerTradeNo string `xml:"partner_trade_no"`
PaymentNo string `xml:"payment_no"`
AmountFen int64 `xml:"amount"`
Status string `xml:"status"`
CMmsAmtFen int64 `xml:"cmms_amt"`
CreateTime string `xml:"create_time"`
PaySuccessTime string `xml:"pay_succ_time"`
Reason string `xml:"reason"`
}
type RedPackSendData struct {
MchBase
MchBillNo string `xml:"mch_billno"`
WxAppId string `xml:"wxappid"`
SendName string `xml:"send_name"`
ReOpenId string `xml:"re_openid"`
TotalAmount int `xml:"total_amount"`
TotalNum int `xml:"total_num"`
Wishing string `xml:"wishing"`
ClientIp string `xml:"client_ip"`
ActName string `xml:"act_name"`
Remark string `xml:"remark"`
}
type RedPackSendRes struct {
MchBaseResponse
MchBillNo string `xml:"mch_billno"`
MchId string `xml:"mch_id"`
WxAppId string `xml:"wxappid"`
ReOpenId string `xml:"re_openid"`
TotalAmount int `xml:"total_amount"`
SendListId string `xml:"send_listid"`
}
type RedPackInfoData struct {
MchBase
MchBillNo string `xml:"mch_billno"`
BillType string `xml:"bill_type"`
}
type RedPackInfoRes struct {
MchBaseResponse
MchBillNo string `xml:"mch_billno"`
MchId string `xml:"mch_id"`
Status string `xml:"status"`
SendType string `xml:"send_type"`
HbType string `xml:"hb_type"`
Reason *string `xml:"reason"`
SendTime string `xml:"send_time"`
RefundTime *string `xml:"refund_time"`
RefundAmount *int `xml:"refund_amount"`
Wishing *string `xml:"wishing"`
Remark *string `xml:"remark"`
ActName *string `xml:"act_name"`
HbList []struct {
HbInfo []struct {
OpenId string `xml:"openid"`
Amount int `xml:"amount"`
RcvTime string `xml:"rcv_time"`
} `xml:"hbinfo"`
} `xml:"hblist"`
}
type TransferData struct {
XMLName xml.Name `xml:"xml"`
NonceStr string `xml:"nonce_str"`
Sign string `xml:"sign"`
SignType string `xml:"sign_type,omitempty"`
MchId string `xml:"mchid"`
MchAppId string `xml:"mch_appid"`
PartnerTradeNo string `xml:"partner_trade_no"`
OpenId string `xml:"openid"`
CheckName string `xml:"check_name"`
ReUserName string `xml:"re_user_name"`
Amount int `xml:"amount"`
Desc string `xml:"desc"`
SpBillCreateIp string `xml:"spbill_create_ip"`
}
type TransferRes struct {
MchBaseResponse
MchId string `xml:"mchid"`
MchAppId string `xml:"mch_appid"`
NonceStr string `xml:"nonce_str"`
PartnerTradeNo string `xml:"partner_trade_no"`
PaymentNo string `xml:"payment_no"`
PaymentTime string `xml:"payment_time"`
}
type PublicKeyData struct {
MchBase
}
type PublicKeyRes struct {
MchBaseResponse
PubKey string `xml:"pub_key"`
}
// RefundNotify 退款状态通知消息
type RefundNotify struct {
MchBaseResponse
MchBase
ReqInfo string `xml:"req_info"`
}
// RefundNotifyBody 退款状态通知内容
type RefundNotifyBody struct {
XMLName xml.Name `xml:"root"`
TransactionId string `xml:"transaction_id"`
OutTradeNo string `xml:"out_trade_no"`
RefundId string `xml:"refund_id"`
OutRefundNo string `xml:"out_refund_no"`
TotalFee int64 `xml:"total_fee"`
SettlementTotalFee int64 `xml:"settlement_total_fee,omitempty"`
RefundFee int64 `xml:"refund_fee"`
SettlementRefundFee int64 `xml:"settlement_refund_fee"`
RefundStatus string `xml:"refund_status"`
SuccessTime string `xml:"success_time,omitempty"`
RefundRecvAccount string `xml:"refund_recv_account"`
RefundAccount string `xml:"refund_account"`
RefundRequestSource string `xml:"refund_request_source"`
}