q-koa 10.0.1 → 10.0.3
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/app.js +12 -2
- package/core/file/services/weixinMP.js +85 -3
- package/package.json +1 -1
package/core/app.js
CHANGED
|
@@ -442,7 +442,9 @@ class APP {
|
|
|
442
442
|
this.app[appName].appConfig &&
|
|
443
443
|
this.app[appName].appConfig.router
|
|
444
444
|
) {
|
|
445
|
-
|
|
445
|
+
try {
|
|
446
|
+
this.app[appName].appConfig.router(router)(this.app[appName])
|
|
447
|
+
} catch (e) {}
|
|
446
448
|
}
|
|
447
449
|
|
|
448
450
|
if (this.config.defaultRouter) {
|
|
@@ -520,7 +522,15 @@ class APP {
|
|
|
520
522
|
)
|
|
521
523
|
const publicExist = fs.existsSync(pluginDir)
|
|
522
524
|
if (!publicExist) await fsPromise.mkdir(pluginDir)
|
|
523
|
-
const
|
|
525
|
+
const excludesModel = _.get(
|
|
526
|
+
this.app[appName],
|
|
527
|
+
'appConfig.excludesModel',
|
|
528
|
+
[]
|
|
529
|
+
)
|
|
530
|
+
const pluginDirList = await fsPromise.readdir(pluginDir)
|
|
531
|
+
const pluginDirResult = pluginDirList.filter(
|
|
532
|
+
(item) => !excludesModel.includes(item)
|
|
533
|
+
)
|
|
524
534
|
for (let i = 0; i < pluginDirResult.length; i++) {
|
|
525
535
|
const folder = pluginDirResult[i]
|
|
526
536
|
const isFolder = fs
|
|
@@ -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
|
}
|