q-koa 13.1.1 → 13.1.2
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.
|
@@ -243,7 +243,7 @@ exports.showTables = async (ctx) => {
|
|
|
243
243
|
),
|
|
244
244
|
|
|
245
245
|
// include for admin
|
|
246
|
-
include:
|
|
246
|
+
include: getValueByModelName(target, 'include', '', model, _model),
|
|
247
247
|
// only include exsit, and for custom like user_distribute has two user model
|
|
248
248
|
relate: lodash.get(target, 'relate', ''),
|
|
249
249
|
// can be mock boolean
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
const {
|
|
1
|
+
const {
|
|
2
|
+
lodash,
|
|
3
|
+
getAppByCtx,
|
|
4
|
+
getConfig,
|
|
5
|
+
moment,
|
|
6
|
+
ServiceError,
|
|
7
|
+
} = require('q-koa')
|
|
2
8
|
|
|
3
9
|
const axios = require('axios')
|
|
4
10
|
const OAuth = require('wechat-oauth')
|
|
@@ -1269,10 +1275,10 @@ exports.short_link = async (ctx) => {
|
|
|
1269
1275
|
ctx.SUCCESS(result)
|
|
1270
1276
|
}
|
|
1271
1277
|
|
|
1272
|
-
exports.url_scheme = async (ctx) => {
|
|
1278
|
+
exports.url_scheme = async (ctx, _data) => {
|
|
1273
1279
|
const { app } = getAppByCtx(ctx)
|
|
1274
1280
|
|
|
1275
|
-
const { page, scene, config = 'weixin_mp' } = ctx.request.body
|
|
1281
|
+
const { page, scene, config = 'weixin_mp' } = _data || ctx.request.body
|
|
1276
1282
|
const appConfig = getConfig(app)
|
|
1277
1283
|
const { app_id, app_secrect } = await appConfig.getObject(config)
|
|
1278
1284
|
const weixinMp = new WeixinMp({
|
|
@@ -1285,9 +1291,32 @@ exports.url_scheme = async (ctx) => {
|
|
|
1285
1291
|
scene,
|
|
1286
1292
|
})
|
|
1287
1293
|
ctx.SUCCESS(result)
|
|
1294
|
+
return result
|
|
1288
1295
|
}
|
|
1289
1296
|
|
|
1290
|
-
exports.
|
|
1297
|
+
exports.query_url_link = async (ctx, _data) => {
|
|
1298
|
+
const { app } = getAppByCtx(ctx)
|
|
1299
|
+
|
|
1300
|
+
const { url_link, config = 'weixin_mp' } = _data || ctx.request.body
|
|
1301
|
+
if (!url_link) throw new ServiceError(`url_link?`)
|
|
1302
|
+
const appConfig = getConfig(app)
|
|
1303
|
+
const { app_id, app_secrect } = await appConfig.getObject(config)
|
|
1304
|
+
const weixinMp = new WeixinMp({
|
|
1305
|
+
appid: app_id,
|
|
1306
|
+
secrect: app_secrect,
|
|
1307
|
+
})
|
|
1308
|
+
weixinMp.init()
|
|
1309
|
+
const result = await weixinMp.queryUrlLink(url_link)
|
|
1310
|
+
const payLoad = {
|
|
1311
|
+
...result,
|
|
1312
|
+
is_out: result.expire_time * 1000 - moment().valueOf() < 0,
|
|
1313
|
+
}
|
|
1314
|
+
|
|
1315
|
+
ctx.SUCCESS(payLoad)
|
|
1316
|
+
return payLoad
|
|
1317
|
+
}
|
|
1318
|
+
|
|
1319
|
+
exports.qr_code = async (ctx, _data) => {
|
|
1291
1320
|
const { app } = getAppByCtx(ctx)
|
|
1292
1321
|
|
|
1293
1322
|
const {
|
|
@@ -1297,7 +1326,7 @@ exports.qr_code = async (ctx) => {
|
|
|
1297
1326
|
is_oss = false,
|
|
1298
1327
|
config = 'weixin_mp',
|
|
1299
1328
|
width,
|
|
1300
|
-
} = ctx.request.body
|
|
1329
|
+
} = _data || ctx.request.body
|
|
1301
1330
|
|
|
1302
1331
|
if (!app.service.weixin) throw new Error(`weixin可能没有service.js`)
|
|
1303
1332
|
const result = await app.service.weixin.qr_code({
|
|
@@ -1309,8 +1338,8 @@ exports.qr_code = async (ctx) => {
|
|
|
1309
1338
|
config,
|
|
1310
1339
|
width,
|
|
1311
1340
|
})
|
|
1312
|
-
|
|
1313
|
-
return
|
|
1341
|
+
ctx.SUCCESS(result)
|
|
1342
|
+
return result
|
|
1314
1343
|
}
|
|
1315
1344
|
|
|
1316
1345
|
exports.sendMessage = async (ctx) => {
|
|
@@ -12,6 +12,8 @@ const createUrlschemeUrl =
|
|
|
12
12
|
'https://api.weixin.qq.com/wxa/generatescheme?access_token=%s'
|
|
13
13
|
const createUrlLinkUrl =
|
|
14
14
|
'https://api.weixin.qq.com/wxa/generate_urllink?access_token=%s'
|
|
15
|
+
const queryUrlLinkUrl =
|
|
16
|
+
'https://api.weixin.qq.com/wxa/query_urllink?access_token=%s'
|
|
15
17
|
const createShortLinkUrl =
|
|
16
18
|
'https://api.weixin.qq.com/wxa/genwxashortlink?access_token=%s'
|
|
17
19
|
const sendMessageUrl =
|
|
@@ -374,6 +376,26 @@ module.exports = class Singleton {
|
|
|
374
376
|
return result.url_link
|
|
375
377
|
}
|
|
376
378
|
|
|
379
|
+
async queryUrlLink(url_link) {
|
|
380
|
+
const access_token = await this.getAccessToken()
|
|
381
|
+
const url = util.format(queryUrlLinkUrl, access_token)
|
|
382
|
+
|
|
383
|
+
const result = await axios
|
|
384
|
+
.post(url, {
|
|
385
|
+
url_link,
|
|
386
|
+
})
|
|
387
|
+
.then((res) => res.data)
|
|
388
|
+
|
|
389
|
+
if (result.errcode) {
|
|
390
|
+
if (result.errcode === 40001) {
|
|
391
|
+
cache.reset()
|
|
392
|
+
return await this.queryUrlLink(url_link)
|
|
393
|
+
}
|
|
394
|
+
throw new Error(`${result.errcode};${result.errmsg}`)
|
|
395
|
+
}
|
|
396
|
+
return result.url_link_info
|
|
397
|
+
}
|
|
398
|
+
|
|
377
399
|
async createShortLink(options) {
|
|
378
400
|
const { page, scene, title, ...rest } = options
|
|
379
401
|
const access_token = await this.getAccessToken()
|