q-koa 10.6.9 → 10.7.3
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/file/plugins/log/model.js +11 -5
- package/core/file/plugins/setting/model.js +11 -1
- package/core/file/plugins/toutiao/controller.js +19 -21
- package/core/file/plugins/toutiao/service.js +61 -0
- package/core/file/plugins/weixin/service.js +5 -13
- package/core/file/utils/index.js +36 -2
- package/package.json +1 -1
|
@@ -32,13 +32,15 @@ exports.header = {
|
|
|
32
32
|
}
|
|
33
33
|
},
|
|
34
34
|
get: function () {
|
|
35
|
+
const value = this.getDataValue('header')
|
|
35
36
|
try {
|
|
36
|
-
const value = this.getDataValue('header')
|
|
37
37
|
const dataValue =
|
|
38
38
|
typeof value === 'object' ? value || {} : JSON.parse(value)
|
|
39
39
|
return dataValue
|
|
40
40
|
} catch {
|
|
41
|
-
return {
|
|
41
|
+
return {
|
|
42
|
+
text: value,
|
|
43
|
+
}
|
|
42
44
|
}
|
|
43
45
|
},
|
|
44
46
|
extra: {
|
|
@@ -56,17 +58,21 @@ exports.body = {
|
|
|
56
58
|
const dataValue = typeof value === 'object' ? value : JSON.parse(value)
|
|
57
59
|
this.setDataValue('body', dataValue)
|
|
58
60
|
} catch {
|
|
59
|
-
|
|
61
|
+
this.setDataValue('body', {
|
|
62
|
+
text: value,
|
|
63
|
+
})
|
|
60
64
|
}
|
|
61
65
|
},
|
|
62
66
|
get: function () {
|
|
67
|
+
const value = this.getDataValue('body')
|
|
63
68
|
try {
|
|
64
|
-
const value = this.getDataValue('body')
|
|
65
69
|
const dataValue =
|
|
66
70
|
typeof value === 'object' ? value || {} : JSON.parse(value)
|
|
67
71
|
return dataValue
|
|
68
72
|
} catch {
|
|
69
|
-
return {
|
|
73
|
+
return {
|
|
74
|
+
text: value,
|
|
75
|
+
}
|
|
70
76
|
}
|
|
71
77
|
},
|
|
72
78
|
extra: {
|
|
@@ -29,7 +29,8 @@ exports.type = {
|
|
|
29
29
|
'rich-text',
|
|
30
30
|
'date',
|
|
31
31
|
'datetime',
|
|
32
|
-
'list'
|
|
32
|
+
'list',
|
|
33
|
+
'json'
|
|
33
34
|
),
|
|
34
35
|
comment: 'type类型',
|
|
35
36
|
allowNull: true,
|
|
@@ -50,6 +51,15 @@ exports.value = {
|
|
|
50
51
|
switch (type) {
|
|
51
52
|
case 'switch':
|
|
52
53
|
return Boolean(Number(this.getDataValue('value')))
|
|
54
|
+
case 'json':
|
|
55
|
+
try {
|
|
56
|
+
const value = JSON.parse(this.getDataValue('value'))
|
|
57
|
+
return value
|
|
58
|
+
} catch (e) {
|
|
59
|
+
return {
|
|
60
|
+
text: this.getDataValue('value'),
|
|
61
|
+
}
|
|
62
|
+
}
|
|
53
63
|
case 'list':
|
|
54
64
|
try {
|
|
55
65
|
const value = JSON.parse(this.getDataValue('value'))
|
|
@@ -5,8 +5,7 @@ const axios = require('axios')
|
|
|
5
5
|
const qr = require('qr-image')
|
|
6
6
|
const path = require('path')
|
|
7
7
|
const TOUTIAO = getService('toutiao')
|
|
8
|
-
const
|
|
9
|
-
const utils = require('../../utils')
|
|
8
|
+
const { signResult, hashFn } = require('../../utils')
|
|
10
9
|
|
|
11
10
|
exports.initData = async (ctx) => {
|
|
12
11
|
const { app, appName } = getAppByCtx(ctx)
|
|
@@ -36,7 +35,7 @@ exports.qr_code = async (ctx) => {
|
|
|
36
35
|
const result = await toutiaoService.createQR({
|
|
37
36
|
path: encodeURIComponent(page),
|
|
38
37
|
appname: type,
|
|
39
|
-
filename:
|
|
38
|
+
filename: hashFn(item.key + page + type),
|
|
40
39
|
})
|
|
41
40
|
console.log(`qr,${item.key},${page},${type}`)
|
|
42
41
|
const qr_image = `https://${site_host || 'api.kuashou.com'}/upload/${result}`
|
|
@@ -195,24 +194,6 @@ exports.login = async (ctx) => {
|
|
|
195
194
|
})
|
|
196
195
|
}
|
|
197
196
|
|
|
198
|
-
const signResult = (params, salt) => {
|
|
199
|
-
var skip_arr = ['thirdparty_id', 'app_id', 'sign']
|
|
200
|
-
var paramArray = new Array()
|
|
201
|
-
for (var k in params) {
|
|
202
|
-
if (skip_arr.indexOf(k) != -1) {
|
|
203
|
-
continue
|
|
204
|
-
}
|
|
205
|
-
if (params[k] == '') {
|
|
206
|
-
continue
|
|
207
|
-
}
|
|
208
|
-
paramArray.push(params[k])
|
|
209
|
-
}
|
|
210
|
-
paramArray.push(salt)
|
|
211
|
-
paramArray.sort()
|
|
212
|
-
var signStr = paramArray.join('&')
|
|
213
|
-
return md5(signStr)
|
|
214
|
-
}
|
|
215
|
-
|
|
216
197
|
exports.pay = async (ctx) => {
|
|
217
198
|
const { app, appName } = getAppByCtx(ctx)
|
|
218
199
|
const appConfig = getConfig(app)
|
|
@@ -384,3 +365,20 @@ exports.checkPay = async (ctx) => {
|
|
|
384
365
|
order_id: res.order_id,
|
|
385
366
|
})
|
|
386
367
|
}
|
|
368
|
+
|
|
369
|
+
exports.refund = async (ctx) => {
|
|
370
|
+
const { app, appName } = getAppByCtx(ctx)
|
|
371
|
+
const appConfig = getConfig(app)
|
|
372
|
+
const { id, prefix = '', price, out_trade_no, type } = ctx.request.body
|
|
373
|
+
|
|
374
|
+
if (!app.service.toutiao) throw new Error(`toutiao可能没有service.js`)
|
|
375
|
+
const res = await app.service.toutiao.refund({
|
|
376
|
+
ctx,
|
|
377
|
+
id,
|
|
378
|
+
prefix,
|
|
379
|
+
price,
|
|
380
|
+
out_trade_no,
|
|
381
|
+
type,
|
|
382
|
+
})
|
|
383
|
+
ctx.SUCCESS(res)
|
|
384
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
const { getAppByCtx, getUserByCtx, getConfig } = require('q-koa')
|
|
2
|
+
const axios = require('axios')
|
|
3
|
+
const { signResult } = require('../../utils')
|
|
4
|
+
|
|
5
|
+
exports.refund = async ({
|
|
6
|
+
ctx,
|
|
7
|
+
id,
|
|
8
|
+
prefix = '',
|
|
9
|
+
total_fee,
|
|
10
|
+
refund_fee,
|
|
11
|
+
price,
|
|
12
|
+
out_trade_no: _out_trade_no,
|
|
13
|
+
type = 'TOUTIAO-DOUYIN',
|
|
14
|
+
...rest
|
|
15
|
+
}) => {
|
|
16
|
+
if (!ctx) throw new Error('?ctx')
|
|
17
|
+
const { app, appName } = getAppByCtx(ctx)
|
|
18
|
+
const appConfig = getConfig(app)
|
|
19
|
+
const { app_id, salt, key, is_sandbox } = await appConfig.getObject('toutiao')
|
|
20
|
+
const { site_host } = await appConfig.getObject('base')
|
|
21
|
+
|
|
22
|
+
const orderModel = prefix ? `${prefix}_order` : 'order'
|
|
23
|
+
const out_trade_no = _out_trade_no
|
|
24
|
+
? _out_trade_no
|
|
25
|
+
: prefix
|
|
26
|
+
? `${key}_${prefix}-${id}_${type}`
|
|
27
|
+
: `${key}_${id}_${type}`
|
|
28
|
+
const orderDetail = await app.model[orderModel].findOne({
|
|
29
|
+
where: {
|
|
30
|
+
id,
|
|
31
|
+
},
|
|
32
|
+
})
|
|
33
|
+
if (!orderDetail) throw new Error('不存在该订单')
|
|
34
|
+
|
|
35
|
+
const url = `https://${
|
|
36
|
+
is_sandbox ? 'open-sandbox.douyin.com' : 'developer.toutiao.com'
|
|
37
|
+
}/api/apps/ecpay/v1/create_refund`
|
|
38
|
+
|
|
39
|
+
const data = {
|
|
40
|
+
app_id,
|
|
41
|
+
out_order_no: out_trade_no,
|
|
42
|
+
out_refund_no: `${prefix}-${id}_${type}`,
|
|
43
|
+
reason: rest.remark || '退款',
|
|
44
|
+
refund_amount: Math.round((refund_fee || price) * 100),
|
|
45
|
+
notify_url: `https://${
|
|
46
|
+
site_host || 'api.kuashou.com'
|
|
47
|
+
}/${appName}/toutiao/refund_notify`,
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const res = await axios
|
|
51
|
+
.post(url, {
|
|
52
|
+
...data,
|
|
53
|
+
sign: signResult(data, salt),
|
|
54
|
+
})
|
|
55
|
+
.then((res) => res.data)
|
|
56
|
+
if (res.err_no) {
|
|
57
|
+
throw new Error(res.err_tips)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return res
|
|
61
|
+
}
|
|
@@ -51,29 +51,21 @@ exports.refund = async ({
|
|
|
51
51
|
})
|
|
52
52
|
if (!orderDetail) throw new Error('不存在该订单')
|
|
53
53
|
try {
|
|
54
|
-
const
|
|
54
|
+
const data = {
|
|
55
55
|
...rest,
|
|
56
56
|
out_trade_no,
|
|
57
|
-
out_refund_no: id
|
|
57
|
+
out_refund_no: `${prefix}-${id}_${type}`,
|
|
58
58
|
total_fee: Math.round((total_fee || refund_fee || price) * 100),
|
|
59
59
|
refund_fee: Math.round((refund_fee || price) * 100),
|
|
60
60
|
notify_url: `https://${
|
|
61
61
|
site_host || 'api.kuashou.com'
|
|
62
62
|
}/${appName}/weixin/refund_notify/${pay_config}`,
|
|
63
|
-
}
|
|
63
|
+
}
|
|
64
|
+
const { result_code, err_code_des } = await payObj.refund(data)
|
|
64
65
|
if (result_code === 'SUCCESS') {
|
|
65
66
|
return true
|
|
66
67
|
} else {
|
|
67
|
-
console.error(
|
|
68
|
-
...rest,
|
|
69
|
-
out_trade_no,
|
|
70
|
-
out_refund_no: id + '_' + type,
|
|
71
|
-
total_fee: Math.round((total_fee || refund_fee || price) * 100),
|
|
72
|
-
refund_fee: Math.round((refund_fee || price) * 100),
|
|
73
|
-
notify_url: `https://${
|
|
74
|
-
site_host || 'api.kuashou.com'
|
|
75
|
-
}/${appName}/weixin/refund_notify/${pay_config}`,
|
|
76
|
-
})
|
|
68
|
+
console.error(data)
|
|
77
69
|
throw new Error(err_code_des)
|
|
78
70
|
}
|
|
79
71
|
} catch (e) {
|
package/core/file/utils/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const { lodash } = require('q-koa')
|
|
2
|
+
const md5 = require('md5')
|
|
2
3
|
|
|
3
4
|
const findConfig = (type) => (item) =>
|
|
4
5
|
item.key === type ||
|
|
@@ -17,7 +18,15 @@ exports.getName = (config) => (type) => {
|
|
|
17
18
|
|
|
18
19
|
exports.getList = (config) => (type) => {
|
|
19
20
|
const obj = config.find((i) => i.code === type)
|
|
20
|
-
if (!obj)
|
|
21
|
+
if (!obj) {
|
|
22
|
+
if (process.env.NODE_ENV === 'production') {
|
|
23
|
+
throw new Error(`找不到${type}相关设置`)
|
|
24
|
+
} else {
|
|
25
|
+
console.error(`找不到${type}相关设置`)
|
|
26
|
+
}
|
|
27
|
+
return []
|
|
28
|
+
}
|
|
29
|
+
|
|
21
30
|
const list = config.filter((i) => i.parent_id === obj.id)
|
|
22
31
|
return list
|
|
23
32
|
}
|
|
@@ -71,7 +80,14 @@ exports.getObject = (config, app) => async (type) => {
|
|
|
71
80
|
}
|
|
72
81
|
}
|
|
73
82
|
}
|
|
74
|
-
if (!flag)
|
|
83
|
+
if (!flag) {
|
|
84
|
+
if (process.env.NODE_ENV === 'production') {
|
|
85
|
+
throw new Error(`找不到${type}相关设置`)
|
|
86
|
+
} else {
|
|
87
|
+
console.error(`找不到${type}相关设置`)
|
|
88
|
+
}
|
|
89
|
+
return temObj
|
|
90
|
+
}
|
|
75
91
|
return temObj
|
|
76
92
|
}
|
|
77
93
|
|
|
@@ -169,3 +185,21 @@ exports.getAppConfig = async ({ app, config, key, app_id }) => {
|
|
|
169
185
|
|
|
170
186
|
return target || null
|
|
171
187
|
}
|
|
188
|
+
|
|
189
|
+
exports.signResult = (params, salt) => {
|
|
190
|
+
var skip_arr = ['thirdparty_id', 'app_id', 'sign']
|
|
191
|
+
var paramArray = new Array()
|
|
192
|
+
for (var k in params) {
|
|
193
|
+
if (skip_arr.indexOf(k) != -1) {
|
|
194
|
+
continue
|
|
195
|
+
}
|
|
196
|
+
if (params[k] == '') {
|
|
197
|
+
continue
|
|
198
|
+
}
|
|
199
|
+
paramArray.push(params[k])
|
|
200
|
+
}
|
|
201
|
+
paramArray.push(salt)
|
|
202
|
+
paramArray.sort()
|
|
203
|
+
var signStr = paramArray.join('&')
|
|
204
|
+
return md5(signStr)
|
|
205
|
+
}
|