q-koa 12.9.3 → 12.9.4
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
CHANGED
|
@@ -588,24 +588,20 @@ class APP {
|
|
|
588
588
|
'page'
|
|
589
589
|
)
|
|
590
590
|
|
|
591
|
-
const
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
:
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
primaryKey: true,
|
|
606
|
-
autoIncrement: true,
|
|
607
|
-
},
|
|
608
|
-
}
|
|
591
|
+
const idType = _.get(
|
|
592
|
+
this.app[appName].config[folder],
|
|
593
|
+
'idType',
|
|
594
|
+
belongs === 'setting' ? 'TINYINT' : 'MEDIUMINT'
|
|
595
|
+
)
|
|
596
|
+
|
|
597
|
+
const _id = {
|
|
598
|
+
id: {
|
|
599
|
+
type: Sequelize[idType].UNSIGNED,
|
|
600
|
+
allowNull: false,
|
|
601
|
+
primaryKey: true,
|
|
602
|
+
autoIncrement: true,
|
|
603
|
+
},
|
|
604
|
+
}
|
|
609
605
|
|
|
610
606
|
const attributes = _.defaultsDeep(_.cloneDeep(_attributes), {
|
|
611
607
|
..._id,
|
|
@@ -793,7 +789,7 @@ class APP {
|
|
|
793
789
|
}
|
|
794
790
|
|
|
795
791
|
if (is_dev) {
|
|
796
|
-
console.log(moment().valueOf() - start)
|
|
792
|
+
console.log('挂载service bind', moment().valueOf() - start)
|
|
797
793
|
}
|
|
798
794
|
}
|
|
799
795
|
|
|
@@ -959,24 +955,24 @@ class APP {
|
|
|
959
955
|
]
|
|
960
956
|
for (let i = 0; i < hooksList.length; i++) {
|
|
961
957
|
if (_.get(app, `${appName}.${hooksList[i]}.${controller}.${fn}`)) {
|
|
962
|
-
if (hooksList[i] === 'controller') {
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
}
|
|
958
|
+
// if (hooksList[i] === 'controller') {
|
|
959
|
+
// process.once('unhandledRejection', (reason, promise) => {
|
|
960
|
+
// if (
|
|
961
|
+
// this.app &&
|
|
962
|
+
// this.app[appName] &&
|
|
963
|
+
// this.app[appName].model &&
|
|
964
|
+
// this.app[appName].model.log
|
|
965
|
+
// ) {
|
|
966
|
+
// this.app[appName].model.log.create({
|
|
967
|
+
// url: ctx.request.href,
|
|
968
|
+
// body: ctx.request.body,
|
|
969
|
+
// message: 'promise unhandledRejection',
|
|
970
|
+
// content: reason.stack,
|
|
971
|
+
// header: ctx.request.header,
|
|
972
|
+
// })
|
|
973
|
+
// }
|
|
974
|
+
// })
|
|
975
|
+
// }
|
|
980
976
|
await app[appName][hooksList[i]][controller][fn](ctx)
|
|
981
977
|
}
|
|
982
978
|
}
|
|
@@ -4,7 +4,12 @@ module.exports = {
|
|
|
4
4
|
multiple: false,
|
|
5
5
|
availableSort: false,
|
|
6
6
|
order: ['created_at'],
|
|
7
|
-
select: [
|
|
7
|
+
select: [
|
|
8
|
+
{ key: 'user_id' },
|
|
9
|
+
{ key: 'nick_name' },
|
|
10
|
+
{ key: 'appid' },
|
|
11
|
+
{ key: 'openid' },
|
|
12
|
+
],
|
|
8
13
|
excludes: [],
|
|
9
14
|
limit: 20,
|
|
10
15
|
defaultOrder: [{ sort: 'descending', type: 'id' }],
|
|
@@ -925,9 +925,12 @@ exports.app_pay = async (ctx) => {
|
|
|
925
925
|
// }
|
|
926
926
|
const appConfig = getConfig(app)
|
|
927
927
|
|
|
928
|
-
const {
|
|
929
|
-
|
|
930
|
-
|
|
928
|
+
const {
|
|
929
|
+
mchId,
|
|
930
|
+
key,
|
|
931
|
+
partner_key,
|
|
932
|
+
appId: appid,
|
|
933
|
+
} = await appConfig.getObject(pay_config)
|
|
931
934
|
|
|
932
935
|
if (!appid) throw new Error(`appId不能存在`)
|
|
933
936
|
|
|
@@ -72,6 +72,11 @@ const getUserPortraitUrl =
|
|
|
72
72
|
|
|
73
73
|
const getCommentInfoUrl =
|
|
74
74
|
'https://api.weixin.qq.com/wxaapi/comment/commentinfo/get?commentId=%s&access_token=%s'
|
|
75
|
+
const createActivityUrl =
|
|
76
|
+
'https://api.weixin.qq.com/cgi-bin/message/wxopen/activityid/create?access_token=%s'
|
|
77
|
+
|
|
78
|
+
const setUpdatableMsgUrl =
|
|
79
|
+
'https://api.weixin.qq.com/cgi-bin/message/wxopen/updatablemsg/send?access_token=%s'
|
|
75
80
|
|
|
76
81
|
const fsPromise = require('fs/promises')
|
|
77
82
|
const LRU = require('lru-cache')
|
|
@@ -864,6 +869,75 @@ module.exports = class Singleton {
|
|
|
864
869
|
return result
|
|
865
870
|
}
|
|
866
871
|
|
|
872
|
+
async createActivity() {
|
|
873
|
+
const access_token = await this.getAccessToken()
|
|
874
|
+
const url = util.format(createActivityUrl, access_token)
|
|
875
|
+
|
|
876
|
+
const result = await axios.get(url).then((res) => res.data)
|
|
877
|
+
if (result.errcode) {
|
|
878
|
+
if (result.errcode === 40001) {
|
|
879
|
+
cache.reset()
|
|
880
|
+
return await this.createActivity()
|
|
881
|
+
}
|
|
882
|
+
throw new Error(`${result.errcode};${result.errmsg}`)
|
|
883
|
+
}
|
|
884
|
+
return result
|
|
885
|
+
}
|
|
886
|
+
|
|
887
|
+
async setUpdatableMsg(target) {
|
|
888
|
+
const {
|
|
889
|
+
activity_id,
|
|
890
|
+
target_state,
|
|
891
|
+
member_count,
|
|
892
|
+
room_limit,
|
|
893
|
+
version_type,
|
|
894
|
+
path,
|
|
895
|
+
} = target
|
|
896
|
+
const access_token = await this.getAccessToken()
|
|
897
|
+
const url = util.format(setUpdatableMsgUrl, access_token)
|
|
898
|
+
const postData = {
|
|
899
|
+
activity_id,
|
|
900
|
+
target_state,
|
|
901
|
+
template_info: {
|
|
902
|
+
parameter_list: [
|
|
903
|
+
member_count
|
|
904
|
+
? {
|
|
905
|
+
name: 'member_count',
|
|
906
|
+
value: member_count + '',
|
|
907
|
+
}
|
|
908
|
+
: null,
|
|
909
|
+
room_limit
|
|
910
|
+
? {
|
|
911
|
+
name: 'room_limit',
|
|
912
|
+
value: room_limit + '',
|
|
913
|
+
}
|
|
914
|
+
: null,
|
|
915
|
+
path
|
|
916
|
+
? {
|
|
917
|
+
name: 'path',
|
|
918
|
+
value: path + '',
|
|
919
|
+
}
|
|
920
|
+
: null,
|
|
921
|
+
version_type
|
|
922
|
+
? {
|
|
923
|
+
name: 'version_type',
|
|
924
|
+
value: version_type + '',
|
|
925
|
+
}
|
|
926
|
+
: null,
|
|
927
|
+
].filter(Boolean),
|
|
928
|
+
},
|
|
929
|
+
}
|
|
930
|
+
const result = await axios.post(url, postData).then((res) => res.data)
|
|
931
|
+
if (result.errcode) {
|
|
932
|
+
if (result.errcode === 40001) {
|
|
933
|
+
cache.reset()
|
|
934
|
+
return await this.setUpdatableMsg(target)
|
|
935
|
+
}
|
|
936
|
+
throw new Error(`${result.errcode};${result.errmsg}`)
|
|
937
|
+
}
|
|
938
|
+
return result
|
|
939
|
+
}
|
|
940
|
+
|
|
867
941
|
getConfig() {
|
|
868
942
|
return this.config
|
|
869
943
|
}
|
package/core/middlewares.js
CHANGED
|
@@ -63,24 +63,26 @@ exports.miResponse = (methods) =>
|
|
|
63
63
|
methods,
|
|
64
64
|
})
|
|
65
65
|
|
|
66
|
-
exports.miCors =
|
|
67
|
-
|
|
68
|
-
ctx
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
'Access-Control-Allow-Headers',
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
ctx.
|
|
80
|
-
|
|
81
|
-
|
|
66
|
+
exports.miCors =
|
|
67
|
+
(arr = [], ip = '192.168.0.1') =>
|
|
68
|
+
async (ctx, next) => {
|
|
69
|
+
ctx.set('Access-Control-Allow-Origin', `${ctx.header.origin || '*'}`)
|
|
70
|
+
ctx.set('Access-Control-Allow-Credentials', true)
|
|
71
|
+
// ctx.set('Access-Control-Allow-Headers', '*');
|
|
72
|
+
ctx.set(
|
|
73
|
+
'Access-Control-Allow-Headers',
|
|
74
|
+
` Origin, X-Requested-With, Content-Type, client-type, Accept, ${arr
|
|
75
|
+
.map((item) => `${item}-token`)
|
|
76
|
+
.join(', ')}`
|
|
77
|
+
)
|
|
78
|
+
ctx.set('server-ip', ip)
|
|
79
|
+
ctx.set('Access-Control-Allow-Methods', 'PUT, POST, GET, DELETE, OPTIONS')
|
|
80
|
+
if (ctx.method === 'OPTIONS') {
|
|
81
|
+
ctx.body = 200
|
|
82
|
+
} else {
|
|
83
|
+
await next()
|
|
84
|
+
}
|
|
82
85
|
}
|
|
83
|
-
}
|
|
84
86
|
|
|
85
87
|
exports.miXmlBody = (config) =>
|
|
86
88
|
xmlParser({
|