q-koa 12.5.6 → 12.5.8

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/config.js CHANGED
@@ -107,7 +107,7 @@ module.exports = {
107
107
  jwt: {
108
108
  secret: 'token',
109
109
  tokenKey: 'token',
110
- expiresIn: '60480000',
110
+ expiresIn: '172800000',
111
111
  whiteList: [], // 应用覆盖
112
112
  _whiteList: [
113
113
  '/',
@@ -1,5 +1,4 @@
1
- const { Sequelize, Random } = require('q-koa');
2
-
1
+ const { Sequelize, Random } = require('q-koa')
3
2
 
4
3
  exports.name = {
5
4
  type: Sequelize.STRING,
@@ -31,7 +30,7 @@ exports.desc = {
31
30
  defaultValue: '',
32
31
  sortOrder: 3,
33
32
  mock: () => Random.csentence(),
34
- extra: {"type":"markdown"},
33
+ extra: { type: 'markdown' },
35
34
  }
36
35
 
37
36
  exports.role_id = {
@@ -54,7 +53,6 @@ exports.sortOrder = {
54
53
  is_mock: false,
55
54
  defaultValue: 0,
56
55
  sortOrder: 5,
57
-
58
56
  }
59
57
 
60
58
  exports.is_on = {
@@ -65,5 +63,36 @@ exports.is_on = {
65
63
  defaultValue: true,
66
64
  sortOrder: 6,
67
65
  mock: () => Random.boolean(),
68
- extra: {"controlInline":true},
66
+ extra: { controlInline: true },
67
+ }
68
+
69
+ exports.extra = {
70
+ type: Sequelize.JSON,
71
+ comment: '额外数据',
72
+ allowNull: true,
73
+ is_mock: false,
74
+ defaultValue: {},
75
+ sortOrder: 7,
76
+ set: function (value) {
77
+ try {
78
+ const dataValue = typeof value === 'object' ? value : JSON.parse(value)
79
+ this.setDataValue('extra', dataValue)
80
+ } catch {
81
+ throw new Error('extra值不合法')
82
+ }
83
+ },
84
+ get: function () {
85
+ const value = this.getDataValue('extra')
86
+ try {
87
+ const dataValue =
88
+ typeof value === 'object' ? value || {} : JSON.parse(value)
89
+
90
+ return dataValue
91
+ } catch {
92
+ return {
93
+ text: value,
94
+ }
95
+ }
96
+ },
97
+ extra: { type: 'json-editor' },
69
98
  }
@@ -4,7 +4,7 @@ const fsPromise = require('fs/promises')
4
4
  const { VM } = require('vm2')
5
5
  const axios = require('axios')
6
6
  const cheerio = require('cheerio')
7
- const { lodash, getAppByCtx, getConfig, Sequelize } = require('q-koa')
7
+ const { lodash, getAppByCtx, getConfig, Sequelize, moment } = require('q-koa')
8
8
  const LRU = require('lru-cache')
9
9
  const cache = new LRU({
10
10
  max: 10,
@@ -687,6 +687,11 @@ exports.mockPay = async (ctx) => {
687
687
  order: model,
688
688
  order_price,
689
689
  ...rest,
690
+ ...(rest.transactionid
691
+ ? {}
692
+ : {
693
+ transactionid: moment().valueOf() + '',
694
+ }),
690
695
  })
691
696
  ctx.SUCCESS('ok')
692
697
  }
@@ -1864,3 +1864,46 @@ exports.getVisitTrend = async (ctx) => {
1864
1864
  await app.model.weixin_visit.create(result.list[0])
1865
1865
  ctx.SUCCESS(result)
1866
1866
  }
1867
+
1868
+ exports.getCommentInfo = async (ctx, _data) => {
1869
+ const { app, appName } = getAppByCtx(ctx)
1870
+ const user_id = getUserByCtx(ctx)
1871
+ const appConfig = getConfig(app)
1872
+ const { is_dev } = await appConfig.getObject('base')
1873
+ const { comment_id } = _data || ctx.request.body
1874
+
1875
+ if (!comment_id) throw new ServiceError('comment_id?')
1876
+
1877
+ const { app_id, app_secrect } = await appConfig.getObject('weixin_mp')
1878
+
1879
+ const weixinMp = new WeixinMp({
1880
+ appid: app_id,
1881
+ secrect: app_secrect,
1882
+ })
1883
+ weixinMp.init()
1884
+
1885
+ const { info } = await weixinMp.getCommentInfo(comment_id)
1886
+
1887
+ const {
1888
+ content: {
1889
+ orderInfo: { busiOrderId },
1890
+ },
1891
+ } = info
1892
+
1893
+ let prefix = ''
1894
+ let order_id = busiOrderId.split('_')[1]
1895
+ if (order_id.includes('-')) {
1896
+ const arr = order_id.split('-')
1897
+ order_id = Number(arr[1])
1898
+ ;[prefix] = arr
1899
+ } else {
1900
+ order_id = Number(order_id)
1901
+ }
1902
+
1903
+ const result = {
1904
+ prefix,
1905
+ order_id,
1906
+ }
1907
+ ctx.SUCCESS(result)
1908
+ return result
1909
+ }
@@ -68,6 +68,9 @@ const getDeliveryListUrl =
68
68
  const getUserPortraitUrl =
69
69
  'https://api.weixin.qq.com/datacube/getweanalysisappiduserportrait?access_token=%s'
70
70
 
71
+ const getCommentInfoUrl =
72
+ 'https://api.weixin.qq.com/wxaapi/comment/commentinfo/get?commentId=%s&access_token=%s'
73
+
71
74
  const fsPromise = require('fs/promises')
72
75
  const LRU = require('lru-cache')
73
76
  const request = require('request')
@@ -813,6 +816,24 @@ module.exports = class Singleton {
813
816
  return result
814
817
  }
815
818
 
819
+ async getCommentInfo(commentId) {
820
+ const access_token = await this.getAccessToken()
821
+ const url = util.format(getCommentInfoUrl, commentId, access_token)
822
+
823
+ const result = await axios.get(url).then((res) => res.data)
824
+ if (result.errcode) {
825
+ if (result.errcode === 40001) {
826
+ cache.reset()
827
+ return await this.getCommentInfo(commentId)
828
+ }
829
+ if (result.errcode === 61503) {
830
+ return null
831
+ }
832
+ throw new Error(`${result.errcode};${result.errmsg}`)
833
+ }
834
+ return result
835
+ }
836
+
816
837
  getConfig() {
817
838
  return this.config
818
839
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "q-koa",
3
- "version": "12.5.6",
3
+ "version": "12.5.8",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {