q-koa 8.1.0 → 8.1.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.
package/core/app.js
CHANGED
|
@@ -133,6 +133,13 @@ class APP {
|
|
|
133
133
|
this.app.use(async (ctx, next) => {
|
|
134
134
|
const verify = util.promisify(jwt.verify)
|
|
135
135
|
const { url, host, ip, method } = ctx.request
|
|
136
|
+
|
|
137
|
+
if (ctx.request.header['user-agent'].startsWith('Tencent Security')) {
|
|
138
|
+
return ctx.ERROR('error')
|
|
139
|
+
}
|
|
140
|
+
if (this.config.blackList.includes(ip)) {
|
|
141
|
+
return ctx.ERROR('error')
|
|
142
|
+
}
|
|
136
143
|
const appName = url.split('/')[1]
|
|
137
144
|
const { secret, whiteList, _whiteList, tokenKey, expiresIn } =
|
|
138
145
|
ctx.app[appName] && ctx.app[appName].appConfig
|
|
@@ -248,7 +255,7 @@ class APP {
|
|
|
248
255
|
starter.on('loadAll', async () => {
|
|
249
256
|
const appName = this.config.includes[0]
|
|
250
257
|
this.server = this.app.listen(this.port, () => {
|
|
251
|
-
console.log(
|
|
258
|
+
console.log(`${moment().format('HH:mm:ss')} server is running at http://localhost:${this.port}`)
|
|
252
259
|
console.log(
|
|
253
260
|
`first app is http://localhost:3001/${appName}/setting/findOne`
|
|
254
261
|
)
|
|
@@ -1015,7 +1022,7 @@ class APP {
|
|
|
1015
1022
|
continue
|
|
1016
1023
|
}
|
|
1017
1024
|
const model = myInclude[j].model
|
|
1018
|
-
const modelName = model.getName()
|
|
1025
|
+
const modelName = myInclude[j].as || model.getName()
|
|
1019
1026
|
|
|
1020
1027
|
if (app[appName].attributes[controller][modelName + '_id']) {
|
|
1021
1028
|
const idList = rows
|
|
@@ -1079,7 +1086,7 @@ class APP {
|
|
|
1079
1086
|
continue
|
|
1080
1087
|
}
|
|
1081
1088
|
const model = myInclude[j].model
|
|
1082
|
-
const modelName = model.getName()
|
|
1089
|
+
const modelName = myInclude[j].as || model.getName()
|
|
1083
1090
|
if (
|
|
1084
1091
|
app[appName].attributes[controller][modelName + '_id']
|
|
1085
1092
|
) {
|
package/core/config.js
CHANGED
|
@@ -12,6 +12,7 @@ const jwt = require('jsonwebtoken')
|
|
|
12
12
|
|
|
13
13
|
const Email = require('../../services/email')
|
|
14
14
|
const Geo = require('../../services/geo')
|
|
15
|
+
const Express = require('../../services/express')
|
|
15
16
|
|
|
16
17
|
const annotationsReg = /(?:^|\n|\r)\s*\/\*[\s\S]*?\*\/\s*(?:\r|\n|$)/g
|
|
17
18
|
const apiReg = /@api(Name|Desc|Param|Route|Return)(\s+)(.*)\n/g
|
|
@@ -400,3 +401,21 @@ exports.verify = async (ctx) => {
|
|
|
400
401
|
const result = await verify(code, 'token')
|
|
401
402
|
ctx.SUCCESS(result)
|
|
402
403
|
}
|
|
404
|
+
|
|
405
|
+
exports.express = async (ctx) => {
|
|
406
|
+
const { app } = getAppByCtx(ctx)
|
|
407
|
+
const appConfig = getConfig(app)
|
|
408
|
+
const { app_code } = await appConfig.getObject('express')
|
|
409
|
+
|
|
410
|
+
const express = new Express({
|
|
411
|
+
app_code,
|
|
412
|
+
})
|
|
413
|
+
|
|
414
|
+
const { id, express_number } = ctx.request.body
|
|
415
|
+
|
|
416
|
+
const result = await express.send({
|
|
417
|
+
no: express_number,
|
|
418
|
+
})
|
|
419
|
+
|
|
420
|
+
ctx.SUCCESS(result)
|
|
421
|
+
}
|
|
@@ -223,7 +223,7 @@ exports.initData = async ({ includes, excludes, app, ctx }) => {
|
|
|
223
223
|
setting: obj.setting.map((i) => {
|
|
224
224
|
if (i.code === 'is_check' && i.value === false) {
|
|
225
225
|
return {
|
|
226
|
-
...i.toJSON(),
|
|
226
|
+
...(i.toJSON ? i.toJSON() : i),
|
|
227
227
|
value: apiVersion === cacheVersion,
|
|
228
228
|
}
|
|
229
229
|
}
|
|
@@ -780,7 +780,7 @@ exports.mp_pay = async (ctx) => {
|
|
|
780
780
|
return_url,
|
|
781
781
|
prefix = '',
|
|
782
782
|
type,
|
|
783
|
-
out_trade_no,
|
|
783
|
+
out_trade_no: _out_trade_no,
|
|
784
784
|
is_admin = false,
|
|
785
785
|
config = 'weixin_mp',
|
|
786
786
|
pay_config = 'weixin_pay',
|
|
@@ -829,22 +829,18 @@ exports.mp_pay = async (ctx) => {
|
|
|
829
829
|
type === 'H5-WEIXIN'
|
|
830
830
|
? ctx.request[`${appName}-user`].h5_user
|
|
831
831
|
: ctx.request[`${appName}-user`].mp_user
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
832
|
+
|
|
833
|
+
const out_trade_no = _out_trade_no
|
|
834
|
+
? _out_trade_no
|
|
835
|
+
: prefix
|
|
836
|
+
? `${appName}_${prefix}-${order_id}_${type}`
|
|
837
|
+
: `${appName}_${order_id}_${type}`
|
|
838
|
+
|
|
839
|
+
const prePayResult = await pay({
|
|
840
840
|
openid: userDetail.openid,
|
|
841
841
|
body: name,
|
|
842
842
|
detail: '公众号支付测试',
|
|
843
|
-
out_trade_no
|
|
844
|
-
? out_trade_no
|
|
845
|
-
: prefix
|
|
846
|
-
? `${appName}_${prefix}-${order_id}_${type}`
|
|
847
|
-
: `${appName}_${order_id}_${type}`,
|
|
843
|
+
out_trade_no,
|
|
848
844
|
total_fee: is_admin || is_dev ? 1 : Math.round(price * 100),
|
|
849
845
|
spbill_create_ip: '192.168.2.210',
|
|
850
846
|
notify_url: `http://${
|
|
@@ -852,6 +848,24 @@ exports.mp_pay = async (ctx) => {
|
|
|
852
848
|
}/${appName}/weixin/notify`,
|
|
853
849
|
})
|
|
854
850
|
|
|
851
|
+
const checkOrder = (obj) => {
|
|
852
|
+
return new Promise((resolve, reject) => {
|
|
853
|
+
wxpay.queryOrder(obj, function (err, order) {
|
|
854
|
+
if (err) throw new Error(err)
|
|
855
|
+
resolve(order)
|
|
856
|
+
})
|
|
857
|
+
})
|
|
858
|
+
}
|
|
859
|
+
|
|
860
|
+
const {
|
|
861
|
+
appId: appid,
|
|
862
|
+
nonceStr: nonce_str,
|
|
863
|
+
package: prepay_id,
|
|
864
|
+
paySign: sign,
|
|
865
|
+
signType,
|
|
866
|
+
timeStamp,
|
|
867
|
+
} = prePayResult
|
|
868
|
+
|
|
855
869
|
if (prepay_id.includes('undefined')) {
|
|
856
870
|
const model = type === 'H5-WEIXIN' ? 'h5_user' : 'mp_user'
|
|
857
871
|
const userTarget = await app.model[model].findOne({
|
|
@@ -863,6 +877,13 @@ exports.mp_pay = async (ctx) => {
|
|
|
863
877
|
throw new Error(
|
|
864
878
|
`appid不符,用户appid${userTarget.appid},付款appid${app_id}`
|
|
865
879
|
)
|
|
880
|
+
|
|
881
|
+
const payResult = await checkOrder({
|
|
882
|
+
out_trade_no,
|
|
883
|
+
})
|
|
884
|
+
if (payResult.trade_state_desc === '支付成功') {
|
|
885
|
+
return ctx.SUCCESS('ok')
|
|
886
|
+
}
|
|
866
887
|
throw new Error(`支付失败,请重试`)
|
|
867
888
|
}
|
|
868
889
|
return ctx.SUCCESS({
|