forked from go-pay/gopay
-
Notifications
You must be signed in to change notification settings - Fork 0
/
koubei_api.go
248 lines (236 loc) · 10 KB
/
koubei_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
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
package alipay
import (
"encoding/json"
"fmt"
"github.com/cedarwu/gopay"
)
// koubei.trade.order.aggregate.consult(聚合支付订单咨询服务)
// 文档地址:https://opendocs.alipay.com/apis/api_1/koubei.trade.order.aggregate.consult
func (a *Client) KoubeiTradeOrderAggregateConsult(bm gopay.BodyMap) (aliRsp *KoubeiTradeOrderAggregateConsultRsp, err error) {
err = bm.CheckEmptyError("shop_id", "total_amount")
if err != nil {
return nil, err
}
var bs []byte
if bs, err = a.doAliPay(bm, "koubei.trade.order.aggregate.consult"); err != nil {
return nil, err
}
aliRsp = new(KoubeiTradeOrderAggregateConsultRsp)
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)
}
// koubei.trade.order.precreate(口碑订单预下单)
// 文档地址:https://opendocs.alipay.com/apis/api_1/koubei.trade.order.precreate
func (a *Client) KoubeiTradeOrderPrecreate(bm gopay.BodyMap) (aliRsp *KoubeiTradeOrderPrecreateRsp, err error) {
err = bm.CheckEmptyError("request_id", "biz_type")
if err != nil {
return nil, err
}
var bs []byte
if bs, err = a.doAliPay(bm, "koubei.trade.order.precreate"); err != nil {
return nil, err
}
aliRsp = new(KoubeiTradeOrderPrecreateRsp)
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)
}
// koubei.trade.itemorder.buy(口碑商品交易购买接口)
// 文档地址:https://opendocs.alipay.com/apis/api_1/koubei.trade.itemorder.buy
func (a *Client) KoubeiTradeItemorderBuy(bm gopay.BodyMap) (aliRsp *KoubeiTradeItemorderBuyRsp, err error) {
err = bm.CheckEmptyError("out_order_no", "subject", "biz_product", "biz_scene", "shop_id", "buyer_id", "total_amount", "item_order_details")
if err != nil {
return nil, err
}
var bs []byte
if bs, err = a.doAliPay(bm, "koubei.trade.itemorder.buy"); err != nil {
return nil, err
}
aliRsp = new(KoubeiTradeItemorderBuyRsp)
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)
}
// koubei.trade.order.consult(口碑订单预咨询)
// 文档地址:https://opendocs.alipay.com/apis/api_1/koubei.trade.order.consult
func (a *Client) KoubeiTradeOrderConsult(bm gopay.BodyMap) (aliRsp *KoubeiTradeOrderConsultRsp, err error) {
err = bm.CheckEmptyError("request_id", "user_id", "total_amount", "shop_id")
if err != nil {
return nil, err
}
var bs []byte
if bs, err = a.doAliPay(bm, "koubei.trade.order.consult"); err != nil {
return nil, err
}
aliRsp = new(KoubeiTradeOrderConsultRsp)
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)
}
// koubei.trade.itemorder.refund(口碑商品交易退货接口)
// 文档地址:https://opendocs.alipay.com/apis/api_1/koubei.trade.itemorder.refund
func (a *Client) KoubeiTradeItemorderRefund(bm gopay.BodyMap) (aliRsp *KoubeiTradeItemorderRefundRsp, err error) {
err = bm.CheckEmptyError("order_no", "out_request_no", "refund_infos")
if err != nil {
return nil, err
}
var bs []byte
if bs, err = a.doAliPay(bm, "koubei.trade.itemorder.refund"); err != nil {
return nil, err
}
aliRsp = new(KoubeiTradeItemorderRefundRsp)
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)
}
// koubei.trade.itemorder.query(口碑商品交易查询接口)
// 文档地址:https://opendocs.alipay.com/apis/api_1/koubei.trade.itemorder.query
func (a *Client) KoubeiTradeItemorderQuery(bm gopay.BodyMap) (aliRsp *KoubeiTradeItemorderQueryRsp, err error) {
err = bm.CheckEmptyError("order_no")
if err != nil {
return nil, err
}
var bs []byte
if bs, err = a.doAliPay(bm, "koubei.trade.itemorder.query"); err != nil {
return nil, err
}
aliRsp = new(KoubeiTradeItemorderQueryRsp)
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)
}
// koubei.trade.ticket.ticketcode.send(码商发码成功回调接口)
// 文档地址:https://opendocs.alipay.com/apis/api_1/koubei.trade.ticket.ticketcode.send
func (a *Client) KoubeiTradeTicketTicketcodeSend(bm gopay.BodyMap) (aliRsp *KoubeiTradeTicketTicketcodeSendRsp, err error) {
err = bm.CheckEmptyError("request_id", "isv_ma_list", "send_order_no", "send_token", "order_no")
if err != nil {
return nil, err
}
var bs []byte
if bs, err = a.doAliPay(bm, "koubei.trade.ticket.ticketcode.send"); err != nil {
return nil, err
}
aliRsp = new(KoubeiTradeTicketTicketcodeSendRsp)
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)
}
// koubei.trade.ticket.ticketcode.delay(口碑凭证延期接口)
// 文档地址:https://opendocs.alipay.com/apis/api_1/koubei.trade.ticket.ticketcode.delay
func (a *Client) KoubeiTradeTicketTicketcodeDelay(bm gopay.BodyMap) (aliRsp *KoubeiTradeTicketTicketcodeDelayRsp, err error) {
err = bm.CheckEmptyError("request_id", "end_date", "ticket_code", "code_type", "order_no")
if err != nil {
return nil, err
}
var bs []byte
if bs, err = a.doAliPay(bm, "koubei.trade.ticket.ticketcode.delay"); err != nil {
return nil, err
}
aliRsp = new(KoubeiTradeTicketTicketcodeDelayRsp)
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)
}
// koubei.trade.ticket.ticketcode.query(口碑凭证码查询)
// 文档地址:https://opendocs.alipay.com/apis/api_1/koubei.trade.ticket.ticketcode.query
func (a *Client) KoubeiTradeTicketTicketcodeQuery(bm gopay.BodyMap) (aliRsp *KoubeiTradeTicketTicketcodeQueryRsp, err error) {
err = bm.CheckEmptyError("ticket_code", "shop_id")
if err != nil {
return nil, err
}
var bs []byte
if bs, err = a.doAliPay(bm, "koubei.trade.ticket.ticketcode.query"); err != nil {
return nil, err
}
aliRsp = new(KoubeiTradeTicketTicketcodeQueryRsp)
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)
}
// koubei.trade.ticket.ticketcode.cancel(口碑凭证码撤销核销)
// 文档地址:https://opendocs.alipay.com/apis/api_1/koubei.trade.ticket.ticketcode.cancel
func (a *Client) KoubeiTradeTicketTicketcodeCancel(bm gopay.BodyMap) (aliRsp *KoubeiTradeTicketTicketcodeCancelRsp, err error) {
err = bm.CheckEmptyError("request_id", "request_biz_no", "ticket_code")
if err != nil {
return nil, err
}
var bs []byte
if bs, err = a.doAliPay(bm, "koubei.trade.ticket.ticketcode.cancel"); err != nil {
return nil, err
}
aliRsp = new(KoubeiTradeTicketTicketcodeCancelRsp)
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)
}