q-koa 12.7.0 → 12.7.4
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.
|
@@ -73,27 +73,23 @@ exports.upload = async (ctx) => {
|
|
|
73
73
|
return ctx.SUCCESS(responseData)
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
-
exports.oss_upload = async (ctx) => {
|
|
76
|
+
exports.oss_upload = async (ctx, _data) => {
|
|
77
77
|
const { app } = getAppByCtx(ctx)
|
|
78
78
|
|
|
79
|
-
if (
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
79
|
+
if (!_data) {
|
|
80
|
+
if (
|
|
81
|
+
!(ctx.request.files && ctx.request.files.file) &&
|
|
82
|
+
!(ctx.request.body.url && ctx.request.body.filename)
|
|
83
|
+
) {
|
|
84
|
+
ctx.status = 500
|
|
85
|
+
ctx.ERROR('请选择上传文件')
|
|
86
|
+
}
|
|
85
87
|
}
|
|
86
88
|
|
|
87
89
|
const appConfig = getConfig(app)
|
|
88
90
|
|
|
89
|
-
const {
|
|
90
|
-
|
|
91
|
-
accessKeySecret,
|
|
92
|
-
bucket,
|
|
93
|
-
region,
|
|
94
|
-
cdn_host,
|
|
95
|
-
oss_host,
|
|
96
|
-
} = await appConfig.getObject('oss')
|
|
91
|
+
const { accessKeyId, accessKeySecret, bucket, region, cdn_host, oss_host } =
|
|
92
|
+
await appConfig.getObject('oss')
|
|
97
93
|
|
|
98
94
|
if (!(accessKeyId && accessKeySecret && bucket && region)) {
|
|
99
95
|
throw new Error('没有配置oss设置')
|
|
@@ -108,6 +104,7 @@ exports.oss_upload = async (ctx) => {
|
|
|
108
104
|
})
|
|
109
105
|
let fileName
|
|
110
106
|
let imageData
|
|
107
|
+
|
|
111
108
|
if (ctx.request.files && ctx.request.files.file) {
|
|
112
109
|
const { file } = ctx.request.files
|
|
113
110
|
fileName = `${String(
|
|
@@ -115,32 +112,45 @@ exports.oss_upload = async (ctx) => {
|
|
|
115
112
|
)}.${file.name.split('.')[file.name.split('.').length - 1]}`
|
|
116
113
|
imageData = file.path
|
|
117
114
|
} else {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
115
|
+
if (_data) {
|
|
116
|
+
fileName = _data.fileName
|
|
117
|
+
imageData = _data.buffer
|
|
118
|
+
} else {
|
|
119
|
+
const { url: imageUrl, filename: imageFileName } = ctx.request.body
|
|
120
|
+
fileName = imageFileName
|
|
121
|
+
const formatUrl = imageUrl.startsWith('//')
|
|
122
|
+
? 'http:' + imageUrl
|
|
123
|
+
: imageUrl
|
|
124
|
+
try {
|
|
125
|
+
imageData = await axios
|
|
126
|
+
.get(formatUrl, {
|
|
127
|
+
responseType: 'arraybuffer',
|
|
128
|
+
})
|
|
129
|
+
.then((res) => res.data)
|
|
130
|
+
} catch (e) {
|
|
131
|
+
ctx.status = 500
|
|
132
|
+
ctx.ERROR('请求图片错误')
|
|
133
|
+
}
|
|
130
134
|
}
|
|
131
135
|
}
|
|
132
136
|
const result = await client.put(fileName, imageData)
|
|
133
137
|
if (result.res && result.res.status === 200) {
|
|
134
138
|
if (oss_host && cdn_host) {
|
|
135
139
|
const url = result.url.replace(oss_host, cdn_host)
|
|
136
|
-
|
|
140
|
+
ctx.SUCCESS({
|
|
137
141
|
url,
|
|
138
142
|
})
|
|
143
|
+
return {
|
|
144
|
+
url,
|
|
145
|
+
}
|
|
139
146
|
} else {
|
|
140
147
|
const url = result.url
|
|
141
|
-
|
|
148
|
+
ctx.SUCCESS({
|
|
142
149
|
url,
|
|
143
150
|
})
|
|
151
|
+
return {
|
|
152
|
+
url,
|
|
153
|
+
}
|
|
144
154
|
}
|
|
145
155
|
} else {
|
|
146
156
|
throw new Error(result.res.statusMessage)
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
const axios = require('axios')
|
|
2
|
+
const XLSX = require('xlsx')
|
|
3
|
+
const moment = require('moment')
|
|
4
|
+
|
|
2
5
|
exports.gpt = async ({ content }) => {
|
|
3
6
|
let result = ''
|
|
4
7
|
let messages = [
|
|
@@ -35,3 +38,17 @@ exports.gpt = async ({ content }) => {
|
|
|
35
38
|
|
|
36
39
|
return result
|
|
37
40
|
}
|
|
41
|
+
|
|
42
|
+
exports.formatXLSX = ({ header, data, fileName: _fileName }) => {
|
|
43
|
+
const fileName = `${_fileName || moment().format('YYYYMMDDHHmmss') + ''}.xlsx`
|
|
44
|
+
const workbook = XLSX.utils.book_new()
|
|
45
|
+
const worksheetData = [header, ...data]
|
|
46
|
+
const worksheet = XLSX.utils.aoa_to_sheet(worksheetData)
|
|
47
|
+
XLSX.utils.book_append_sheet(workbook, worksheet, 'Sheet1')
|
|
48
|
+
const buffer = XLSX.write(workbook, { type: 'buffer', bookType: 'xlsx' })
|
|
49
|
+
|
|
50
|
+
return {
|
|
51
|
+
fileName,
|
|
52
|
+
buffer,
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -1215,6 +1215,20 @@ exports.url_link = async (ctx) => {
|
|
|
1215
1215
|
ctx.SUCCESS(result)
|
|
1216
1216
|
}
|
|
1217
1217
|
|
|
1218
|
+
exports.short_link = async (ctx) => {
|
|
1219
|
+
const { app } = getAppByCtx(ctx)
|
|
1220
|
+
|
|
1221
|
+
const { page, scene, config = 'weixin_mp' } = ctx.request.body
|
|
1222
|
+
if (!app.service.weixin) throw new Error(`weixin可能没有service.js`)
|
|
1223
|
+
const result = await app.service.weixin.short_link({
|
|
1224
|
+
app,
|
|
1225
|
+
page,
|
|
1226
|
+
scene,
|
|
1227
|
+
config,
|
|
1228
|
+
})
|
|
1229
|
+
ctx.SUCCESS(result)
|
|
1230
|
+
}
|
|
1231
|
+
|
|
1218
1232
|
exports.url_scheme = async (ctx) => {
|
|
1219
1233
|
const { app } = getAppByCtx(ctx)
|
|
1220
1234
|
|
|
@@ -1513,7 +1527,7 @@ exports.checkPayOnly = async (ctx, _data) => {
|
|
|
1513
1527
|
ctx.SUCCESS({ prefix, out_trade_no, ...payResult })
|
|
1514
1528
|
}
|
|
1515
1529
|
|
|
1516
|
-
exports.checkRefund = async (ctx) => {
|
|
1530
|
+
exports.checkRefund = async (ctx, _data) => {
|
|
1517
1531
|
const { app, appName, controller } = getAppByCtx(ctx)
|
|
1518
1532
|
|
|
1519
1533
|
const {
|
|
@@ -1523,7 +1537,7 @@ exports.checkRefund = async (ctx) => {
|
|
|
1523
1537
|
config = 'weixin_mp',
|
|
1524
1538
|
pay_config = 'weixin_pay',
|
|
1525
1539
|
out_trade_no: _out_trade_no,
|
|
1526
|
-
} = ctx.request.body
|
|
1540
|
+
} = _data || ctx.request.body
|
|
1527
1541
|
|
|
1528
1542
|
const appConfig = getConfig(app)
|
|
1529
1543
|
const { appId, mchId, key, partner_key } = await appConfig.getObject(
|
|
@@ -1562,6 +1576,7 @@ exports.checkRefund = async (ctx) => {
|
|
|
1562
1576
|
})
|
|
1563
1577
|
|
|
1564
1578
|
ctx.SUCCESS(result)
|
|
1579
|
+
return result
|
|
1565
1580
|
}
|
|
1566
1581
|
|
|
1567
1582
|
exports.checkPayNew = async (ctx) => {
|
|
@@ -103,7 +103,6 @@ exports.refund = async ({
|
|
|
103
103
|
}/${appName}/weixin/refund_notify/${pay_config}`,
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
-
console.log(data)
|
|
107
106
|
const { result_code, err_code_des, ...restData } = isPem
|
|
108
107
|
? await wxpay.refund(data)
|
|
109
108
|
: await payObj.refund(data)
|
|
@@ -198,7 +197,6 @@ exports.refundOnly = async ({
|
|
|
198
197
|
out_refund_no,
|
|
199
198
|
}
|
|
200
199
|
|
|
201
|
-
console.log(data)
|
|
202
200
|
const { result_code, err_code_des, ...restData } = (await isPem)
|
|
203
201
|
? await wxpay.refund(data)
|
|
204
202
|
: await payObj.refund(data)
|
|
@@ -452,6 +450,21 @@ exports.url_link = async ({ app, page, scene, config = 'weixin_mp' }) => {
|
|
|
452
450
|
return result
|
|
453
451
|
}
|
|
454
452
|
|
|
453
|
+
exports.short_link = async ({ app, page, scene, config = 'weixin_mp' }) => {
|
|
454
|
+
const appConfig = getConfig(app)
|
|
455
|
+
const { app_id, app_secrect } = await appConfig.getObject(config)
|
|
456
|
+
const weixinMp = new WeixinMp({
|
|
457
|
+
appid: app_id,
|
|
458
|
+
secrect: app_secrect,
|
|
459
|
+
})
|
|
460
|
+
weixinMp.init()
|
|
461
|
+
const result = await weixinMp.createShortLink({
|
|
462
|
+
page,
|
|
463
|
+
scene,
|
|
464
|
+
})
|
|
465
|
+
return result
|
|
466
|
+
}
|
|
467
|
+
|
|
455
468
|
exports.user_enter_tempsession = async ({ app, result }) => {
|
|
456
469
|
console.log('user_enter_tempsession', result)
|
|
457
470
|
}
|
|
@@ -12,6 +12,8 @@ const createUrlschemeUrl =
|
|
|
12
12
|
'https://api.weixin.qq.com/wxa/generatescheme?access_token=%s'
|
|
13
13
|
const createUrlLinkUrl =
|
|
14
14
|
'https://api.weixin.qq.com/wxa/generate_urllink?access_token=%s'
|
|
15
|
+
const createShortLinkUrl =
|
|
16
|
+
'https://api.weixin.qq.com/wxa/genwxashortlink?access_token=%s'
|
|
15
17
|
const sendMessageUrl =
|
|
16
18
|
'https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=%s'
|
|
17
19
|
const handleMessageUrl =
|
|
@@ -367,6 +369,34 @@ module.exports = class Singleton {
|
|
|
367
369
|
return result.url_link
|
|
368
370
|
}
|
|
369
371
|
|
|
372
|
+
async createShortLink(options) {
|
|
373
|
+
const { page, scene, ...rest } = options
|
|
374
|
+
const access_token = await this.getAccessToken()
|
|
375
|
+
const url = util.format(createShortLinkUrl, access_token)
|
|
376
|
+
const query = options.scene
|
|
377
|
+
? Object.keys(options.scene)
|
|
378
|
+
.map((item) => `${item}=${options.scene[item]}`)
|
|
379
|
+
.join('&')
|
|
380
|
+
: ''
|
|
381
|
+
const payLoad = {
|
|
382
|
+
...rest,
|
|
383
|
+
page_url: options.page + (query ? '?' + query : ''),
|
|
384
|
+
page_title: options.page_title,
|
|
385
|
+
is_permanent: true,
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
const result = await axios.post(url, payLoad).then((res) => res.data)
|
|
389
|
+
|
|
390
|
+
if (result.errcode) {
|
|
391
|
+
if (result.errcode === 40001) {
|
|
392
|
+
cache.reset()
|
|
393
|
+
return await this.createShortLink(options)
|
|
394
|
+
}
|
|
395
|
+
throw new Error(`${result.errcode};${result.errmsg}`)
|
|
396
|
+
}
|
|
397
|
+
return result.link
|
|
398
|
+
}
|
|
399
|
+
|
|
370
400
|
async createUrlscheme(options) {
|
|
371
401
|
const { page, scene, ...rest } = options
|
|
372
402
|
const access_token = await this.getAccessToken()
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "q-koa",
|
|
3
|
-
"version": "12.7.
|
|
3
|
+
"version": "12.7.4",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -59,7 +59,8 @@
|
|
|
59
59
|
"sha1": "^1.1.1",
|
|
60
60
|
"redis": "^4.0.3",
|
|
61
61
|
"yly-nodejs-sdk": "^1.0.2",
|
|
62
|
-
"vm2": "^3.9.19"
|
|
62
|
+
"vm2": "^3.9.19",
|
|
63
|
+
"xlsx": "^0.18.5"
|
|
63
64
|
},
|
|
64
65
|
"devDependencies": {
|
|
65
66
|
"eslint": "^4.19.1",
|