q-koa 12.9.4 → 12.9.6
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
|
@@ -22,7 +22,7 @@ const jwt = require('jsonwebtoken')
|
|
|
22
22
|
const verify = util.promisify(jwt.verify)
|
|
23
23
|
const fsExtra = require('fs-extra')
|
|
24
24
|
const { getObject, getAppConfig } = require('./file/utils')
|
|
25
|
-
|
|
25
|
+
const { push } = require('./file/plugins/log/service')
|
|
26
26
|
const restc = require('./restc')
|
|
27
27
|
const APP_DIR = 'app'
|
|
28
28
|
const PLUGINS_DIR = 'plugins'
|
|
@@ -472,6 +472,10 @@ class APP {
|
|
|
472
472
|
await this.initModel(appName)
|
|
473
473
|
// const models = Object.keys(this.app[appName].model).join(' / ')
|
|
474
474
|
} catch (e) {
|
|
475
|
+
push({
|
|
476
|
+
appName,
|
|
477
|
+
message: `${appName}数据库连接失败`,
|
|
478
|
+
})
|
|
475
479
|
console.log(`${appName}数据库连接失败`)
|
|
476
480
|
console.log(e)
|
|
477
481
|
throw new Error(e.message)
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
const {
|
|
1
|
+
const { getConfig } = require('q-koa')
|
|
2
|
+
const lodash = require('lodash')
|
|
2
3
|
const axios = require('axios')
|
|
3
4
|
|
|
4
5
|
const is_dev = process.env.NODE_ENV !== 'production'
|
|
@@ -38,10 +39,17 @@ exports.push = async ({ app, appName = '通知', url, message }) => {
|
|
|
38
39
|
return
|
|
39
40
|
}
|
|
40
41
|
if (log_push_url) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
)
|
|
42
|
+
let site_name = appName
|
|
43
|
+
let logo_image = ''
|
|
44
|
+
let logo_img = ''
|
|
45
|
+
if (app) {
|
|
46
|
+
const appConfig = getConfig(app)
|
|
47
|
+
const res = await appConfig.getObject('base')
|
|
48
|
+
|
|
49
|
+
site_name = res.site_name
|
|
50
|
+
logo_image = res.logo_image
|
|
51
|
+
logo_img = res.logo_img
|
|
52
|
+
}
|
|
45
53
|
|
|
46
54
|
const queryObject = {
|
|
47
55
|
...(is_dev ? {} : { url: encodeURIComponent(url) }),
|
|
@@ -925,12 +925,9 @@ exports.app_pay = async (ctx) => {
|
|
|
925
925
|
// }
|
|
926
926
|
const appConfig = getConfig(app)
|
|
927
927
|
|
|
928
|
-
const {
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
partner_key,
|
|
932
|
-
appId: appid,
|
|
933
|
-
} = await appConfig.getObject(pay_config)
|
|
928
|
+
const { mchId, key, partner_key, appId: appid } = await appConfig.getObject(
|
|
929
|
+
pay_config
|
|
930
|
+
)
|
|
934
931
|
|
|
935
932
|
if (!appid) throw new Error(`appId不能存在`)
|
|
936
933
|
|
|
@@ -1963,3 +1960,89 @@ exports.getCommentInfo = async (ctx, _data) => {
|
|
|
1963
1960
|
ctx.SUCCESS(result)
|
|
1964
1961
|
return result
|
|
1965
1962
|
}
|
|
1963
|
+
|
|
1964
|
+
exports.createActivity = async (ctx, _data) => {
|
|
1965
|
+
const { app, appName } = getAppByCtx(ctx)
|
|
1966
|
+
let {
|
|
1967
|
+
config = 'weixin_mp',
|
|
1968
|
+
template_type = 'start',
|
|
1969
|
+
limit_number = 5,
|
|
1970
|
+
room_limit = 100,
|
|
1971
|
+
activityId = '',
|
|
1972
|
+
} = _data || ctx.request.body
|
|
1973
|
+
const appConfig = getConfig(app)
|
|
1974
|
+
const { app_id, app_secrect } = await appConfig.getObject(config)
|
|
1975
|
+
|
|
1976
|
+
const weixinMp = new WeixinMp({
|
|
1977
|
+
appid: app_id,
|
|
1978
|
+
secrect: app_secrect,
|
|
1979
|
+
})
|
|
1980
|
+
weixinMp.init()
|
|
1981
|
+
|
|
1982
|
+
const template = {
|
|
1983
|
+
start: '21B034D08C5615B9889CE362BB957B1EE69A584B',
|
|
1984
|
+
present: '666F374D69D16C932E45D7E7D9F10CEF6177F5F5',
|
|
1985
|
+
}
|
|
1986
|
+
|
|
1987
|
+
if (!activityId) {
|
|
1988
|
+
const res = await weixinMp.createActivity()
|
|
1989
|
+
activityId = res.activity_id
|
|
1990
|
+
}
|
|
1991
|
+
|
|
1992
|
+
const payLoad = {
|
|
1993
|
+
withShareTicket: true,
|
|
1994
|
+
isUpdatableMessage: true,
|
|
1995
|
+
activityId,
|
|
1996
|
+
templateInfo: {
|
|
1997
|
+
parameterList: [
|
|
1998
|
+
{
|
|
1999
|
+
name: 'member_count',
|
|
2000
|
+
value: limit_number + '',
|
|
2001
|
+
},
|
|
2002
|
+
{
|
|
2003
|
+
name: 'room_limit',
|
|
2004
|
+
value: room_limit + '',
|
|
2005
|
+
},
|
|
2006
|
+
],
|
|
2007
|
+
templateId: template[template_type],
|
|
2008
|
+
},
|
|
2009
|
+
}
|
|
2010
|
+
ctx.SUCCESS(payLoad)
|
|
2011
|
+
return payLoad
|
|
2012
|
+
}
|
|
2013
|
+
|
|
2014
|
+
exports.setUpdatableMsg = async (ctx, _data) => {
|
|
2015
|
+
const { app, appName } = getAppByCtx(ctx)
|
|
2016
|
+
|
|
2017
|
+
const {
|
|
2018
|
+
config = 'weixin_mp',
|
|
2019
|
+
activity_id,
|
|
2020
|
+
target_state = 0,
|
|
2021
|
+
room_limit,
|
|
2022
|
+
member_count,
|
|
2023
|
+
path,
|
|
2024
|
+
version_type,
|
|
2025
|
+
} = _data || ctx.request.body
|
|
2026
|
+
|
|
2027
|
+
if (!activity_id) throw new ServiceError('?activity_id')
|
|
2028
|
+
|
|
2029
|
+
const appConfig = getConfig(app)
|
|
2030
|
+
const { app_id, app_secrect } = await appConfig.getObject(config)
|
|
2031
|
+
const weixinMp = new WeixinMp({
|
|
2032
|
+
appid: app_id,
|
|
2033
|
+
secrect: app_secrect,
|
|
2034
|
+
})
|
|
2035
|
+
weixinMp.init()
|
|
2036
|
+
|
|
2037
|
+
const result = await weixinMp.setUpdatableMsg({
|
|
2038
|
+
activity_id,
|
|
2039
|
+
target_state,
|
|
2040
|
+
room_limit,
|
|
2041
|
+
member_count,
|
|
2042
|
+
path,
|
|
2043
|
+
version_type,
|
|
2044
|
+
})
|
|
2045
|
+
|
|
2046
|
+
ctx.SUCCESS(result)
|
|
2047
|
+
return result
|
|
2048
|
+
}
|
|
@@ -373,14 +373,8 @@ exports.qr_code = async ({
|
|
|
373
373
|
|
|
374
374
|
return qr_image
|
|
375
375
|
} else {
|
|
376
|
-
const {
|
|
377
|
-
|
|
378
|
-
accessKeySecret,
|
|
379
|
-
bucket,
|
|
380
|
-
region,
|
|
381
|
-
cdn_host,
|
|
382
|
-
oss_host,
|
|
383
|
-
} = await appConfig.getObject('oss')
|
|
376
|
+
const { accessKeyId, accessKeySecret, bucket, region, cdn_host, oss_host } =
|
|
377
|
+
await appConfig.getObject('oss')
|
|
384
378
|
if (!(accessKeyId && accessKeySecret && bucket && region)) {
|
|
385
379
|
throw new Error('没有配置oss设置')
|
|
386
380
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const util = require('util')
|
|
2
2
|
const axios = require('axios')
|
|
3
3
|
|
|
4
|
-
const { lodash } = require('q-koa')
|
|
4
|
+
const { lodash, ServiceError } = require('q-koa')
|
|
5
5
|
const getAccessTokenUrl =
|
|
6
6
|
'https://api.weixin.qq.com/cgi-bin/token?grant_type=%s&appid=%s&secret=%s'
|
|
7
7
|
const getPhoneNumberUrl =
|
|
@@ -885,7 +885,7 @@ module.exports = class Singleton {
|
|
|
885
885
|
}
|
|
886
886
|
|
|
887
887
|
async setUpdatableMsg(target) {
|
|
888
|
-
|
|
888
|
+
let {
|
|
889
889
|
activity_id,
|
|
890
890
|
target_state,
|
|
891
891
|
member_count,
|
|
@@ -893,6 +893,16 @@ module.exports = class Singleton {
|
|
|
893
893
|
version_type,
|
|
894
894
|
path,
|
|
895
895
|
} = target
|
|
896
|
+
|
|
897
|
+
if (target_state === 1) {
|
|
898
|
+
version_type = version_type || 'release'
|
|
899
|
+
path = path || 'pages/index/index'
|
|
900
|
+
room_limit = null
|
|
901
|
+
member_count = null
|
|
902
|
+
} else {
|
|
903
|
+
version_type = ''
|
|
904
|
+
path = ''
|
|
905
|
+
}
|
|
896
906
|
const access_token = await this.getAccessToken()
|
|
897
907
|
const url = util.format(setUpdatableMsgUrl, access_token)
|
|
898
908
|
const postData = {
|
|
@@ -927,6 +937,9 @@ module.exports = class Singleton {
|
|
|
927
937
|
].filter(Boolean),
|
|
928
938
|
},
|
|
929
939
|
}
|
|
940
|
+
if (!postData.template_info.parameter_list.length) {
|
|
941
|
+
throw new ServiceError('?parameter_list length 0')
|
|
942
|
+
}
|
|
930
943
|
const result = await axios.post(url, postData).then((res) => res.data)
|
|
931
944
|
if (result.errcode) {
|
|
932
945
|
if (result.errcode === 40001) {
|