q-koa 12.0.4 → 12.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.
@@ -1728,3 +1728,39 @@ exports.setMsgJumpPath = async (ctx) => {
1728
1728
 
1729
1729
  ctx.SUCCESS('ok')
1730
1730
  }
1731
+
1732
+ exports.getUserPortrait = async (ctx) => {
1733
+ const { app, appName } = getAppByCtx(ctx)
1734
+ const appConfig = getConfig(app)
1735
+
1736
+ const { config = 'weixin_mp', type = 'day' } = ctx.request.body
1737
+ const { app_id, app_secrect } = await appConfig.getObject(config)
1738
+
1739
+ const weixinMp = new WeixinMp({
1740
+ appid: app_id,
1741
+ secrect: app_secrect,
1742
+ })
1743
+
1744
+ weixinMp.init()
1745
+
1746
+ let obj = {}
1747
+ if (type === 'day') {
1748
+ obj = {
1749
+ begin_date: moment().add(-1, 'days').format('YYYYMMDD'),
1750
+ end_date: moment().add(-1, 'days').format('YYYYMMDD'),
1751
+ }
1752
+ } else if (type === 'week') {
1753
+ obj = {
1754
+ begin_date: moment().add(-7, 'days').format('YYYYMMDD'),
1755
+ end_date: moment().add(-1, 'days').format('YYYYMMDD'),
1756
+ }
1757
+ } else if (type === 'month') {
1758
+ obj = {
1759
+ begin_date: moment().add(-30, 'days').format('YYYYMMDD'),
1760
+ end_date: moment().add(-1, 'days').format('YYYYMMDD'),
1761
+ }
1762
+ }
1763
+ const result = await weixinMp.getUserPortrait(obj)
1764
+
1765
+ ctx.SUCCESS(result)
1766
+ }
@@ -65,6 +65,9 @@ const setMsgJumpPathUrl =
65
65
  const getDeliveryListUrl =
66
66
  'https://api.weixin.qq.com/cgi-bin/express/delivery/open_msg/get_delivery_list?access_token=%s'
67
67
 
68
+ const getUserPortraitUrl =
69
+ 'https://api.weixin.qq.com/datacube/getweanalysisappiduserportrait?access_token=%s'
70
+
68
71
  const fsPromise = require('fs/promises')
69
72
  const LRU = require('lru-cache')
70
73
  const request = require('request')
@@ -753,6 +756,25 @@ module.exports = class Singleton {
753
756
  return result
754
757
  }
755
758
 
759
+ async getUserPortrait(payLoad) {
760
+ const access_token = await this.getAccessToken()
761
+ const url = util.format(getUserPortraitUrl, access_token)
762
+
763
+ const result = await axios
764
+ .post(url, {
765
+ ...payLoad,
766
+ })
767
+ .then((res) => res.data)
768
+ if (result.errcode) {
769
+ if (result.errcode === 40001) {
770
+ cache.reset()
771
+ return await this.getUserPortrait(payLoad)
772
+ }
773
+ throw new Error(`${result.errcode};${result.errmsg}`)
774
+ }
775
+ return result
776
+ }
777
+
756
778
  getConfig() {
757
779
  return this.config
758
780
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "q-koa",
3
- "version": "12.0.4",
3
+ "version": "12.0.6",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -58,7 +58,8 @@
58
58
  "node-uuid": "^1.4.8",
59
59
  "sha1": "^1.1.1",
60
60
  "redis": "^4.0.3",
61
- "yly-nodejs-sdk": "^1.0.2"
61
+ "yly-nodejs-sdk": "^1.0.2",
62
+ "vm2": "^3.9.19"
62
63
  },
63
64
  "devDependencies": {
64
65
  "eslint": "^4.19.1",