q-koa 10.6.7 → 10.6.9
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/app.js
CHANGED
|
@@ -1987,6 +1987,10 @@ APP.getClientTypeByCtx = (ctx) => {
|
|
|
1987
1987
|
|
|
1988
1988
|
APP.getConfig = (app) => ({
|
|
1989
1989
|
async getObject(type) {
|
|
1990
|
+
if (!type) {
|
|
1991
|
+
console.error(`getObject type : ${type}`)
|
|
1992
|
+
return {}
|
|
1993
|
+
}
|
|
1990
1994
|
let configList = app.cache.get('configList')
|
|
1991
1995
|
if (!configList) {
|
|
1992
1996
|
configList = await app.model.setting.findAll({
|
|
@@ -5,7 +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
|
-
|
|
8
|
+
const md5 = require('md5')
|
|
9
9
|
const utils = require('../../utils')
|
|
10
10
|
|
|
11
11
|
exports.initData = async (ctx) => {
|
|
@@ -194,3 +194,193 @@ exports.login = async (ctx) => {
|
|
|
194
194
|
user: result,
|
|
195
195
|
})
|
|
196
196
|
}
|
|
197
|
+
|
|
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
|
+
exports.pay = async (ctx) => {
|
|
217
|
+
const { app, appName } = getAppByCtx(ctx)
|
|
218
|
+
const appConfig = getConfig(app)
|
|
219
|
+
const { is_dev, site_host } = await appConfig.getObject('base')
|
|
220
|
+
const { app_id, salt, key, is_sandbox, ...rest } = await appConfig.getObject(
|
|
221
|
+
'toutiao'
|
|
222
|
+
)
|
|
223
|
+
|
|
224
|
+
const {
|
|
225
|
+
name,
|
|
226
|
+
out_trade_no: _out_trade_no,
|
|
227
|
+
prefix = '',
|
|
228
|
+
order_id,
|
|
229
|
+
type = 'TOUTIAO-WEIXIN',
|
|
230
|
+
price,
|
|
231
|
+
is_admin = false,
|
|
232
|
+
valid_time = 900,
|
|
233
|
+
} = ctx.request.body
|
|
234
|
+
|
|
235
|
+
const url = `https://${
|
|
236
|
+
is_sandbox ? 'open-sandbox.douyin.com' : 'developer.toutiao.com'
|
|
237
|
+
}/api/apps/ecpay/v1/create_order`
|
|
238
|
+
|
|
239
|
+
const out_order_no = _out_trade_no
|
|
240
|
+
? _out_trade_no
|
|
241
|
+
: prefix
|
|
242
|
+
? `${key.length > 10 ? appName : key}_${prefix}-${order_id}_${type}`
|
|
243
|
+
: `${key.length > 10 ? appName : key}_${order_id}_${type}`
|
|
244
|
+
|
|
245
|
+
const notify_url = `https://${
|
|
246
|
+
site_host || 'api.kuashou.com'
|
|
247
|
+
}/${appName}/toutiao/notify`
|
|
248
|
+
|
|
249
|
+
const data = {
|
|
250
|
+
app_id,
|
|
251
|
+
out_order_no,
|
|
252
|
+
total_amount: is_admin || is_dev ? 1 : Math.round(price * 100),
|
|
253
|
+
subject: name,
|
|
254
|
+
body: `订单【${out_order_no}】`,
|
|
255
|
+
valid_time,
|
|
256
|
+
notify_url,
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
const res = await axios
|
|
260
|
+
.post(url, {
|
|
261
|
+
...data,
|
|
262
|
+
sign: signResult(data, salt),
|
|
263
|
+
})
|
|
264
|
+
.then((res) => res.data)
|
|
265
|
+
|
|
266
|
+
if (res.err_no) {
|
|
267
|
+
throw new Error(res.err_tips)
|
|
268
|
+
}
|
|
269
|
+
ctx.SUCCESS(res.data)
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
exports.notify = async (ctx) => {
|
|
273
|
+
const { app } = getAppByCtx(ctx)
|
|
274
|
+
const { type, msg, nonce, msg_signature, timestamp } = ctx.request.body
|
|
275
|
+
|
|
276
|
+
const {
|
|
277
|
+
appid,
|
|
278
|
+
cp_orderno: out_trade_no,
|
|
279
|
+
cp_extra,
|
|
280
|
+
way,
|
|
281
|
+
channel_no,
|
|
282
|
+
payment_order_no,
|
|
283
|
+
total_amount,
|
|
284
|
+
status,
|
|
285
|
+
item_id,
|
|
286
|
+
seller_uid,
|
|
287
|
+
paid_at,
|
|
288
|
+
order_id: transactionid,
|
|
289
|
+
} = JSON.parse(msg)
|
|
290
|
+
|
|
291
|
+
let order_id = out_trade_no.split('_')[1]
|
|
292
|
+
const order_price = Number(total_amount) / 100
|
|
293
|
+
let prefix = ''
|
|
294
|
+
if (order_id.includes('-')) {
|
|
295
|
+
const arr = order_id.split('-')
|
|
296
|
+
order_id = Number(arr[1])
|
|
297
|
+
;[prefix] = arr
|
|
298
|
+
} else {
|
|
299
|
+
order_id = Number(order_id)
|
|
300
|
+
}
|
|
301
|
+
const model = prefix ? `${prefix}_order` : 'order'
|
|
302
|
+
let openid = ''
|
|
303
|
+
|
|
304
|
+
console.log(order_id, '微信支付回调-----', model, order_price, transactionid)
|
|
305
|
+
if (app.service[model] && app.service[model].notify) {
|
|
306
|
+
await app.service[model].notify({
|
|
307
|
+
app,
|
|
308
|
+
order_id,
|
|
309
|
+
order: model,
|
|
310
|
+
order_price,
|
|
311
|
+
transactionid,
|
|
312
|
+
out_trade_no,
|
|
313
|
+
openid,
|
|
314
|
+
})
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
ctx.status = 200
|
|
318
|
+
ctx.body = {
|
|
319
|
+
err_no: 0,
|
|
320
|
+
err_tips: 'success',
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
exports.checkPay = async (ctx) => {
|
|
325
|
+
const { app, appName } = getAppByCtx(ctx)
|
|
326
|
+
|
|
327
|
+
const {
|
|
328
|
+
id,
|
|
329
|
+
prefix,
|
|
330
|
+
type = 'TOUTIAO-DOUYIN',
|
|
331
|
+
out_trade_no: _out_trade_no,
|
|
332
|
+
} = ctx.request.body
|
|
333
|
+
|
|
334
|
+
const orderModel = prefix ? `${prefix}_order` : 'order'
|
|
335
|
+
const result = await app.model[orderModel].findOne({
|
|
336
|
+
where: {
|
|
337
|
+
id,
|
|
338
|
+
},
|
|
339
|
+
})
|
|
340
|
+
if (!result) return ctx.SUCCESS('找不到')
|
|
341
|
+
|
|
342
|
+
const appConfig = getConfig(app)
|
|
343
|
+
const { is_dev, site_host } = await appConfig.getObject('base')
|
|
344
|
+
const { app_id, salt, key, is_sandbox, ...rest } = await appConfig.getObject(
|
|
345
|
+
'toutiao'
|
|
346
|
+
)
|
|
347
|
+
|
|
348
|
+
const orderPrefix = prefix ? `${prefix}-` : ''
|
|
349
|
+
const out_trade_no = _out_trade_no
|
|
350
|
+
? _out_trade_no
|
|
351
|
+
: `${key}_${orderPrefix}${id}_${type}`
|
|
352
|
+
|
|
353
|
+
const url = `https://${
|
|
354
|
+
is_sandbox ? 'open-sandbox.douyin.com' : 'developer.toutiao.com'
|
|
355
|
+
}/api/apps/ecpay/v1/query_order`
|
|
356
|
+
|
|
357
|
+
const data = {
|
|
358
|
+
app_id,
|
|
359
|
+
out_order_no: out_trade_no,
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
const res = await axios
|
|
363
|
+
.post(url, {
|
|
364
|
+
...data,
|
|
365
|
+
sign: signResult(data, salt),
|
|
366
|
+
})
|
|
367
|
+
.then((res) => res.data)
|
|
368
|
+
|
|
369
|
+
if (res.err_no) {
|
|
370
|
+
throw new Error(res.err_tips)
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
const order_price = Number(res.payment_info.total_fee) / 100
|
|
374
|
+
await app.service[orderModel].notify({
|
|
375
|
+
app,
|
|
376
|
+
order: orderModel,
|
|
377
|
+
order_id: id,
|
|
378
|
+
order_price,
|
|
379
|
+
transactionid: res.order_id,
|
|
380
|
+
out_trade_no: res.out_trade_no,
|
|
381
|
+
})
|
|
382
|
+
ctx.SUCCESS({
|
|
383
|
+
...res.payment_info,
|
|
384
|
+
order_id: res.order_id,
|
|
385
|
+
})
|
|
386
|
+
}
|
|
@@ -7,8 +7,6 @@ exports.login = async (ctx) => {
|
|
|
7
7
|
const { mobile, password, config: _config, ...rest } = ctx.request.body
|
|
8
8
|
|
|
9
9
|
const config = _config || ctx.request.header.config || 'weixin_mp'
|
|
10
|
-
const appConfig = getConfig(app)
|
|
11
|
-
const { app_id } = await appConfig.getObject(config)
|
|
12
10
|
|
|
13
11
|
const where =
|
|
14
12
|
process.env.NODE_ENV !== 'production'
|
|
@@ -36,6 +34,22 @@ exports.login = async (ctx) => {
|
|
|
36
34
|
where,
|
|
37
35
|
})
|
|
38
36
|
if (!result) throw new Error('账号密码错误')
|
|
37
|
+
if (_config === 'none') {
|
|
38
|
+
const tokenResult = {
|
|
39
|
+
id: result.id,
|
|
40
|
+
name: result.name,
|
|
41
|
+
mobile: result.mobile,
|
|
42
|
+
}
|
|
43
|
+
const token = await app.sign({
|
|
44
|
+
user: tokenResult,
|
|
45
|
+
})
|
|
46
|
+
return ctx.SUCCESS({
|
|
47
|
+
token,
|
|
48
|
+
user: app.appConfig.loginData
|
|
49
|
+
? lodash.omit(result.toJSON(), app.appConfig.loginData.omit)
|
|
50
|
+
: result,
|
|
51
|
+
})
|
|
52
|
+
}
|
|
39
53
|
if (
|
|
40
54
|
ctx.request[`${appName}-user`] &&
|
|
41
55
|
ctx.request[`${appName}-user`].mp_user
|
|
@@ -89,6 +103,8 @@ exports.login = async (ctx) => {
|
|
|
89
103
|
}
|
|
90
104
|
)
|
|
91
105
|
}
|
|
106
|
+
const appConfig = getConfig(app)
|
|
107
|
+
const { app_id } = await appConfig.getObject(config)
|
|
92
108
|
/**
|
|
93
109
|
* 查出最新用户,存token并返回
|
|
94
110
|
*/
|
|
@@ -115,18 +131,20 @@ exports.login = async (ctx) => {
|
|
|
115
131
|
: {
|
|
116
132
|
model: app.model.mp_user,
|
|
117
133
|
}
|
|
118
|
-
const includeDefault =
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
134
|
+
const includeDefault =
|
|
135
|
+
config !== 'none'
|
|
136
|
+
? [
|
|
137
|
+
{
|
|
138
|
+
model: app.model.github_user,
|
|
139
|
+
},
|
|
140
|
+
h5_user_include,
|
|
141
|
+
mp_user_include,
|
|
142
|
+
{
|
|
143
|
+
model: app.model.toutiao_user,
|
|
144
|
+
},
|
|
145
|
+
...app.include.user,
|
|
146
|
+
].filter((item) => item.model)
|
|
147
|
+
: []
|
|
130
148
|
if (app.appConfig.loginData) {
|
|
131
149
|
const include = includeDefault.filter((i) => {
|
|
132
150
|
return app.appConfig.loginData.excludeInclude.every((m) => {
|