q-koa 8.1.5 → 8.1.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.
@@ -986,69 +986,16 @@ exports.qr_code = async (ctx) => {
986
986
  config = 'weixin_mp',
987
987
  } = ctx.request.body
988
988
 
989
- // if (!lodash.get(ctx.request, `${appName}-user.id`, null)) throw new Error('没有登录')
990
-
991
- const appConfig = getConfig(app)
992
- const { app_id, app_secrect } = await appConfig.getObject(config)
993
-
994
- const { site_host } = await appConfig.getObject('base')
995
- const weixinMp = new WeixinMp({
996
- appid: app_id,
997
- secrect: app_secrect,
998
- targetPath: `${path.resolve(__dirname, `${process.cwd()}/public/upload`)}`,
989
+ const result = await app.service.weixin.qr_code({
990
+ app,
991
+ page,
992
+ is_hyaline,
993
+ scene,
994
+ is_oss,
995
+ config,
999
996
  })
1000
- weixinMp.init()
1001
- if (!is_oss) {
1002
- const result = await weixinMp.createQR({
1003
- page,
1004
- is_hyaline,
1005
- scene,
1006
- })
1007
- const qr_image = `https://${
1008
- site_host || 'api.kuashou.com'
1009
- }/upload/${result}`
1010
997
 
1011
- ctx.SUCCESS(qr_image)
1012
- } else {
1013
- const {
1014
- accessKeyId,
1015
- accessKeySecret,
1016
- bucket,
1017
- region,
1018
- cdn_host,
1019
- oss_host,
1020
- } = await appConfig.getObject('oss')
1021
- if (!(accessKeyId && accessKeySecret && bucket && region)) {
1022
- throw new Error('没有配置oss设置')
1023
- }
1024
- const buffer = await weixinMp.createQRBuffer({
1025
- page,
1026
- is_hyaline,
1027
- scene,
1028
- })
1029
- const client = new OSS({
1030
- accessKeyId,
1031
- accessKeySecret,
1032
- bucket,
1033
- region,
1034
- secure: true,
1035
- })
1036
- const fileName = `${
1037
- String(new Date().getTime()).split('').reverse().join('') + Math.random()
1038
- }.png`
1039
- const result = await client.put(fileName, buffer)
1040
- if (result.res && result.res.status === 200) {
1041
- if (oss_host && cdn_host) {
1042
- const url = result.url.replace(oss_host, cdn_host)
1043
- return ctx.SUCCESS(url)
1044
- } else {
1045
- const url = result.url
1046
- return ctx.SUCCESS(url)
1047
- }
1048
- } else {
1049
- throw new Error(result.res.statusMessage)
1050
- }
1051
- }
998
+ return ctx.SUCCESS(result)
1052
999
  }
1053
1000
 
1054
1001
  exports.sendMessage = async (ctx) => {
@@ -1,8 +1,9 @@
1
1
  const { getAppByCtx, getConfig } = require('q-koa')
2
2
  const { Pay } = require('@sigodenjs/wechatpay')
3
- const fs = require('fs')
4
3
  const path = require('path')
5
4
  const fsPromise = require('fs/promises')
5
+ const WeixinMp = require('../../services/weixinMP')
6
+ const OSS = require('ali-oss')
6
7
 
7
8
  exports.refund = async ({
8
9
  ctx,
@@ -106,3 +107,73 @@ exports.cash = async ({ ctx, id, user_id, number }) => {
106
107
  if (result.err_code_des) throw new Error(result.err_code_des)
107
108
  return result
108
109
  }
110
+ exports.qr_code = async ({
111
+ app,
112
+ page,
113
+ is_hyaline,
114
+ scene,
115
+ is_oss = false,
116
+ config = 'weixin_mp',
117
+ }) => {
118
+ const appConfig = getConfig(app)
119
+ const { app_id, app_secrect } = await appConfig.getObject(config)
120
+
121
+ const { site_host } = await appConfig.getObject('base')
122
+ const weixinMp = new WeixinMp({
123
+ appid: app_id,
124
+ secrect: app_secrect,
125
+ targetPath: `${path.resolve(__dirname, `${process.cwd()}/public/upload`)}`,
126
+ })
127
+ weixinMp.init()
128
+ if (!is_oss) {
129
+ const result = await weixinMp.createQR({
130
+ page,
131
+ is_hyaline,
132
+ scene,
133
+ })
134
+ const qr_image = `https://${
135
+ site_host || 'api.kuashou.com'
136
+ }/upload/${result}`
137
+
138
+ return qr_image
139
+ } else {
140
+ const {
141
+ accessKeyId,
142
+ accessKeySecret,
143
+ bucket,
144
+ region,
145
+ cdn_host,
146
+ oss_host,
147
+ } = await appConfig.getObject('oss')
148
+ if (!(accessKeyId && accessKeySecret && bucket && region)) {
149
+ throw new Error('没有配置oss设置')
150
+ }
151
+ const buffer = await weixinMp.createQRBuffer({
152
+ page,
153
+ is_hyaline,
154
+ scene,
155
+ })
156
+ const client = new OSS({
157
+ accessKeyId,
158
+ accessKeySecret,
159
+ bucket,
160
+ region,
161
+ secure: true,
162
+ })
163
+ const fileName = `${
164
+ String(new Date().getTime()).split('').reverse().join('') + Math.random()
165
+ }.png`
166
+ const result = await client.put(fileName, buffer)
167
+ if (result.res && result.res.status === 200) {
168
+ if (oss_host && cdn_host) {
169
+ const url = result.url.replace(oss_host, cdn_host)
170
+ return url
171
+ } else {
172
+ const url = result.url
173
+ return url
174
+ }
175
+ } else {
176
+ throw new Error(result.res.statusMessage)
177
+ }
178
+ }
179
+ }
@@ -320,7 +320,7 @@ module.exports = class Singleton {
320
320
  if (result.errcode) {
321
321
  if (result.errcode === 40001) {
322
322
  cache.reset()
323
- return await this.getPhoneNumber(code)
323
+ return await this.createUrlLink(options)
324
324
  }
325
325
  throw new Error(`${result.errcode};${result.errmsg}`)
326
326
  }
@@ -348,7 +348,7 @@ module.exports = class Singleton {
348
348
  if (result.errcode) {
349
349
  if (result.errcode === 40001) {
350
350
  cache.reset()
351
- return await this.getPhoneNumber(code)
351
+ return await this.createUrlscheme(options)
352
352
  }
353
353
  throw new Error(`${result.errcode};${result.errmsg}`)
354
354
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "q-koa",
3
- "version": "8.1.5",
3
+ "version": "8.1.8",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {