q-koa 8.8.2 → 8.8.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
CHANGED
|
@@ -426,6 +426,11 @@ class APP {
|
|
|
426
426
|
) {
|
|
427
427
|
this.app[appName].appConfig.router(router)(this.app[appName])
|
|
428
428
|
}
|
|
429
|
+
|
|
430
|
+
if (this.config.defaultRouter) {
|
|
431
|
+
this.config.defaultRouter(router)(this.app[appName])
|
|
432
|
+
}
|
|
433
|
+
|
|
429
434
|
this.initRouter(router)
|
|
430
435
|
this.app.use(router.routes()).use(router.allowedMethods())
|
|
431
436
|
}
|
package/core/config.js
CHANGED
|
@@ -130,4 +130,20 @@ module.exports = {
|
|
|
130
130
|
excludes: ['admin'],
|
|
131
131
|
},
|
|
132
132
|
cacheModel: [],
|
|
133
|
+
defaultRouter: (router) => (app) => {
|
|
134
|
+
router.get('/common/getAppConfig', app.controller.common.getAppConfig)
|
|
135
|
+
router.get('/weixin/messagePush', app.controller.weixin.messagePush)
|
|
136
|
+
router.get('/common/createQr', app.controller.common.createQr)
|
|
137
|
+
router.get('/lanhu/:str', async (ctx) => {
|
|
138
|
+
const { str } = ctx.params
|
|
139
|
+
const url = `https://lanhu.oss-cn-beijing.aliyuncs.com/${str}`
|
|
140
|
+
const imgData = await axios
|
|
141
|
+
.get(url, {
|
|
142
|
+
responseType: 'arraybuffer',
|
|
143
|
+
})
|
|
144
|
+
.then((res) => res.data)
|
|
145
|
+
ctx.set('content-type', 'image')
|
|
146
|
+
ctx.body = imgData
|
|
147
|
+
})
|
|
148
|
+
},
|
|
133
149
|
}
|
|
@@ -181,9 +181,9 @@ exports.email = async (ctx) => {
|
|
|
181
181
|
exports.createQr = async (ctx) => {
|
|
182
182
|
const { app, appName } = getAppByCtx(ctx)
|
|
183
183
|
|
|
184
|
-
const { url } = ctx.request.query
|
|
184
|
+
const { url, size = 10 } = ctx.request.query
|
|
185
185
|
const img = qr.image(url, {
|
|
186
|
-
size:
|
|
186
|
+
size: Number(size),
|
|
187
187
|
})
|
|
188
188
|
ctx.type = 'image/png'
|
|
189
189
|
ctx.body = img
|
|
@@ -501,7 +501,6 @@ exports.urlToOss = async (ctx) => {
|
|
|
501
501
|
.then((res) => res.data)
|
|
502
502
|
|
|
503
503
|
const type = getImageType(buffer)
|
|
504
|
-
console.log('type', type)
|
|
505
504
|
const fileName = `${
|
|
506
505
|
String(new Date().getTime()).split('').reverse().join('') + Math.random()
|
|
507
506
|
}${type}`
|
|
@@ -519,3 +518,12 @@ exports.urlToOss = async (ctx) => {
|
|
|
519
518
|
throw new Error('上传失败')
|
|
520
519
|
}
|
|
521
520
|
}
|
|
521
|
+
|
|
522
|
+
exports.getAppConfig = async (ctx) => {
|
|
523
|
+
const { app, appName } = getAppByCtx(ctx)
|
|
524
|
+
const appConfig = getConfig(app)
|
|
525
|
+
if (!ctx.request.query.config) throw new Error('?config')
|
|
526
|
+
const result = await appConfig.getObject(ctx.request.query.config)
|
|
527
|
+
|
|
528
|
+
ctx.SUCCESS(result)
|
|
529
|
+
}
|
|
@@ -14,6 +14,12 @@ const fxp = require('fast-xml-parser')
|
|
|
14
14
|
const crypto = require('crypto')
|
|
15
15
|
const OSS = require('ali-oss')
|
|
16
16
|
|
|
17
|
+
const check = ({ timestamp, nonce, signature, token }) => {
|
|
18
|
+
const tmp = [token, timestamp, nonce].sort().join('')
|
|
19
|
+
const currSign = crypto.createHash('sha1').update(tmp).digest('hex')
|
|
20
|
+
return currSign === signature
|
|
21
|
+
}
|
|
22
|
+
|
|
17
23
|
exports.getConfig = async (ctx) => {
|
|
18
24
|
const { app } = getAppByCtx(ctx)
|
|
19
25
|
|
|
@@ -1216,3 +1222,47 @@ exports.init_mp_openid = async (ctx) => {
|
|
|
1216
1222
|
|
|
1217
1223
|
ctx.SUCCESS(result.length)
|
|
1218
1224
|
}
|
|
1225
|
+
|
|
1226
|
+
exports.messagePush = async (ctx) => {
|
|
1227
|
+
const { app, appName } = getAppByCtx(ctx)
|
|
1228
|
+
|
|
1229
|
+
const { echostr, nonce, signature, timestamp } = ctx.request.query
|
|
1230
|
+
|
|
1231
|
+
const token = appName
|
|
1232
|
+
|
|
1233
|
+
const checkResult = check({
|
|
1234
|
+
nonce,
|
|
1235
|
+
signature,
|
|
1236
|
+
timestamp,
|
|
1237
|
+
token,
|
|
1238
|
+
})
|
|
1239
|
+
|
|
1240
|
+
if (!checkResult) {
|
|
1241
|
+
return (ctx.body = 'It is not from weixin')
|
|
1242
|
+
}
|
|
1243
|
+
|
|
1244
|
+
if (ctx.request.method === 'GET') {
|
|
1245
|
+
ctx.body = echostr
|
|
1246
|
+
} else {
|
|
1247
|
+
const result = ctx.request.body
|
|
1248
|
+
if (!lodash.isEmpty(result)) {
|
|
1249
|
+
const event = result.Event
|
|
1250
|
+
if (event) {
|
|
1251
|
+
if (app.service.weixin[event]) {
|
|
1252
|
+
await app.service.weixin[event]({
|
|
1253
|
+
app,
|
|
1254
|
+
result,
|
|
1255
|
+
})
|
|
1256
|
+
}
|
|
1257
|
+
} else {
|
|
1258
|
+
await app.service.weixin.handleUserMessage({
|
|
1259
|
+
app,
|
|
1260
|
+
result,
|
|
1261
|
+
})
|
|
1262
|
+
}
|
|
1263
|
+
}
|
|
1264
|
+
|
|
1265
|
+
ctx.status = 200
|
|
1266
|
+
ctx.body = 'success'
|
|
1267
|
+
}
|
|
1268
|
+
}
|