-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
imdada.go
575 lines (524 loc) · 20.3 KB
/
imdada.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
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
/*
* Copyright `IMDaDa-Go` Author(https://houseme.github.io/imdadago/). All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* You can obtain one at https://github.com/houseme/imdadago.
*/
package dadago
import (
"context"
"crypto/md5"
"crypto/tls"
"encoding/hex"
"errors"
"os"
"sort"
"strconv"
"strings"
"time"
"github.com/bytedance/sonic"
"github.com/cloudwego/hertz/pkg/app/client"
"github.com/cloudwego/hertz/pkg/common/hlog"
"github.com/cloudwego/hertz/pkg/protocol"
"github.com/cloudwego/hertz/pkg/protocol/consts"
"github.com/houseme/imdadago/domain"
"github.com/houseme/imdadago/internal/log"
)
// New creates a new ImDada client.
func New(ctx context.Context, opts ...Option) *Client {
op := options{
TimeOut: 10 * time.Second,
UserAgent: []byte(userAgent),
Gateway: gateway,
Level: Level(hlog.LevelDebug),
LogPath: os.TempDir(),
}
for _, option := range opts {
option(&op)
}
c := &Client{
op: op,
log: log.InitLog(ctx, op.LogPath, hlog.Level(op.Level)),
response: &protocol.Response{},
request: &domain.Request{
AppKey: op.AppKey,
V: version,
Format: format,
SourceID: op.SourceID,
},
}
c.log.SetLevel(hlog.Level(op.Level))
c.log.CtxInfof(ctx, "im dada init client start level:%s", op.Level)
return c
}
// generateTimestamp Generate current time
func (c *Client) generateTimestamp() {
c.request.Timestamp = time.Now().Unix()
}
// md5Sign
func (c *Client) md5Sign() {
var builder strings.Builder
builder.WriteString(c.op.AppSecret)
builder.WriteString("app_key" + c.request.AppKey)
builder.WriteString("body" + c.request.Body)
builder.WriteString("format" + c.request.Format)
builder.WriteString("source_id" + c.request.SourceID)
builder.WriteString("timestamp" + strconv.FormatInt(c.request.Timestamp, 10))
builder.WriteString("v" + c.request.V)
builder.WriteString(c.op.AppSecret)
h := md5.New()
h.Write([]byte(builder.String()))
c.request.Signature = strings.ToUpper(hex.EncodeToString(h.Sum(nil)))
}
// initRequest
func (c *Client) initRequest(method string) {
c.generateTimestamp()
c.md5Sign()
c.gateway = c.op.Gateway + method
}
// doRequest does the request.
func (c *Client) doRequest(ctx context.Context, method string) error {
c.initRequest(method)
c.log.CtxDebugf(ctx, "request data: %+v", c.request)
jsonBytes, err := sonic.Marshal(c.request)
if err != nil {
return err
}
c.log.CtxDebugf(ctx, "jsonBytes: %s", string(jsonBytes))
request := &protocol.Request{}
request.SetBody(jsonBytes)
request.Header.SetContentTypeBytes([]byte("application/json"))
request.Header.Set("accept", "application/json")
c.log.CtxDebugf(ctx, "request url: %s", c.gateway)
request.SetRequestURI(c.gateway)
request.Header.SetMethod(consts.MethodPost)
request.Header.SetUserAgentBytes(c.op.UserAgent)
c.log.CtxDebugf(ctx, "request create end")
hertz, err := client.NewClient(client.WithTLSConfig(&tls.Config{
InsecureSkipVerify: true,
}), client.WithDialTimeout(c.op.TimeOut))
if err != nil {
return err
}
c.log.CtxDebugf(ctx, "do request start")
if err = hertz.Do(ctx, request, c.response); err != nil {
return err
}
return nil
}
// QueryBalance query balance.
// 查询账户余额 url: http://newopen.imdada.cn/#/development/file/balanceQuery
func (c *Client) QueryBalance(ctx context.Context, req *domain.QueryBalanceRequest) (resp *domain.QueryBalanceResponse, err error) {
if c.request.Body, err = sonic.MarshalString(req); err != nil {
return nil, err
}
c.log.CtxDebugf(ctx, "QueryBalance request data: %s", c.request.Body)
if err = c.doRequest(ctx, queryBalance); err != nil {
return nil, err
}
c.log.CtxDebugf(ctx, "QueryBalance response data: %s", string(c.response.Body()))
if err = sonic.Unmarshal(c.response.Body(), &resp); err != nil {
return nil, err
}
return
}
// Recharge account recharge.
// 获取充值链接 url: http://newopen.imdada.cn/#/development/file/recharge
func (c *Client) Recharge(ctx context.Context, req *domain.RechargeRequest) (resp *domain.RechargeResponse, err error) {
if c.request.Body, err = sonic.MarshalString(req); err != nil {
return nil, err
}
c.log.CtxDebugf(ctx, "Recharge request data: %s", c.request.Body)
if err = c.doRequest(ctx, recharge); err != nil {
return nil, err
}
c.log.CtxDebugf(ctx, "Recharge response data: %s", string(c.response.Body()))
if err = sonic.Unmarshal(c.response.Body(), &resp); err != nil {
return nil, err
}
return
}
// CreateMerchant create merchant.
// 添加商户 url: http://newopen.imdada.cn/#/development/file/merchantAdd
func (c *Client) CreateMerchant(ctx context.Context, req *domain.MerchantCreateRequest) (resp *domain.MerchantCreateResponse, err error) {
if c.request.Body, err = sonic.MarshalString(req); err != nil {
return nil, err
}
c.request.SourceID = ""
c.log.CtxDebugf(ctx, "CreateMerchant request data: %s", c.request.Body)
if err = c.doRequest(ctx, merchantCreate); err != nil {
return nil, err
}
c.log.CtxDebugf(ctx, "CreateMerchant response data: %s", string(c.response.Body()))
if err = sonic.Unmarshal(c.response.Body(), &resp); err != nil {
return nil, err
}
return
}
// CreateShop create shop.
// 添加门店 url: http://newopen.imdada.cn/#/development/file/shopAdd
func (c *Client) CreateShop(ctx context.Context, req *domain.ShopCreateRequest) (resp *domain.ShopCreateResponse, err error) {
if c.request.Body, err = sonic.MarshalString(req); err != nil {
return nil, err
}
c.log.CtxDebugf(ctx, "CreateShop request data: %s", c.request.Body)
if err = c.doRequest(ctx, shopCreate); err != nil {
return nil, err
}
c.log.CtxDebugf(ctx, "CreateShop response data: %s", string(c.response.Body()))
if err = sonic.Unmarshal(c.response.Body(), &resp); err != nil {
return nil, err
}
return
}
// ModifyShop modify shop.
// 编辑门店 url: http://newopen.imdada.cn/#/development/file/shopUpdate
func (c *Client) ModifyShop(ctx context.Context, req *domain.ShopUpdateRequest) (resp *domain.ShopUpdateResponse, err error) {
if c.request.Body, err = sonic.MarshalString(req); err != nil {
return nil, err
}
c.log.CtxDebugf(ctx, "ModifyShop request data: %s", c.request.Body)
if err = c.doRequest(ctx, shopUpdate); err != nil {
return nil, err
}
c.log.CtxDebugf(ctx, "ModifyShop response data: %s", string(c.response.Body()))
if err = sonic.Unmarshal(c.response.Body(), &resp); err != nil {
return nil, err
}
return
}
// QueryShop query shop.
// 门店详情 url: http://newopen.imdada.cn/#/development/file/shopDetail
func (c *Client) QueryShop(ctx context.Context, req *domain.ShopQueryRequest) (resp *domain.ShopQueryResponse, err error) {
if c.request.Body, err = sonic.MarshalString(req); err != nil {
return nil, err
}
c.log.CtxDebugf(ctx, "QueryShop request data: %s", c.request.Body)
if err = c.doRequest(ctx, shopQuery); err != nil {
return nil, err
}
c.log.CtxDebugf(ctx, "QueryShop response data: %s", string(c.response.Body()))
if err = sonic.Unmarshal(c.response.Body(), &resp); err != nil {
return nil, err
}
return
}
// QueryCity query city list
// 获取城市信息列表 http://newopen.imdada.cn/#/development/file/cityList
func (c *Client) QueryCity(ctx context.Context, req *domain.CityListQueryRequest) (resp *domain.CityListQueryResponse, err error) {
if req == nil {
c.request.Body = ""
} else {
if c.request.Body, err = sonic.MarshalString(req); err != nil {
return nil, err
}
}
c.log.CtxDebugf(ctx, "QueryCity request data: %s ", c.request.Body)
if err = c.doRequest(ctx, cityCodeList); err != nil {
return nil, err
}
c.log.CtxDebugf(ctx, "QueryCity response data: %s", string(c.response.Body()))
if err = sonic.Unmarshal(c.response.Body(), &resp); err != nil {
return nil, err
}
return
}
// CreateOrder create order.
// 添加订单 url: http://newopen.imdada.cn/#/development/file/add
func (c *Client) CreateOrder(ctx context.Context, req *domain.OrdersCreateRequest) (resp *domain.OrdersCreateResponse, err error) {
if c.request.Body, err = sonic.MarshalString(req); err != nil {
return nil, err
}
c.log.CtxDebugf(ctx, "CreateOrder request data: %s", c.request.Body)
if err = c.doRequest(ctx, ordersCreate); err != nil {
return nil, err
}
c.log.CtxDebugf(ctx, "CreateOrder response data: %s", string(c.response.Body()))
if err = sonic.Unmarshal(c.response.Body(), &resp); err != nil {
return nil, err
}
return
}
// ReCreateOrder recreate order.
// 重新发布订单 url: http://newopen.imdada.cn/#/development/file/reAdd
func (c *Client) ReCreateOrder(ctx context.Context, req *domain.OrdersCreateRequest) (resp *domain.OrdersCreateResponse, err error) {
if c.request.Body, err = sonic.MarshalString(req); err != nil {
return nil, err
}
c.log.CtxDebugf(ctx, "ReCreateOrder request data: %s", c.request.Body)
if err = c.doRequest(ctx, orderReCreate); err != nil {
return nil, err
}
c.log.CtxDebugf(ctx, "ReCreateOrder response data: %s", string(c.response.Body()))
if err = sonic.Unmarshal(c.response.Body(), &resp); err != nil {
return nil, err
}
return
}
// QueryDeliverFee query deliver fee.
// 订单运费查询 url: http://newopen.imdada.cn/#/development/file/readyAdd
func (c *Client) QueryDeliverFee(ctx context.Context, req *domain.DeliverFeeQueryRequest) (resp *domain.DeliverFeeQueryResponse, err error) {
if c.request.Body, err = sonic.MarshalString(req); err != nil {
return nil, err
}
c.log.CtxDebugf(ctx, "QueryDeliverFee request data: %s", c.request.Body)
if err = c.doRequest(ctx, orderDeliverFeeQuery); err != nil {
return nil, err
}
c.log.CtxDebugf(ctx, "QueryDeliverFee response data: %s", string(c.response.Body()))
if err = sonic.Unmarshal(c.response.Body(), &resp); err != nil {
return nil, err
}
return
}
// OrdersCreateByDeliverFeeQuery create order by deliver the fee query.
// 通过运费接口创建订单 url: http://newopen.imdada.cn/#/development/file/addAfterQuery
func (c *Client) OrdersCreateByDeliverFeeQuery(ctx context.Context, req *domain.OrdersCreateByDeliverFeeQueryRequest) (resp *domain.OrdersCreateByDeliverFeeQueryResponse, err error) {
if c.request.Body, err = sonic.MarshalString(req); err != nil {
return nil, err
}
c.log.CtxDebugf(ctx, "OrdersCreateByDeliverFeeQuery request data: %s", c.request.Body)
if err = c.doRequest(ctx, orderCreateAfterQuery); err != nil {
return nil, err
}
c.log.CtxDebugf(ctx, "OrdersCreateByDeliverFeeQuery response data: %s", string(c.response.Body()))
if err = sonic.Unmarshal(c.response.Body(), &resp); err != nil {
return nil, err
}
return
}
// OrdersAddTip add tip.
// 添加小费 url: http://newopen.imdada.cn/#/development/file/addTip
func (c *Client) OrdersAddTip(ctx context.Context, req *domain.OrdersAddTipRequest) (resp *domain.OrdersAddTipResponse, err error) {
if c.request.Body, err = sonic.MarshalString(req); err != nil {
return nil, err
}
c.log.CtxDebugf(ctx, "OrdersAddTip request data: %s", c.request.Body)
if err = c.doRequest(ctx, orderAddTip); err != nil {
return nil, err
}
c.log.CtxDebugf(ctx, "OrdersAddTip response data: %s", string(c.response.Body()))
if err = sonic.Unmarshal(c.response.Body(), &resp); err != nil {
return nil, err
}
return
}
// QueryOrderStatus query order status.
// 订单详情查询 url: http://newopen.imdada.cn/#/development/file/statusQuery
func (c *Client) QueryOrderStatus(ctx context.Context, req *domain.OrdersQueryRequest) (resp *domain.OrdersQueryResponse, err error) {
if c.request.Body, err = sonic.MarshalString(req); err != nil {
return nil, err
}
c.log.CtxDebugf(ctx, "QueryOrderStatus request data: %s", c.request.Body)
if err = c.doRequest(ctx, orderStatusQuery); err != nil {
return nil, err
}
c.log.CtxDebugf(ctx, "QueryOrderStatus response data: %s", string(c.response.Body()))
if err = sonic.Unmarshal(c.response.Body(), &resp); err != nil {
return nil, err
}
return
}
// CancelOrder cancel order.
// 取消订单 url: http://newopen.imdada.cn/#/development/file/formalCancel
func (c *Client) CancelOrder(ctx context.Context, req *domain.OrdersCancelRequest) (resp *domain.OrdersCancelResponse, err error) {
if c.request.Body, err = sonic.MarshalString(req); err != nil {
return nil, err
}
c.log.CtxDebugf(ctx, "CancelOrder request data: %s", c.request.Body)
if err = c.doRequest(ctx, orderCancel); err != nil {
return nil, err
}
c.log.CtxDebugf(ctx, "CancelOrder response data: %s", string(c.response.Body()))
if err = sonic.Unmarshal(c.response.Body(), &resp); err != nil {
return nil, err
}
return
}
// AdditionalOrders additional order.
// 增加订单 url: http://newopen.imdada.cn/#/development/file/appointOrder
func (c *Client) AdditionalOrders(ctx context.Context, req *domain.OrdersAddAppointRequest) (resp *domain.OrdersAddAppointResponse, err error) {
if c.request.Body, err = sonic.MarshalString(req); err != nil {
return nil, err
}
c.log.CtxDebugf(ctx, "AdditionalOrders request data: %s", c.request.Body)
if err = c.doRequest(ctx, additionalOrders); err != nil {
return nil, err
}
c.log.CtxDebugf(ctx, "AdditionalOrders response data: %s", string(c.response.Body()))
if err = sonic.Unmarshal(c.response.Body(), &resp); err != nil {
return nil, err
}
return
}
// CancelTheAddOnOrder cancel appoint order CancelTheAddOnOrder
// 取消预约单 url: http://newopen.imdada.cn/#/development/file/appointOrderCancel
func (c *Client) CancelTheAddOnOrder(ctx context.Context, req *domain.OrdersCancelAppointRequest) (resp *domain.OrdersCancelAppointResponse, err error) {
if c.request.Body, err = sonic.MarshalString(req); err != nil {
return nil, err
}
c.log.CtxDebugf(ctx, "CancelTheAddOnOrder request data: %s", c.request.Body)
if err = c.doRequest(ctx, cancelAppointOrders); err != nil {
return nil, err
}
c.log.CtxDebugf(ctx, "CancelTheAddOnOrder response data: %s", string(c.response.Body()))
if err = sonic.Unmarshal(c.response.Body(), &resp); err != nil {
return nil, err
}
return
}
// QueriesCanAppendKnights query can append knights.
// 查询可追加骑士 url: http://newopen.imdada.cn/#/development/file/listTransportersToAppoint
func (c *Client) QueriesCanAppendKnights(ctx context.Context, req *domain.OrdersAppointTransporterRequest) (resp *domain.OrdersAppointTransporterResponse, err error) {
if c.request.Body, err = sonic.MarshalString(req); err != nil {
return nil, err
}
c.log.CtxDebugf(ctx, "QueriesCanAppendKnights request data: %s", c.request.Body)
if err = c.doRequest(ctx, transportAppointList); err != nil {
return nil, err
}
c.log.CtxDebugf(ctx, "QueriesCanAppendKnights response data: %s", string(c.response.Body()))
if err = sonic.Unmarshal(c.response.Body(), &resp); err != nil {
return nil, err
}
return
}
// CreateAComplaint create a complaint.
// 创建投诉 url: http://newopen.imdada.cn/#/development/file/complaintDada
func (c *Client) CreateAComplaint(ctx context.Context, req *domain.ComplaintRequest) (resp *domain.ComplaintResponse, err error) {
if c.request.Body, err = sonic.MarshalString(req); err != nil {
return nil, err
}
c.log.CtxDebugf(ctx, "CreateAComplaint request data: %s", c.request.Body)
if err = c.doRequest(ctx, complaintCreate); err != nil {
return nil, err
}
c.log.CtxDebugf(ctx, "CreateAComplaint response data: %s", string(c.response.Body()))
if err = sonic.Unmarshal(c.response.Body(), &resp); err != nil {
return nil, err
}
return
}
// QueryComplaint query complaint.
// 查询投诉 url: http://newopen.imdada.cn/#/development/file/queryComplaintDada
func (c *Client) QueryComplaint(ctx context.Context, req *domain.ComplaintReasonRequest) (resp *domain.ComplaintReasonResponse, err error) {
if c.request.Body, err = sonic.MarshalString(req); err != nil {
return nil, err
}
c.log.CtxDebugf(ctx, "QueryComplaint request data: %s", c.request.Body)
if err = c.doRequest(ctx, complaintReasons); err != nil {
return nil, err
}
c.log.CtxDebugf(ctx, "QueryComplaint response data: %s", string(c.response.Body()))
if err = sonic.Unmarshal(c.response.Body(), &resp); err != nil {
return nil, err
}
return
}
// OrderConfirmGoods order confirm goods.
// 商户确认物品已返还
func (c *Client) OrderConfirmGoods(ctx context.Context, req *domain.OrdersConfirmGoodsRequest) (resp *domain.OrdersConfirmGoodsResponse, err error) {
if c.request.Body, err = sonic.MarshalString(req); err != nil {
return nil, err
}
c.log.CtxDebugf(ctx, "OrderConfirmGoods request data: %s", c.request.Body)
if err = c.doRequest(ctx, orderConfirmGoods); err != nil {
return nil, err
}
c.log.CtxDebugf(ctx, "OrderConfirmGoods response data: %s", string(c.response.Body()))
if err = sonic.Unmarshal(c.response.Body(), &resp); err != nil {
return nil, err
}
return
}
// OrderConfirmCancel order confirm cancel.
// 商户审核骑士取消订单 url: http://newopen.imdada.cn/#/development/file/applicationCancel
func (c *Client) OrderConfirmCancel(ctx context.Context, req *domain.OrdersTransporterCancelAsyncConfirmRequest) (resp *domain.OrdersTransporterCancelAsyncConfirmResponse, err error) {
if c.request.Body, err = sonic.MarshalString(req); err != nil {
return nil, err
}
c.log.CtxDebugf(ctx, "OrderConfirmCancel request data: %s", c.request.Body)
if err = c.doRequest(ctx, messageConfirm); err != nil {
return nil, err
}
c.log.CtxDebugf(ctx, "OrderConfirmCancel response data: %s", string(c.response.Body()))
if err = sonic.Unmarshal(c.response.Body(), &resp); err != nil {
return nil, err
}
return
}
// QueryTransporterPosition query transporter position.
// 查询骑士位置 url: http://newopen.imdada.cn/#/development/file/queryLocation
func (c *Client) QueryTransporterPosition(ctx context.Context, req *domain.OrdersTransporterPositionRequest) (resp *domain.OrdersTransporterPositionResponse, err error) {
if c.request.Body, err = sonic.MarshalString(req); err != nil {
return nil, err
}
c.log.CtxDebugf(ctx, "QueryTransporterPosition request data: %s", c.request.Body)
if err = c.doRequest(ctx, transporterPosition); err != nil {
return nil, err
}
c.log.CtxDebugf(ctx, "QueryTransporterPosition response data: %s", string(c.response.Body()))
if err = sonic.Unmarshal(c.response.Body(), &resp); err != nil {
return nil, err
}
return
}
// QueryTransporterTrack query transporter track.
// 查询骑士轨迹 url: http://newopen.imdada.cn/#/development/file/queryDeliverTrack
func (c *Client) QueryTransporterTrack(ctx context.Context, req *domain.OrdersTransporterTrackRequest) (resp *domain.OrdersTransporterTrackResponse, err error) {
if c.request.Body, err = sonic.MarshalString(req); err != nil {
return nil, err
}
c.log.CtxDebugf(ctx, "QueryTransporterTrack request data: %s", c.request.Body)
if err = c.doRequest(ctx, transporterTrack); err != nil {
return nil, err
}
c.log.CtxDebugf(ctx, "QueryTransporterTrack response data: %s", string(c.response.Body()))
if err = sonic.Unmarshal(c.response.Body(), &resp); err != nil {
return nil, err
}
return
}
// ModifyFetchCode modify fetch code.
// 修改取货码 url: http://newopen.imdada.cn/#/development/file/modifyFetchCode
func (c *Client) ModifyFetchCode(ctx context.Context, req *domain.OrdersFetchCodeModifyRequest) (resp *domain.OrdersFetchCodeModifyResponse, err error) {
if c.request.Body, err = sonic.MarshalString(req); err != nil {
return nil, err
}
c.log.CtxDebugf(ctx, "ModifyFetchCode request data: %s", c.request.Body)
if err = c.doRequest(ctx, fetchCodeModify); err != nil {
return nil, err
}
c.log.CtxDebugf(ctx, "ModifyFetchCode response data: %s", string(c.response.Body()))
if err = sonic.Unmarshal(c.response.Body(), &resp); err != nil {
return nil, err
}
return
}
//
// VerifySignature verify signature.
func (c *Client) VerifySignature(_ context.Context, updateTime int64, clientID, orderID, signature string) (err error) {
var list []string
list = append(list, strconv.FormatInt(updateTime, 10))
list = append(list, clientID)
list = append(list, orderID)
sort.Strings(list)
sign := strings.Join(list, "")
h := md5.New()
h.Write([]byte(sign))
if hex.EncodeToString(h.Sum(nil)) != signature {
return errors.New("signature error")
}
return
}