q-koa 10.0.1 → 10.0.2
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.
|
@@ -41,8 +41,16 @@ const getOrderUrl =
|
|
|
41
41
|
const refundOrderUrl =
|
|
42
42
|
'https://api.weixin.qq.com/shop/pay/refundorder?access_token=%s'
|
|
43
43
|
|
|
44
|
-
const
|
|
45
|
-
|
|
44
|
+
const addGoodUrl = 'https://api.weixin.qq.com/shop/spu/add?access_token=%s'
|
|
45
|
+
|
|
46
|
+
const getCategoryUrl = 'https://api.weixin.qq.com/shop/cat/get?access_token=%s'
|
|
47
|
+
|
|
48
|
+
const getBrandListUrl =
|
|
49
|
+
'https://api.weixin.qq.com/shop/account/get_brand_list?access_token=%s'
|
|
50
|
+
|
|
51
|
+
const uploadImageUrl =
|
|
52
|
+
'https://api.weixin.qq.com/shop/img/upload?access_token=%s'
|
|
53
|
+
|
|
46
54
|
const fsPromise = require('fs/promises')
|
|
47
55
|
const LRU = require('lru-cache')
|
|
48
56
|
const request = require('request')
|
|
@@ -51,7 +59,6 @@ const cache = new LRU({
|
|
|
51
59
|
maxAge: 1000 * 60 * 60,
|
|
52
60
|
})
|
|
53
61
|
const uuid = require('node-uuid')
|
|
54
|
-
const { rest } = require('lodash')
|
|
55
62
|
|
|
56
63
|
const uploadPromise = (options) => {
|
|
57
64
|
return new Promise((resolve, reject) => {
|
|
@@ -571,6 +578,81 @@ module.exports = class Singleton {
|
|
|
571
578
|
return result.data
|
|
572
579
|
}
|
|
573
580
|
|
|
581
|
+
async addGood(payLoad) {
|
|
582
|
+
const access_token = await this.getAccessToken()
|
|
583
|
+
const url = util.format(addGoodUrl, access_token)
|
|
584
|
+
const result = await axios
|
|
585
|
+
.post(url, {
|
|
586
|
+
...payLoad,
|
|
587
|
+
})
|
|
588
|
+
.then((res) => res.data)
|
|
589
|
+
if (result.errcode) {
|
|
590
|
+
if (result.errcode === 40001) {
|
|
591
|
+
cache.reset()
|
|
592
|
+
return await this.addGood(payLoad)
|
|
593
|
+
}
|
|
594
|
+
// return payLoad
|
|
595
|
+
throw new Error(`${result.errcode};${result.errmsg}`)
|
|
596
|
+
}
|
|
597
|
+
return result.data
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
async getCategory(payLoad) {
|
|
601
|
+
const access_token = await this.getAccessToken()
|
|
602
|
+
const url = util.format(getCategoryUrl, access_token)
|
|
603
|
+
|
|
604
|
+
const result = await axios
|
|
605
|
+
.post(url, {
|
|
606
|
+
...payLoad,
|
|
607
|
+
})
|
|
608
|
+
.then((res) => res.data)
|
|
609
|
+
if (result.errcode) {
|
|
610
|
+
if (result.errcode === 40001) {
|
|
611
|
+
cache.reset()
|
|
612
|
+
return await this.getCategory(payLoad)
|
|
613
|
+
}
|
|
614
|
+
throw new Error(`${result.errcode};${result.errmsg}`)
|
|
615
|
+
}
|
|
616
|
+
return result.third_cat_list
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
async getBrandList(payLoad) {
|
|
620
|
+
const access_token = await this.getAccessToken()
|
|
621
|
+
const url = util.format(getBrandListUrl, access_token)
|
|
622
|
+
|
|
623
|
+
const result = await axios
|
|
624
|
+
.post(url, {
|
|
625
|
+
...payLoad,
|
|
626
|
+
})
|
|
627
|
+
.then((res) => res.data)
|
|
628
|
+
if (result.errcode) {
|
|
629
|
+
if (result.errcode === 40001) {
|
|
630
|
+
cache.reset()
|
|
631
|
+
return await this.getBrandList(payLoad)
|
|
632
|
+
}
|
|
633
|
+
throw new Error(`${result.errcode};${result.errmsg}`)
|
|
634
|
+
}
|
|
635
|
+
return result.data
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
async uploadImage(payLoad) {
|
|
639
|
+
const access_token = await this.getAccessToken()
|
|
640
|
+
const url = util.format(uploadImageUrl, access_token)
|
|
641
|
+
|
|
642
|
+
const result = await uploadPromise({
|
|
643
|
+
url,
|
|
644
|
+
formData: payLoad,
|
|
645
|
+
})
|
|
646
|
+
if (result.errcode) {
|
|
647
|
+
if (result.errcode === 40001) {
|
|
648
|
+
cache.reset()
|
|
649
|
+
return await this.uploadImage(payLoad)
|
|
650
|
+
}
|
|
651
|
+
throw new Error(`${result.errcode};${result.errmsg}`)
|
|
652
|
+
}
|
|
653
|
+
return result.img_info
|
|
654
|
+
}
|
|
655
|
+
|
|
574
656
|
getConfig() {
|
|
575
657
|
return this.config
|
|
576
658
|
}
|