q-koa 8.1.4 → 8.1.7

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,62 +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 = false,
995
+ config = 'weixin_mp',
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
- } = await appConfig.getObject('oss')
1019
- if (!(accessKeyId && accessKeySecret && bucket && region)) {
1020
- throw new Error('没有配置oss设置')
1021
- }
1022
- const buffer = await weixinMp.createQRBuffer({
1023
- page,
1024
- is_hyaline,
1025
- scene,
1026
- })
1027
- const client = new OSS({
1028
- accessKeyId,
1029
- accessKeySecret,
1030
- bucket,
1031
- region,
1032
- secure: true,
1033
- })
1034
- const fileName = `${
1035
- String(new Date().getTime()).split('').reverse().join('') + Math.random()
1036
- }.png`
1037
- const result = await client.put(fileName, buffer)
1038
- if (result.res && result.res.status === 200) {
1039
- const url = result.url
1040
- return ctx.SUCCESS(url)
1041
- } else {
1042
- throw new Error(result.res.statusMessage)
1043
- }
1044
- }
998
+ return ctx.SUCCESS(result)
1045
999
  }
1046
1000
 
1047
1001
  exports.sendMessage = async (ctx) => {
@@ -1221,7 +1175,6 @@ exports.checkPay = async (ctx) => {
1221
1175
  const payResult = await checkOrder({
1222
1176
  out_trade_no,
1223
1177
  })
1224
-
1225
1178
  if (payResult.trade_state_desc === '支付成功') {
1226
1179
  const order_price = Number(payResult.total_fee) / 100
1227
1180
  await app.service[orderModel].notify({
@@ -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.4",
3
+ "version": "8.1.7",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {