q-koa 8.0.3 → 8.0.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.
@@ -918,7 +918,25 @@ exports.notify = async (ctx) => {
918
918
  ctx.res.end(returnResult)
919
919
  }
920
920
 
921
- exports.urlScheme = async (ctx) => {
921
+ exports.url_link = async (ctx) => {
922
+ const { app } = getAppByCtx(ctx)
923
+
924
+ const { page, scene, config = 'weixin_mp' } = ctx.request.body
925
+ const appConfig = getConfig(app)
926
+ const { app_id, app_secrect } = await appConfig.getObject(config)
927
+ const weixinMp = new WeixinMp({
928
+ appid: app_id,
929
+ secrect: app_secrect,
930
+ })
931
+ weixinMp.init()
932
+ const result = await weixinMp.createUrlLink({
933
+ page,
934
+ scene,
935
+ })
936
+ ctx.SUCCESS(result)
937
+ }
938
+
939
+ exports.url_scheme = async (ctx) => {
922
940
  const { app } = getAppByCtx(ctx)
923
941
 
924
942
  const { page, scene, config = 'weixin_mp' } = ctx.request.body
@@ -10,6 +10,8 @@ const createQRCodeUrl =
10
10
  'https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=%s'
11
11
  const createUrlschemeUrl =
12
12
  'https://api.weixin.qq.com/wxa/generatescheme?access_token=%s'
13
+ const createUrlLinkUrl =
14
+ 'https://api.weixin.qq.com/wxa/generate_urllink?access_token=%s'
13
15
  const sendMessageUrl =
14
16
  'https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=%s'
15
17
  const handleMessageUrl =
@@ -299,6 +301,32 @@ module.exports = class Singleton {
299
301
  return result.phone_info
300
302
  }
301
303
 
304
+ async createUrlLink(options) {
305
+ const { page, scene, ...rest } = options
306
+ const access_token = await this.getAccessToken()
307
+ const url = util.format(createUrlLinkUrl, access_token)
308
+ const payLoad = {
309
+ ...rest,
310
+ path: options.page,
311
+ query: options.scene
312
+ ? Object.keys(options.scene)
313
+ .map((item) => `${item}=${options.scene[item]}`)
314
+ .join('&')
315
+ : '',
316
+ }
317
+
318
+ const result = await axios.post(url, payLoad).then((res) => res.data)
319
+
320
+ if (result.errcode) {
321
+ if (result.errcode === 40001) {
322
+ cache.reset()
323
+ return await this.getPhoneNumber(code)
324
+ }
325
+ throw new Error(`${result.errcode};${result.errmsg}`)
326
+ }
327
+ return result.url_link
328
+ }
329
+
302
330
  async createUrlscheme(options) {
303
331
  const { page, scene, ...rest } = options
304
332
  const access_token = await this.getAccessToken()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "q-koa",
3
- "version": "8.0.3",
3
+ "version": "8.0.6",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -40,6 +40,7 @@
40
40
  "koa-static": "^5.0.0",
41
41
  "koa-useragent": "^4.0.0",
42
42
  "koa-xml-body": "^2.1.0",
43
+ "koa-proxies": "^0.12.2",
43
44
  "lodash": "^4.17.15",
44
45
  "lru-cache": "^5.1.1",
45
46
  "mockjs": "^1.0.1-beta3",