q-koa 13.8.53 → 13.8.54
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/core/file/services/weixinMP.js +210 -168
- package/package.json +1 -1
|
@@ -198,14 +198,15 @@ module.exports = class Singleton {
|
|
|
198
198
|
return access_token
|
|
199
199
|
}
|
|
200
200
|
|
|
201
|
-
async getExpress() {
|
|
201
|
+
async getExpress(_retried = false) {
|
|
202
202
|
const access_token = await this.getAccessToken()
|
|
203
203
|
const url = util.format(getExpressUrl, access_token)
|
|
204
204
|
const result = await wxAxios.post(url).then((res) => res.data)
|
|
205
205
|
if (result.errcode) {
|
|
206
|
-
if (result.errcode
|
|
207
|
-
|
|
208
|
-
|
|
206
|
+
if ([40001, 40014, 42001].includes(result.errcode)) {
|
|
207
|
+
if (_retried) throw new Error(`${result.errcode};${result.errmsg}`)
|
|
208
|
+
await this.getAccessToken(true)
|
|
209
|
+
return await this.getExpress(true)
|
|
209
210
|
}
|
|
210
211
|
throw new Error(`${result.errcode};${result.errmsg}`)
|
|
211
212
|
}
|
|
@@ -224,7 +225,7 @@ module.exports = class Singleton {
|
|
|
224
225
|
shop,
|
|
225
226
|
insured,
|
|
226
227
|
service,
|
|
227
|
-
}) {
|
|
228
|
+
}, _retried = false) {
|
|
228
229
|
const access_token = await this.getAccessToken()
|
|
229
230
|
const url = util.format(addOrderUrl, access_token)
|
|
230
231
|
|
|
@@ -243,8 +244,9 @@ module.exports = class Singleton {
|
|
|
243
244
|
|
|
244
245
|
const result = await wxAxios.post(url, formatOptions).then((res) => res.data)
|
|
245
246
|
if (result.errcode) {
|
|
246
|
-
if (result.errcode
|
|
247
|
-
|
|
247
|
+
if ([40001, 40014, 42001].includes(result.errcode)) {
|
|
248
|
+
if (_retried) throw new Error(`${result.errcode};${result.errmsg}`)
|
|
249
|
+
await this.getAccessToken(true)
|
|
248
250
|
return await this.addOrder({
|
|
249
251
|
add_source,
|
|
250
252
|
order_id,
|
|
@@ -257,14 +259,14 @@ module.exports = class Singleton {
|
|
|
257
259
|
shop,
|
|
258
260
|
insured,
|
|
259
261
|
service,
|
|
260
|
-
})
|
|
262
|
+
}, true)
|
|
261
263
|
}
|
|
262
264
|
throw new Error(`${result.errcode};${result.errmsg}`)
|
|
263
265
|
}
|
|
264
266
|
return result
|
|
265
267
|
}
|
|
266
268
|
|
|
267
|
-
async addSubanchor({ roomId, username }) {
|
|
269
|
+
async addSubanchor({ roomId, username }, _retried = false) {
|
|
268
270
|
const access_token = await this.getAccessToken()
|
|
269
271
|
const url = util.format(addSubanchorUrl, access_token)
|
|
270
272
|
|
|
@@ -275,19 +277,20 @@ module.exports = class Singleton {
|
|
|
275
277
|
|
|
276
278
|
const result = await wxAxios.post(url, formatOptions).then((res) => res.data)
|
|
277
279
|
if (result.errcode) {
|
|
278
|
-
if (result.errcode
|
|
279
|
-
|
|
280
|
+
if ([40001, 40014, 42001].includes(result.errcode)) {
|
|
281
|
+
if (_retried) throw new Error(`${result.errcode};${result.errmsg}`)
|
|
282
|
+
await this.getAccessToken(true)
|
|
280
283
|
return await this.addSubanchor({
|
|
281
284
|
roomId,
|
|
282
285
|
username,
|
|
283
|
-
})
|
|
286
|
+
}, true)
|
|
284
287
|
}
|
|
285
288
|
throw new Error(`${result.errcode};${result.errmsg}`)
|
|
286
289
|
}
|
|
287
290
|
return result
|
|
288
291
|
}
|
|
289
292
|
|
|
290
|
-
async addRole({ username, role = 2 }) {
|
|
293
|
+
async addRole({ username, role = 2 }, _retried = false) {
|
|
291
294
|
const access_token = await this.getAccessToken()
|
|
292
295
|
const url = util.format(addRoleUrl, access_token)
|
|
293
296
|
|
|
@@ -297,12 +300,13 @@ module.exports = class Singleton {
|
|
|
297
300
|
}
|
|
298
301
|
const result = await wxAxios.post(url, formatOptions).then((res) => res.data)
|
|
299
302
|
if (result.errcode) {
|
|
300
|
-
if (result.errcode
|
|
301
|
-
|
|
303
|
+
if ([40001, 40014, 42001].includes(result.errcode)) {
|
|
304
|
+
if (_retried) throw new Error(`${result.errcode};${result.errmsg}`)
|
|
305
|
+
await this.getAccessToken(true)
|
|
302
306
|
return await this.addRole({
|
|
303
307
|
username,
|
|
304
308
|
role,
|
|
305
|
-
})
|
|
309
|
+
}, true)
|
|
306
310
|
}
|
|
307
311
|
throw new Error(`${result.errcode};${result.errmsg}`)
|
|
308
312
|
}
|
|
@@ -321,7 +325,7 @@ module.exports = class Singleton {
|
|
|
321
325
|
anchorWechat = '',
|
|
322
326
|
anchorName = '',
|
|
323
327
|
closeReplay = 1,
|
|
324
|
-
}) {
|
|
328
|
+
}, _retried = false) {
|
|
325
329
|
const access_token = await this.getAccessToken()
|
|
326
330
|
const url = util.format(createLiveUrl, access_token)
|
|
327
331
|
|
|
@@ -347,8 +351,9 @@ module.exports = class Singleton {
|
|
|
347
351
|
}
|
|
348
352
|
const result = await wxAxios.post(url, formatOptions).then((res) => res.data)
|
|
349
353
|
if (result.errcode) {
|
|
350
|
-
if (result.errcode
|
|
351
|
-
|
|
354
|
+
if ([40001, 40014, 42001].includes(result.errcode)) {
|
|
355
|
+
if (_retried) throw new Error(`${result.errcode};${result.errmsg}`)
|
|
356
|
+
await this.getAccessToken(true)
|
|
352
357
|
return await this.createLive({
|
|
353
358
|
name,
|
|
354
359
|
createrWechat,
|
|
@@ -361,14 +366,14 @@ module.exports = class Singleton {
|
|
|
361
366
|
anchorWechat,
|
|
362
367
|
anchorName,
|
|
363
368
|
closeReplay,
|
|
364
|
-
})
|
|
369
|
+
}, true)
|
|
365
370
|
}
|
|
366
371
|
throw new Error(`${result.errcode};${result.errmsg}`)
|
|
367
372
|
}
|
|
368
373
|
return result
|
|
369
374
|
}
|
|
370
375
|
|
|
371
|
-
async getLive(start = 0, limit = 10) {
|
|
376
|
+
async getLive(start = 0, limit = 10, _retried = false) {
|
|
372
377
|
const access_token = await this.getAccessToken()
|
|
373
378
|
const url = util.format(getLiveUrl, access_token)
|
|
374
379
|
|
|
@@ -378,30 +383,32 @@ module.exports = class Singleton {
|
|
|
378
383
|
}
|
|
379
384
|
const result = await wxAxios.post(url, formatOptions).then((res) => res.data)
|
|
380
385
|
if (result.errcode) {
|
|
381
|
-
if (result.errcode
|
|
382
|
-
|
|
383
|
-
|
|
386
|
+
if ([40001, 40014, 42001].includes(result.errcode)) {
|
|
387
|
+
if (_retried) throw new Error(`${result.errcode};${result.errmsg}`)
|
|
388
|
+
await this.getAccessToken(true)
|
|
389
|
+
return await this.getLive(start, limit, true)
|
|
384
390
|
}
|
|
385
391
|
throw new Error(`${result.errcode};${result.errmsg}`)
|
|
386
392
|
}
|
|
387
393
|
return result.room_info
|
|
388
394
|
}
|
|
389
395
|
|
|
390
|
-
async getPhoneNumber(code) {
|
|
396
|
+
async getPhoneNumber(code, _retried = false) {
|
|
391
397
|
const access_token = await this.getAccessToken()
|
|
392
398
|
const url = util.format(getPhoneNumberUrl, access_token)
|
|
393
399
|
const result = await wxAxios.post(url, { code }).then((res) => res.data)
|
|
394
400
|
if (result.errcode) {
|
|
395
|
-
if (result.errcode
|
|
396
|
-
|
|
397
|
-
|
|
401
|
+
if ([40001, 40014, 42001].includes(result.errcode)) {
|
|
402
|
+
if (_retried) throw new Error(`${result.errcode};${result.errmsg}`)
|
|
403
|
+
await this.getAccessToken(true)
|
|
404
|
+
return await this.getPhoneNumber(code, true)
|
|
398
405
|
}
|
|
399
406
|
throw new Error(`${result.errcode};${result.errmsg}`)
|
|
400
407
|
}
|
|
401
408
|
return result.phone_info
|
|
402
409
|
}
|
|
403
410
|
|
|
404
|
-
async createUrlLink(options) {
|
|
411
|
+
async createUrlLink(options, _retried = false) {
|
|
405
412
|
const { page, scene, ...rest } = options
|
|
406
413
|
const access_token = await this.getAccessToken()
|
|
407
414
|
const url = util.format(createUrlLinkUrl, access_token)
|
|
@@ -418,16 +425,17 @@ module.exports = class Singleton {
|
|
|
418
425
|
const result = await wxAxios.post(url, payLoad).then((res) => res.data)
|
|
419
426
|
|
|
420
427
|
if (result.errcode) {
|
|
421
|
-
if (result.errcode
|
|
422
|
-
|
|
423
|
-
|
|
428
|
+
if ([40001, 40014, 42001].includes(result.errcode)) {
|
|
429
|
+
if (_retried) throw new Error(`${result.errcode};${result.errmsg}`)
|
|
430
|
+
await this.getAccessToken(true)
|
|
431
|
+
return await this.createUrlLink(options, true)
|
|
424
432
|
}
|
|
425
433
|
throw new Error(`${result.errcode};${result.errmsg}`)
|
|
426
434
|
}
|
|
427
435
|
return result.url_link
|
|
428
436
|
}
|
|
429
437
|
|
|
430
|
-
async queryUrlLink(url_link) {
|
|
438
|
+
async queryUrlLink(url_link, _retried = false) {
|
|
431
439
|
const access_token = await this.getAccessToken()
|
|
432
440
|
const url = util.format(queryUrlLinkUrl, access_token)
|
|
433
441
|
|
|
@@ -438,9 +446,10 @@ module.exports = class Singleton {
|
|
|
438
446
|
.then((res) => res.data)
|
|
439
447
|
|
|
440
448
|
if (result.errcode) {
|
|
441
|
-
if (result.errcode
|
|
442
|
-
|
|
443
|
-
|
|
449
|
+
if ([40001, 40014, 42001].includes(result.errcode)) {
|
|
450
|
+
if (_retried) throw new Error(`${result.errcode};${result.errmsg}`)
|
|
451
|
+
await this.getAccessToken(true)
|
|
452
|
+
return await this.queryUrlLink(url_link, true)
|
|
444
453
|
}
|
|
445
454
|
if (result.errcode === 85403) {
|
|
446
455
|
return {
|
|
@@ -452,7 +461,7 @@ module.exports = class Singleton {
|
|
|
452
461
|
return result.url_link_info
|
|
453
462
|
}
|
|
454
463
|
|
|
455
|
-
async createShortLink(options) {
|
|
464
|
+
async createShortLink(options, _retried = false) {
|
|
456
465
|
const { page, scene, title, ...rest } = options
|
|
457
466
|
const access_token = await this.getAccessToken()
|
|
458
467
|
const url = util.format(createShortLinkUrl, access_token)
|
|
@@ -471,16 +480,17 @@ module.exports = class Singleton {
|
|
|
471
480
|
const result = await wxAxios.post(url, payLoad).then((res) => res.data)
|
|
472
481
|
|
|
473
482
|
if (result.errcode) {
|
|
474
|
-
if (result.errcode
|
|
475
|
-
|
|
476
|
-
|
|
483
|
+
if ([40001, 40014, 42001].includes(result.errcode)) {
|
|
484
|
+
if (_retried) throw new Error(`${result.errcode};${result.errmsg}`)
|
|
485
|
+
await this.getAccessToken(true)
|
|
486
|
+
return await this.createShortLink(options, true)
|
|
477
487
|
}
|
|
478
488
|
throw new Error(`${result.errcode};${result.errmsg}`)
|
|
479
489
|
}
|
|
480
490
|
return result.link
|
|
481
491
|
}
|
|
482
492
|
|
|
483
|
-
async createUrlscheme(options) {
|
|
493
|
+
async createUrlscheme(options, _retried = false) {
|
|
484
494
|
const { page, scene, ...rest } = options
|
|
485
495
|
const access_token = await this.getAccessToken()
|
|
486
496
|
const url = util.format(createUrlschemeUrl, access_token)
|
|
@@ -499,16 +509,17 @@ module.exports = class Singleton {
|
|
|
499
509
|
const result = await wxAxios.post(url, payLoad).then((res) => res.data)
|
|
500
510
|
|
|
501
511
|
if (result.errcode) {
|
|
502
|
-
if (result.errcode
|
|
503
|
-
|
|
504
|
-
|
|
512
|
+
if ([40001, 40014, 42001].includes(result.errcode)) {
|
|
513
|
+
if (_retried) throw new Error(`${result.errcode};${result.errmsg}`)
|
|
514
|
+
await this.getAccessToken(true)
|
|
515
|
+
return await this.createUrlscheme(options, true)
|
|
505
516
|
}
|
|
506
517
|
throw new Error(`${result.errcode};${result.errmsg}`)
|
|
507
518
|
}
|
|
508
519
|
return result.openlink
|
|
509
520
|
}
|
|
510
521
|
|
|
511
|
-
async createQR(options) {
|
|
522
|
+
async createQR(options, _retried = false) {
|
|
512
523
|
if (!this.config.targetPath) throw new Error('没有配置文件夹')
|
|
513
524
|
const access_token = await this.getAccessToken()
|
|
514
525
|
const url = util.format(createQRCodeUrl, access_token)
|
|
@@ -533,9 +544,10 @@ module.exports = class Singleton {
|
|
|
533
544
|
return res.data
|
|
534
545
|
})
|
|
535
546
|
if (bufferResult.errcode) {
|
|
536
|
-
if (bufferResult.errcode
|
|
537
|
-
|
|
538
|
-
|
|
547
|
+
if ([40001, 40014, 42001].includes(bufferResult.errcode)) {
|
|
548
|
+
if (_retried) throw new Error(`${bufferResult.errcode};${bufferResult.errmsg}`)
|
|
549
|
+
await this.getAccessToken(true)
|
|
550
|
+
return await this.createQR(options, true)
|
|
539
551
|
}
|
|
540
552
|
throw new Error(bufferResult.errmsg)
|
|
541
553
|
}
|
|
@@ -546,7 +558,7 @@ module.exports = class Singleton {
|
|
|
546
558
|
return `${creatuuid}.png`
|
|
547
559
|
}
|
|
548
560
|
|
|
549
|
-
async createQRBuffer(options) {
|
|
561
|
+
async createQRBuffer(options, _retried = false) {
|
|
550
562
|
const access_token = await this.getAccessToken()
|
|
551
563
|
const url = util.format(createQRCodeUrl, access_token)
|
|
552
564
|
const payLoad = {
|
|
@@ -569,16 +581,17 @@ module.exports = class Singleton {
|
|
|
569
581
|
return res.data
|
|
570
582
|
})
|
|
571
583
|
if (bufferResult.errcode) {
|
|
572
|
-
if (bufferResult.errcode
|
|
573
|
-
|
|
574
|
-
|
|
584
|
+
if ([40001, 40014, 42001].includes(bufferResult.errcode)) {
|
|
585
|
+
if (_retried) throw new Error(`${bufferResult.errcode};${bufferResult.errmsg}`)
|
|
586
|
+
await this.getAccessToken(true)
|
|
587
|
+
return await this.createQRBuffer(options, true)
|
|
575
588
|
}
|
|
576
589
|
throw new Error(bufferResult.errmsg)
|
|
577
590
|
}
|
|
578
591
|
return bufferResult
|
|
579
592
|
}
|
|
580
593
|
|
|
581
|
-
async sendMessage(options) {
|
|
594
|
+
async sendMessage(options, _retried = false) {
|
|
582
595
|
const access_token = await this.getAccessToken()
|
|
583
596
|
const url = util.format(sendMessageUrl, access_token)
|
|
584
597
|
const formatOptions = {
|
|
@@ -591,30 +604,32 @@ module.exports = class Singleton {
|
|
|
591
604
|
}
|
|
592
605
|
const result = await wxAxios.post(url, formatOptions).then((res) => res.data)
|
|
593
606
|
if (result.errcode) {
|
|
594
|
-
if (result.errcode
|
|
595
|
-
|
|
596
|
-
|
|
607
|
+
if ([40001, 40014, 42001].includes(result.errcode)) {
|
|
608
|
+
if (_retried) throw new Error(`${result.errcode};${result.errmsg}`)
|
|
609
|
+
await this.getAccessToken(true)
|
|
610
|
+
return await this.sendMessage(options, true)
|
|
597
611
|
}
|
|
598
612
|
throw new Error(`${result.errcode};${result.errmsg}`)
|
|
599
613
|
}
|
|
600
614
|
return result
|
|
601
615
|
}
|
|
602
616
|
|
|
603
|
-
async handleMessage(options) {
|
|
617
|
+
async handleMessage(options, _retried = false) {
|
|
604
618
|
const access_token = await this.getAccessToken()
|
|
605
619
|
const url = util.format(handleMessageUrl, access_token)
|
|
606
620
|
const result = await wxAxios.post(url, options).then((res) => res.data)
|
|
607
621
|
if (result.errcode) {
|
|
608
|
-
if (result.errcode
|
|
609
|
-
|
|
610
|
-
|
|
622
|
+
if ([40001, 40014, 42001].includes(result.errcode)) {
|
|
623
|
+
if (_retried) throw new Error(`${result.errcode};${result.errmsg}`)
|
|
624
|
+
await this.getAccessToken(true)
|
|
625
|
+
return await this.handleMessage(options, true)
|
|
611
626
|
}
|
|
612
627
|
throw new Error(`${result.errcode};${result.errmsg}`)
|
|
613
628
|
}
|
|
614
629
|
return result
|
|
615
630
|
}
|
|
616
631
|
|
|
617
|
-
async handleTyping({ touser, is_typing = true }) {
|
|
632
|
+
async handleTyping({ touser, is_typing = true }, _retried = false) {
|
|
618
633
|
const options = {
|
|
619
634
|
touser,
|
|
620
635
|
command: is_typing ? 'Typing' : 'CancelTyping',
|
|
@@ -623,16 +638,17 @@ module.exports = class Singleton {
|
|
|
623
638
|
const url = util.format(handleTypingUrl, access_token)
|
|
624
639
|
const result = await wxAxios.post(url, options).then((res) => res.data)
|
|
625
640
|
if (result.errcode) {
|
|
626
|
-
if (result.errcode
|
|
627
|
-
|
|
628
|
-
|
|
641
|
+
if ([40001, 40014, 42001].includes(result.errcode)) {
|
|
642
|
+
if (_retried) throw new Error(`${result.errcode};${result.errmsg}`)
|
|
643
|
+
await this.getAccessToken(true)
|
|
644
|
+
return await this.handleTyping({ touser, is_typing }, true)
|
|
629
645
|
}
|
|
630
646
|
throw new Error(`${result.errcode};${result.errmsg}`)
|
|
631
647
|
}
|
|
632
648
|
return result
|
|
633
649
|
}
|
|
634
650
|
|
|
635
|
-
async uploadFile(imgUrl) {
|
|
651
|
+
async uploadFile(imgUrl, _retried = false) {
|
|
636
652
|
if (!imgUrl || !imgUrl.includes('//')) throw new Error('检查imgUrl是否链接')
|
|
637
653
|
|
|
638
654
|
const access_token = await this.getAccessToken()
|
|
@@ -643,16 +659,17 @@ module.exports = class Singleton {
|
|
|
643
659
|
formData.append('media', stream)
|
|
644
660
|
const uploadResult = await uploadPromise(url, formData)
|
|
645
661
|
if (uploadResult.errcode) {
|
|
646
|
-
if (uploadResult.errcode
|
|
647
|
-
|
|
648
|
-
|
|
662
|
+
if ([40001, 40014, 42001].includes(uploadResult.errcode)) {
|
|
663
|
+
if (_retried) throw new Error(`${uploadResult.errcode};${uploadResult.errmsg}`)
|
|
664
|
+
await this.getAccessToken(true)
|
|
665
|
+
return await this.uploadFile(imgUrl, true)
|
|
649
666
|
}
|
|
650
667
|
throw new Error(`${uploadResult.errcode};${uploadResult.errmsg}`)
|
|
651
668
|
}
|
|
652
669
|
return uploadResult.media_id
|
|
653
670
|
}
|
|
654
671
|
|
|
655
|
-
async invokeService(payLoad) {
|
|
672
|
+
async invokeService(payLoad, _retried = false) {
|
|
656
673
|
const access_token = await this.getAccessToken()
|
|
657
674
|
const url = util.format(serviceMarketUrl, access_token)
|
|
658
675
|
const result = await wxAxios
|
|
@@ -661,16 +678,17 @@ module.exports = class Singleton {
|
|
|
661
678
|
})
|
|
662
679
|
.then((res) => res.data)
|
|
663
680
|
if (result.errcode) {
|
|
664
|
-
if (result.errcode
|
|
665
|
-
|
|
666
|
-
|
|
681
|
+
if ([40001, 40014, 42001].includes(result.errcode)) {
|
|
682
|
+
if (_retried) throw new Error(`${result.errcode};${result.errmsg}`)
|
|
683
|
+
await this.getAccessToken(true)
|
|
684
|
+
return await this.invokeService(payLoad, true)
|
|
667
685
|
}
|
|
668
686
|
throw new Error(`${result.errcode};${result.errmsg}`)
|
|
669
687
|
}
|
|
670
688
|
return result.data
|
|
671
689
|
}
|
|
672
690
|
|
|
673
|
-
async createOrder(payLoad) {
|
|
691
|
+
async createOrder(payLoad, _retried = false) {
|
|
674
692
|
const access_token = await this.getAccessToken()
|
|
675
693
|
const url = util.format(createOrderUrl, access_token)
|
|
676
694
|
const result = await wxAxios
|
|
@@ -680,16 +698,17 @@ module.exports = class Singleton {
|
|
|
680
698
|
.then((res) => res.data)
|
|
681
699
|
|
|
682
700
|
if (result.errcode) {
|
|
683
|
-
if (result.errcode
|
|
684
|
-
|
|
685
|
-
|
|
701
|
+
if ([40001, 40014, 42001].includes(result.errcode)) {
|
|
702
|
+
if (_retried) throw new Error(`${result.errcode};${result.errmsg}`)
|
|
703
|
+
await this.getAccessToken(true)
|
|
704
|
+
return await this.createOrder(payLoad, true)
|
|
686
705
|
}
|
|
687
706
|
throw new Error(`${result.errcode};${result.errmsg}`)
|
|
688
707
|
}
|
|
689
708
|
return result.payment_params
|
|
690
709
|
}
|
|
691
710
|
|
|
692
|
-
async getOrder(payLoad) {
|
|
711
|
+
async getOrder(payLoad, _retried = false) {
|
|
693
712
|
const access_token = await this.getAccessToken()
|
|
694
713
|
const url = util.format(getOrderUrl, access_token)
|
|
695
714
|
const result = await wxAxios
|
|
@@ -699,16 +718,17 @@ module.exports = class Singleton {
|
|
|
699
718
|
.then((res) => res.data)
|
|
700
719
|
|
|
701
720
|
if (result.errcode) {
|
|
702
|
-
if (result.errcode
|
|
703
|
-
|
|
704
|
-
|
|
721
|
+
if ([40001, 40014, 42001].includes(result.errcode)) {
|
|
722
|
+
if (_retried) throw new Error(`${result.errcode};${result.errmsg}`)
|
|
723
|
+
await this.getAccessToken(true)
|
|
724
|
+
return await this.getOrder(payLoad, true)
|
|
705
725
|
}
|
|
706
726
|
throw new Error(`${result.errcode};${result.errmsg}`)
|
|
707
727
|
}
|
|
708
728
|
return result.order
|
|
709
729
|
}
|
|
710
730
|
|
|
711
|
-
async refundOrder(payLoad) {
|
|
731
|
+
async refundOrder(payLoad, _retried = false) {
|
|
712
732
|
const access_token = await this.getAccessToken()
|
|
713
733
|
const url = util.format(refundOrderUrl, access_token)
|
|
714
734
|
const result = await wxAxios
|
|
@@ -718,16 +738,17 @@ module.exports = class Singleton {
|
|
|
718
738
|
.then((res) => res.data)
|
|
719
739
|
|
|
720
740
|
if (result.errcode) {
|
|
721
|
-
if (result.errcode
|
|
722
|
-
|
|
723
|
-
|
|
741
|
+
if ([40001, 40014, 42001].includes(result.errcode)) {
|
|
742
|
+
if (_retried) throw new Error(`${result.errcode};${result.errmsg}`)
|
|
743
|
+
await this.getAccessToken(true)
|
|
744
|
+
return await this.refundOrder(payLoad, true)
|
|
724
745
|
}
|
|
725
746
|
throw new Error(`${result.errcode};${result.errmsg}`)
|
|
726
747
|
}
|
|
727
748
|
return result.data
|
|
728
749
|
}
|
|
729
750
|
|
|
730
|
-
async addGood(payLoad) {
|
|
751
|
+
async addGood(payLoad, _retried = false) {
|
|
731
752
|
const access_token = await this.getAccessToken()
|
|
732
753
|
const url = util.format(addGoodUrl, access_token)
|
|
733
754
|
const result = await wxAxios
|
|
@@ -736,9 +757,10 @@ module.exports = class Singleton {
|
|
|
736
757
|
})
|
|
737
758
|
.then((res) => res.data)
|
|
738
759
|
if (result.errcode) {
|
|
739
|
-
if (result.errcode
|
|
740
|
-
|
|
741
|
-
|
|
760
|
+
if ([40001, 40014, 42001].includes(result.errcode)) {
|
|
761
|
+
if (_retried) throw new Error(`${result.errcode};${result.errmsg}`)
|
|
762
|
+
await this.getAccessToken(true)
|
|
763
|
+
return await this.addGood(payLoad, true)
|
|
742
764
|
}
|
|
743
765
|
// return payLoad
|
|
744
766
|
throw new Error(`${result.errcode};${result.errmsg}`)
|
|
@@ -746,7 +768,7 @@ module.exports = class Singleton {
|
|
|
746
768
|
return result.data
|
|
747
769
|
}
|
|
748
770
|
|
|
749
|
-
async getCategory(payLoad) {
|
|
771
|
+
async getCategory(payLoad, _retried = false) {
|
|
750
772
|
const access_token = await this.getAccessToken()
|
|
751
773
|
const url = util.format(getCategoryUrl, access_token)
|
|
752
774
|
|
|
@@ -756,16 +778,17 @@ module.exports = class Singleton {
|
|
|
756
778
|
})
|
|
757
779
|
.then((res) => res.data)
|
|
758
780
|
if (result.errcode) {
|
|
759
|
-
if (result.errcode
|
|
760
|
-
|
|
761
|
-
|
|
781
|
+
if ([40001, 40014, 42001].includes(result.errcode)) {
|
|
782
|
+
if (_retried) throw new Error(`${result.errcode};${result.errmsg}`)
|
|
783
|
+
await this.getAccessToken(true)
|
|
784
|
+
return await this.getCategory(payLoad, true)
|
|
762
785
|
}
|
|
763
786
|
throw new Error(`${result.errcode};${result.errmsg}`)
|
|
764
787
|
}
|
|
765
788
|
return result
|
|
766
789
|
}
|
|
767
790
|
|
|
768
|
-
async getBrandList(payLoad) {
|
|
791
|
+
async getBrandList(payLoad, _retried = false) {
|
|
769
792
|
const access_token = await this.getAccessToken()
|
|
770
793
|
const url = util.format(getBrandListUrl, access_token)
|
|
771
794
|
|
|
@@ -775,16 +798,17 @@ module.exports = class Singleton {
|
|
|
775
798
|
})
|
|
776
799
|
.then((res) => res.data)
|
|
777
800
|
if (result.errcode) {
|
|
778
|
-
if (result.errcode
|
|
779
|
-
|
|
780
|
-
|
|
801
|
+
if ([40001, 40014, 42001].includes(result.errcode)) {
|
|
802
|
+
if (_retried) throw new Error(`${result.errcode};${result.errmsg}`)
|
|
803
|
+
await this.getAccessToken(true)
|
|
804
|
+
return await this.getBrandList(payLoad, true)
|
|
781
805
|
}
|
|
782
806
|
throw new Error(`${result.errcode};${result.errmsg}`)
|
|
783
807
|
}
|
|
784
808
|
return result.data
|
|
785
809
|
}
|
|
786
810
|
|
|
787
|
-
async getShipTemplate(payLoad) {
|
|
811
|
+
async getShipTemplate(payLoad, _retried = false) {
|
|
788
812
|
const access_token = await this.getAccessToken()
|
|
789
813
|
const url = util.format(getShipTemplateUrl, access_token)
|
|
790
814
|
|
|
@@ -794,16 +818,17 @@ module.exports = class Singleton {
|
|
|
794
818
|
})
|
|
795
819
|
.then((res) => res.data)
|
|
796
820
|
if (result.errcode) {
|
|
797
|
-
if (result.errcode
|
|
798
|
-
|
|
799
|
-
|
|
821
|
+
if ([40001, 40014, 42001].includes(result.errcode)) {
|
|
822
|
+
if (_retried) throw new Error(`${result.errcode};${result.errmsg}`)
|
|
823
|
+
await this.getAccessToken(true)
|
|
824
|
+
return await this.getShipTemplate(payLoad, true)
|
|
800
825
|
}
|
|
801
826
|
throw new Error(`${result.errcode};${result.errmsg}`)
|
|
802
827
|
}
|
|
803
828
|
return result
|
|
804
829
|
}
|
|
805
830
|
|
|
806
|
-
async uploadShip(payLoad) {
|
|
831
|
+
async uploadShip(payLoad, _retried = false) {
|
|
807
832
|
const access_token = await this.getAccessToken()
|
|
808
833
|
const url = util.format(uploadShipUrl, access_token)
|
|
809
834
|
|
|
@@ -813,16 +838,17 @@ module.exports = class Singleton {
|
|
|
813
838
|
})
|
|
814
839
|
.then((res) => res.data)
|
|
815
840
|
if (result.errcode) {
|
|
816
|
-
if (result.errcode
|
|
817
|
-
|
|
818
|
-
|
|
841
|
+
if ([40001, 40014, 42001].includes(result.errcode)) {
|
|
842
|
+
if (_retried) throw new Error(`${result.errcode};${result.errmsg}`)
|
|
843
|
+
await this.getAccessToken(true)
|
|
844
|
+
return await this.uploadShip(payLoad, true)
|
|
819
845
|
}
|
|
820
846
|
throw new Error(`${result.errcode};${result.errmsg}`)
|
|
821
847
|
}
|
|
822
848
|
return result
|
|
823
849
|
}
|
|
824
850
|
|
|
825
|
-
async uploadPreShip(payLoad) {
|
|
851
|
+
async uploadPreShip(payLoad, _retried = false) {
|
|
826
852
|
const access_token = await this.getAccessToken()
|
|
827
853
|
const url = util.format(uploadPreShipUrl, access_token)
|
|
828
854
|
|
|
@@ -832,16 +858,17 @@ module.exports = class Singleton {
|
|
|
832
858
|
})
|
|
833
859
|
.then((res) => res.data)
|
|
834
860
|
if (result.errcode) {
|
|
835
|
-
if (result.errcode
|
|
836
|
-
|
|
837
|
-
|
|
861
|
+
if ([40001, 40014, 42001].includes(result.errcode)) {
|
|
862
|
+
if (_retried) throw new Error(`${result.errcode};${result.errmsg}`)
|
|
863
|
+
await this.getAccessToken(true)
|
|
864
|
+
return await this.uploadPreShip(payLoad, true)
|
|
838
865
|
}
|
|
839
866
|
throw new Error(`${result.errcode};${result.errmsg}`)
|
|
840
867
|
}
|
|
841
868
|
return result
|
|
842
869
|
}
|
|
843
870
|
|
|
844
|
-
async getShipOrderList(payLoad) {
|
|
871
|
+
async getShipOrderList(payLoad, _retried = false) {
|
|
845
872
|
const access_token = await this.getAccessToken()
|
|
846
873
|
const url = util.format(getShipOrderListUrl, access_token)
|
|
847
874
|
|
|
@@ -851,16 +878,17 @@ module.exports = class Singleton {
|
|
|
851
878
|
})
|
|
852
879
|
.then((res) => res.data)
|
|
853
880
|
if (result.errcode) {
|
|
854
|
-
if (result.errcode
|
|
855
|
-
|
|
856
|
-
|
|
881
|
+
if ([40001, 40014, 42001].includes(result.errcode)) {
|
|
882
|
+
if (_retried) throw new Error(`${result.errcode};${result.errmsg}`)
|
|
883
|
+
await this.getAccessToken(true)
|
|
884
|
+
return await this.getShipOrderList(payLoad, true)
|
|
857
885
|
}
|
|
858
886
|
throw new Error(`${result.errcode};${result.errmsg}`)
|
|
859
887
|
}
|
|
860
888
|
return result
|
|
861
889
|
}
|
|
862
890
|
|
|
863
|
-
async uploadImage(payLoad) {
|
|
891
|
+
async uploadImage(payLoad, _retried = false) {
|
|
864
892
|
const access_token = await this.getAccessToken()
|
|
865
893
|
const { upload_type, resp_type, ...rest } = payLoad
|
|
866
894
|
|
|
@@ -878,16 +906,17 @@ module.exports = class Singleton {
|
|
|
878
906
|
.then((res) => res.data)
|
|
879
907
|
|
|
880
908
|
if (result.errcode) {
|
|
881
|
-
if (result.errcode
|
|
882
|
-
|
|
883
|
-
|
|
909
|
+
if ([40001, 40014, 42001].includes(result.errcode)) {
|
|
910
|
+
if (_retried) throw new Error(`${result.errcode};${result.errmsg}`)
|
|
911
|
+
await this.getAccessToken(true)
|
|
912
|
+
return await this.uploadImage(payLoad, true)
|
|
884
913
|
}
|
|
885
914
|
throw new Error(`${result.errcode};${result.errmsg}`)
|
|
886
915
|
}
|
|
887
916
|
return result.pic_file
|
|
888
917
|
}
|
|
889
918
|
|
|
890
|
-
async setMsgJumpPath(payLoad) {
|
|
919
|
+
async setMsgJumpPath(payLoad, _retried = false) {
|
|
891
920
|
const access_token = await this.getAccessToken()
|
|
892
921
|
const url = util.format(setMsgJumpPathUrl, access_token)
|
|
893
922
|
|
|
@@ -897,16 +926,17 @@ module.exports = class Singleton {
|
|
|
897
926
|
})
|
|
898
927
|
.then((res) => res.data)
|
|
899
928
|
if (result.errcode) {
|
|
900
|
-
if (result.errcode
|
|
901
|
-
|
|
902
|
-
|
|
929
|
+
if ([40001, 40014, 42001].includes(result.errcode)) {
|
|
930
|
+
if (_retried) throw new Error(`${result.errcode};${result.errmsg}`)
|
|
931
|
+
await this.getAccessToken(true)
|
|
932
|
+
return await this.setMsgJumpPath(payLoad, true)
|
|
903
933
|
}
|
|
904
934
|
throw new Error(`${result.errcode};${result.errmsg}`)
|
|
905
935
|
}
|
|
906
936
|
return result
|
|
907
937
|
}
|
|
908
938
|
|
|
909
|
-
async getDeliveryList(payLoad) {
|
|
939
|
+
async getDeliveryList(payLoad, _retried = false) {
|
|
910
940
|
const access_token = await this.getAccessToken()
|
|
911
941
|
const url = util.format(getDeliveryListUrl, access_token)
|
|
912
942
|
|
|
@@ -916,16 +946,17 @@ module.exports = class Singleton {
|
|
|
916
946
|
})
|
|
917
947
|
.then((res) => res.data)
|
|
918
948
|
if (result.errcode) {
|
|
919
|
-
if (result.errcode
|
|
920
|
-
|
|
921
|
-
|
|
949
|
+
if ([40001, 40014, 42001].includes(result.errcode)) {
|
|
950
|
+
if (_retried) throw new Error(`${result.errcode};${result.errmsg}`)
|
|
951
|
+
await this.getAccessToken(true)
|
|
952
|
+
return await this.getDeliveryList(payLoad, true)
|
|
922
953
|
}
|
|
923
954
|
throw new Error(`${result.errcode};${result.errmsg}`)
|
|
924
955
|
}
|
|
925
956
|
return result
|
|
926
957
|
}
|
|
927
958
|
|
|
928
|
-
async getUserPortrait(payLoad) {
|
|
959
|
+
async getUserPortrait(payLoad, _retried = false) {
|
|
929
960
|
const access_token = await this.getAccessToken()
|
|
930
961
|
const url = util.format(getUserPortraitUrl, access_token)
|
|
931
962
|
|
|
@@ -935,16 +966,17 @@ module.exports = class Singleton {
|
|
|
935
966
|
})
|
|
936
967
|
.then((res) => res.data)
|
|
937
968
|
if (result.errcode) {
|
|
938
|
-
if (result.errcode
|
|
939
|
-
|
|
940
|
-
|
|
969
|
+
if ([40001, 40014, 42001].includes(result.errcode)) {
|
|
970
|
+
if (_retried) throw new Error(`${result.errcode};${result.errmsg}`)
|
|
971
|
+
await this.getAccessToken(true)
|
|
972
|
+
return await this.getUserPortrait(payLoad, true)
|
|
941
973
|
}
|
|
942
974
|
throw new Error(`${result.errcode};${result.errmsg}`)
|
|
943
975
|
}
|
|
944
976
|
return result
|
|
945
977
|
}
|
|
946
978
|
|
|
947
|
-
async getVisitTrend(payLoad) {
|
|
979
|
+
async getVisitTrend(payLoad, _retried = false) {
|
|
948
980
|
const access_token = await this.getAccessToken()
|
|
949
981
|
let url = ''
|
|
950
982
|
if (payLoad.type === 'month') {
|
|
@@ -970,9 +1002,10 @@ module.exports = class Singleton {
|
|
|
970
1002
|
})
|
|
971
1003
|
.then((res) => res.data)
|
|
972
1004
|
if (result.errcode) {
|
|
973
|
-
if (result.errcode
|
|
974
|
-
|
|
975
|
-
|
|
1005
|
+
if ([40001, 40014, 42001].includes(result.errcode)) {
|
|
1006
|
+
if (_retried) throw new Error(`${result.errcode};${result.errmsg}`)
|
|
1007
|
+
await this.getAccessToken(true)
|
|
1008
|
+
return await this.getVisitTrend(payLoad, true)
|
|
976
1009
|
}
|
|
977
1010
|
if (result.errcode === 61503) {
|
|
978
1011
|
return null
|
|
@@ -982,15 +1015,16 @@ module.exports = class Singleton {
|
|
|
982
1015
|
return result
|
|
983
1016
|
}
|
|
984
1017
|
|
|
985
|
-
async getCommentInfo(commentId) {
|
|
1018
|
+
async getCommentInfo(commentId, _retried = false) {
|
|
986
1019
|
const access_token = await this.getAccessToken()
|
|
987
1020
|
const url = util.format(getCommentInfoUrl, commentId, access_token)
|
|
988
1021
|
|
|
989
1022
|
const result = await wxAxios.get(url).then((res) => res.data)
|
|
990
1023
|
if (result.errcode) {
|
|
991
|
-
if (result.errcode
|
|
992
|
-
|
|
993
|
-
|
|
1024
|
+
if ([40001, 40014, 42001].includes(result.errcode)) {
|
|
1025
|
+
if (_retried) throw new Error(`${result.errcode};${result.errmsg}`)
|
|
1026
|
+
await this.getAccessToken(true)
|
|
1027
|
+
return await this.getCommentInfo(commentId, true)
|
|
994
1028
|
}
|
|
995
1029
|
if (result.errcode === 61503) {
|
|
996
1030
|
return null
|
|
@@ -1000,22 +1034,23 @@ module.exports = class Singleton {
|
|
|
1000
1034
|
return result
|
|
1001
1035
|
}
|
|
1002
1036
|
|
|
1003
|
-
async createActivity() {
|
|
1037
|
+
async createActivity(_retried = false) {
|
|
1004
1038
|
const access_token = await this.getAccessToken()
|
|
1005
1039
|
const url = util.format(createActivityUrl, access_token)
|
|
1006
1040
|
|
|
1007
1041
|
const result = await wxAxios.get(url).then((res) => res.data)
|
|
1008
1042
|
if (result.errcode) {
|
|
1009
|
-
if (result.errcode
|
|
1010
|
-
|
|
1011
|
-
|
|
1043
|
+
if ([40001, 40014, 42001].includes(result.errcode)) {
|
|
1044
|
+
if (_retried) throw new Error(`${result.errcode};${result.errmsg}`)
|
|
1045
|
+
await this.getAccessToken(true)
|
|
1046
|
+
return await this.createActivity(true)
|
|
1012
1047
|
}
|
|
1013
1048
|
throw new Error(`${result.errcode};${result.errmsg}`)
|
|
1014
1049
|
}
|
|
1015
1050
|
return result
|
|
1016
1051
|
}
|
|
1017
1052
|
|
|
1018
|
-
async setUpdatableMsg(target) {
|
|
1053
|
+
async setUpdatableMsg(target, _retried = false) {
|
|
1019
1054
|
let {
|
|
1020
1055
|
activity_id,
|
|
1021
1056
|
target_state,
|
|
@@ -1073,9 +1108,10 @@ module.exports = class Singleton {
|
|
|
1073
1108
|
}
|
|
1074
1109
|
const result = await wxAxios.post(url, postData).then((res) => res.data)
|
|
1075
1110
|
if (result.errcode) {
|
|
1076
|
-
if (result.errcode
|
|
1077
|
-
|
|
1078
|
-
|
|
1111
|
+
if ([40001, 40014, 42001].includes(result.errcode)) {
|
|
1112
|
+
if (_retried) throw new Error(`${result.errcode};${result.errmsg}`)
|
|
1113
|
+
await this.getAccessToken(true)
|
|
1114
|
+
return await this.setUpdatableMsg(target, true)
|
|
1079
1115
|
}
|
|
1080
1116
|
throw new Error(`${result.errcode};${result.errmsg}`)
|
|
1081
1117
|
}
|
|
@@ -1113,7 +1149,7 @@ module.exports = class Singleton {
|
|
|
1113
1149
|
}
|
|
1114
1150
|
}
|
|
1115
1151
|
|
|
1116
|
-
async b2bRefund({ mchid, app_key, data }) {
|
|
1152
|
+
async b2bRefund({ mchid, app_key, data }, _retried = false) {
|
|
1117
1153
|
const requestUrl = b2bRefundUrl
|
|
1118
1154
|
|
|
1119
1155
|
const access_token = await this.getAccessToken()
|
|
@@ -1130,16 +1166,17 @@ module.exports = class Singleton {
|
|
|
1130
1166
|
const url = util.format(requestUrl, access_token, pay_sig)
|
|
1131
1167
|
const result = await wxAxios.post(url, signData).then((res) => res.data)
|
|
1132
1168
|
if (result.errcode) {
|
|
1133
|
-
if (result.errcode
|
|
1134
|
-
|
|
1135
|
-
|
|
1169
|
+
if ([40001, 40014, 42001].includes(result.errcode)) {
|
|
1170
|
+
if (_retried) throw new Error(`${result.errcode};${result.errmsg}`)
|
|
1171
|
+
await this.getAccessToken(true)
|
|
1172
|
+
return await this.b2bRefund({ mchid, app_key, data }, true)
|
|
1136
1173
|
}
|
|
1137
1174
|
throw new Error(`${result.errcode};${result.errmsg}`)
|
|
1138
1175
|
}
|
|
1139
1176
|
return result
|
|
1140
1177
|
}
|
|
1141
1178
|
|
|
1142
|
-
async b2bCheckRefund({ mchid, app_key, out_refund_no }) {
|
|
1179
|
+
async b2bCheckRefund({ mchid, app_key, out_refund_no }, _retried = false) {
|
|
1143
1180
|
const requestUrl = b2bCheckRefundUrl
|
|
1144
1181
|
|
|
1145
1182
|
const access_token = await this.getAccessToken()
|
|
@@ -1156,16 +1193,17 @@ module.exports = class Singleton {
|
|
|
1156
1193
|
const url = util.format(requestUrl, access_token, pay_sig)
|
|
1157
1194
|
const result = await wxAxios.post(url, signData).then((res) => res.data)
|
|
1158
1195
|
if (result.errcode) {
|
|
1159
|
-
if (result.errcode
|
|
1160
|
-
|
|
1161
|
-
|
|
1196
|
+
if ([40001, 40014, 42001].includes(result.errcode)) {
|
|
1197
|
+
if (_retried) throw new Error(`${result.errcode};${result.errmsg}`)
|
|
1198
|
+
await this.getAccessToken(true)
|
|
1199
|
+
return await this.b2bCheckRefund({ mchid, app_key, out_refund_no }, true)
|
|
1162
1200
|
}
|
|
1163
1201
|
throw new Error(`${result.errcode};${result.errmsg}`)
|
|
1164
1202
|
}
|
|
1165
1203
|
return result
|
|
1166
1204
|
}
|
|
1167
1205
|
|
|
1168
|
-
async b2bCheckOrder({ mchid, app_key, out_trade_no }) {
|
|
1206
|
+
async b2bCheckOrder({ mchid, app_key, out_trade_no }, _retried = false) {
|
|
1169
1207
|
const requestUrl = b2bCheckOrderUrl
|
|
1170
1208
|
|
|
1171
1209
|
const access_token = await this.getAccessToken()
|
|
@@ -1182,16 +1220,17 @@ module.exports = class Singleton {
|
|
|
1182
1220
|
const url = util.format(requestUrl, access_token, pay_sig)
|
|
1183
1221
|
const result = await wxAxios.post(url, signData).then((res) => res.data)
|
|
1184
1222
|
if (result.errcode) {
|
|
1185
|
-
if (result.errcode
|
|
1186
|
-
|
|
1187
|
-
|
|
1223
|
+
if ([40001, 40014, 42001].includes(result.errcode)) {
|
|
1224
|
+
if (_retried) throw new Error(`${result.errcode};${result.errmsg}`)
|
|
1225
|
+
await this.getAccessToken(true)
|
|
1226
|
+
return await this.b2bCheckOrder({ mchid, app_key, out_trade_no }, true)
|
|
1188
1227
|
}
|
|
1189
1228
|
throw new Error(`${result.errcode};${result.errmsg}`)
|
|
1190
1229
|
}
|
|
1191
1230
|
return result
|
|
1192
1231
|
}
|
|
1193
1232
|
|
|
1194
|
-
async b2bPreStore(list) {
|
|
1233
|
+
async b2bPreStore(list, _retried = false) {
|
|
1195
1234
|
const access_token = await this.getAccessToken()
|
|
1196
1235
|
const url = util.format(b2bPreStoreUrl, access_token)
|
|
1197
1236
|
|
|
@@ -1201,16 +1240,17 @@ module.exports = class Singleton {
|
|
|
1201
1240
|
})
|
|
1202
1241
|
.then((res) => res.data)
|
|
1203
1242
|
if (result.errcode) {
|
|
1204
|
-
if (result.errcode
|
|
1205
|
-
|
|
1206
|
-
|
|
1243
|
+
if ([40001, 40014, 42001].includes(result.errcode)) {
|
|
1244
|
+
if (_retried) throw new Error(`${result.errcode};${result.errmsg}`)
|
|
1245
|
+
await this.getAccessToken(true)
|
|
1246
|
+
return await this.b2bPreStore(list, true)
|
|
1207
1247
|
}
|
|
1208
1248
|
throw new Error(`${result.errcode};${result.errmsg}`)
|
|
1209
1249
|
}
|
|
1210
1250
|
return result
|
|
1211
1251
|
}
|
|
1212
1252
|
|
|
1213
|
-
async b2bFinish({ mchid, app_key, out_trade_no }) {
|
|
1253
|
+
async b2bFinish({ mchid, app_key, out_trade_no }, _retried = false) {
|
|
1214
1254
|
const requestUrl = b2bFinishUrl
|
|
1215
1255
|
|
|
1216
1256
|
const access_token = await this.getAccessToken()
|
|
@@ -1227,16 +1267,17 @@ module.exports = class Singleton {
|
|
|
1227
1267
|
const url = util.format(requestUrl, access_token, pay_sig)
|
|
1228
1268
|
const result = await wxAxios.post(url, signData).then((res) => res.data)
|
|
1229
1269
|
if (result.errcode) {
|
|
1230
|
-
if (result.errcode
|
|
1231
|
-
|
|
1232
|
-
|
|
1270
|
+
if ([40001, 40014, 42001].includes(result.errcode)) {
|
|
1271
|
+
if (_retried) throw new Error(`${result.errcode};${result.errmsg}`)
|
|
1272
|
+
await this.getAccessToken(true)
|
|
1273
|
+
return await this.b2bFinish({ mchid, app_key, out_trade_no }, true)
|
|
1233
1274
|
}
|
|
1234
1275
|
throw new Error(`${result.errcode};${result.errmsg}`)
|
|
1235
1276
|
}
|
|
1236
1277
|
return result
|
|
1237
1278
|
}
|
|
1238
1279
|
|
|
1239
|
-
async b2bSendMessage({ type = 2, to_user_list = [], data = {} }) {
|
|
1280
|
+
async b2bSendMessage({ type = 2, to_user_list = [], data = {} }, _retried = false) {
|
|
1240
1281
|
const access_token = await this.getAccessToken()
|
|
1241
1282
|
const url = util.format(b2bSendMessageUrl, access_token)
|
|
1242
1283
|
|
|
@@ -1248,9 +1289,10 @@ module.exports = class Singleton {
|
|
|
1248
1289
|
})
|
|
1249
1290
|
.then((res) => res.data)
|
|
1250
1291
|
if (result.errcode) {
|
|
1251
|
-
if (result.errcode
|
|
1252
|
-
|
|
1253
|
-
|
|
1292
|
+
if ([40001, 40014, 42001].includes(result.errcode)) {
|
|
1293
|
+
if (_retried) throw new Error(`${result.errcode};${result.errmsg}`)
|
|
1294
|
+
await this.getAccessToken(true)
|
|
1295
|
+
return await this.b2bSendMessage({ type, to_user_list, data }, true)
|
|
1254
1296
|
}
|
|
1255
1297
|
throw new Error(`${result.errcode};${result.errmsg}`)
|
|
1256
1298
|
}
|