q-koa 8.8.2 → 8.8.5
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
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
const axios = require('axios')
|
|
1
2
|
const { Sequelize } = require('sequelize')
|
|
2
3
|
const db = new Map()
|
|
3
4
|
module.exports = {
|
|
@@ -130,4 +131,29 @@ module.exports = {
|
|
|
130
131
|
excludes: ['admin'],
|
|
131
132
|
},
|
|
132
133
|
cacheModel: [],
|
|
134
|
+
defaultRouter: (router) => (app) => {
|
|
135
|
+
router.get('/weixin/h5_login', app.controller.weixin.h5_login)
|
|
136
|
+
router.get(
|
|
137
|
+
'/weixin/h5_login_callback',
|
|
138
|
+
app.controller.weixin.h5_login_callback
|
|
139
|
+
)
|
|
140
|
+
router.get(
|
|
141
|
+
'/weixin/h5_login_info_callback',
|
|
142
|
+
app.controller.weixin.h5_login_info_callback
|
|
143
|
+
)
|
|
144
|
+
router.get('/common/getAppConfig', app.controller.common.getAppConfig)
|
|
145
|
+
router.get('/weixin/messagePush', app.controller.weixin.messagePush)
|
|
146
|
+
router.get('/common/createQr', app.controller.common.createQr)
|
|
147
|
+
router.get('/lanhu/:str', async (ctx) => {
|
|
148
|
+
const { str } = ctx.params
|
|
149
|
+
const url = `https://lanhu.oss-cn-beijing.aliyuncs.com/${str}`
|
|
150
|
+
const imgData = await axios
|
|
151
|
+
.get(url, {
|
|
152
|
+
responseType: 'arraybuffer',
|
|
153
|
+
})
|
|
154
|
+
.then((res) => res.data)
|
|
155
|
+
ctx.set('content-type', 'image')
|
|
156
|
+
ctx.body = imgData
|
|
157
|
+
})
|
|
158
|
+
},
|
|
133
159
|
}
|
|
@@ -181,9 +181,10 @@ 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
|
+
if (!url) return ctx.ERROR('?url')
|
|
185
186
|
const img = qr.image(url, {
|
|
186
|
-
size:
|
|
187
|
+
size: Number(size),
|
|
187
188
|
})
|
|
188
189
|
ctx.type = 'image/png'
|
|
189
190
|
ctx.body = img
|
|
@@ -501,7 +502,6 @@ exports.urlToOss = async (ctx) => {
|
|
|
501
502
|
.then((res) => res.data)
|
|
502
503
|
|
|
503
504
|
const type = getImageType(buffer)
|
|
504
|
-
console.log('type', type)
|
|
505
505
|
const fileName = `${
|
|
506
506
|
String(new Date().getTime()).split('').reverse().join('') + Math.random()
|
|
507
507
|
}${type}`
|
|
@@ -519,3 +519,12 @@ exports.urlToOss = async (ctx) => {
|
|
|
519
519
|
throw new Error('上传失败')
|
|
520
520
|
}
|
|
521
521
|
}
|
|
522
|
+
|
|
523
|
+
exports.getAppConfig = async (ctx) => {
|
|
524
|
+
const { app, appName } = getAppByCtx(ctx)
|
|
525
|
+
const appConfig = getConfig(app)
|
|
526
|
+
if (!ctx.request.query.config) throw new Error('?config')
|
|
527
|
+
const result = await appConfig.getObject(ctx.request.query.config)
|
|
528
|
+
|
|
529
|
+
ctx.SUCCESS(result)
|
|
530
|
+
}
|
|
@@ -183,6 +183,8 @@ exports.showTables = async (ctx) => {
|
|
|
183
183
|
deleteCheckList: lodash.get(target, 'deleteCheckList', []),
|
|
184
184
|
// 批量更新字段
|
|
185
185
|
bulkCreateList: lodash.get(target, 'bulkCreateList', []),
|
|
186
|
+
|
|
187
|
+
fn: app.controller[_model] ? Object.keys(app.controller[_model]) : [],
|
|
186
188
|
}
|
|
187
189
|
})
|
|
188
190
|
|
|
@@ -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
|
+
}
|