q-koa 8.1.1 → 8.1.5
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,10 +133,11 @@ 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
|
+
}
|
|
136
140
|
if (this.config.blackList.includes(ip)) {
|
|
137
|
-
if (this.config.log.request) {
|
|
138
|
-
console.log('IP==>', ip)
|
|
139
|
-
}
|
|
140
141
|
return ctx.ERROR('error')
|
|
141
142
|
}
|
|
142
143
|
const appName = url.split('/')[1]
|
|
@@ -254,7 +255,7 @@ class APP {
|
|
|
254
255
|
starter.on('loadAll', async () => {
|
|
255
256
|
const appName = this.config.includes[0]
|
|
256
257
|
this.server = this.app.listen(this.port, () => {
|
|
257
|
-
console.log(
|
|
258
|
+
console.log(`${moment().format('HH:mm:ss')} server is running at http://localhost:${this.port}`)
|
|
258
259
|
console.log(
|
|
259
260
|
`first app is http://localhost:3001/${appName}/setting/findOne`
|
|
260
261
|
)
|
|
@@ -1021,7 +1022,7 @@ class APP {
|
|
|
1021
1022
|
continue
|
|
1022
1023
|
}
|
|
1023
1024
|
const model = myInclude[j].model
|
|
1024
|
-
const modelName = model.getName()
|
|
1025
|
+
const modelName = myInclude[j].as || model.getName()
|
|
1025
1026
|
|
|
1026
1027
|
if (app[appName].attributes[controller][modelName + '_id']) {
|
|
1027
1028
|
const idList = rows
|
|
@@ -1085,7 +1086,7 @@ class APP {
|
|
|
1085
1086
|
continue
|
|
1086
1087
|
}
|
|
1087
1088
|
const model = myInclude[j].model
|
|
1088
|
-
const modelName = model.getName()
|
|
1089
|
+
const modelName = myInclude[j].as || model.getName()
|
|
1089
1090
|
if (
|
|
1090
1091
|
app[appName].attributes[controller][modelName + '_id']
|
|
1091
1092
|
) {
|
|
@@ -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({
|
|
@@ -994,6 +1015,8 @@ exports.qr_code = async (ctx) => {
|
|
|
994
1015
|
accessKeySecret,
|
|
995
1016
|
bucket,
|
|
996
1017
|
region,
|
|
1018
|
+
cdn_host,
|
|
1019
|
+
oss_host,
|
|
997
1020
|
} = await appConfig.getObject('oss')
|
|
998
1021
|
if (!(accessKeyId && accessKeySecret && bucket && region)) {
|
|
999
1022
|
throw new Error('没有配置oss设置')
|
|
@@ -1015,8 +1038,13 @@ exports.qr_code = async (ctx) => {
|
|
|
1015
1038
|
}.png`
|
|
1016
1039
|
const result = await client.put(fileName, buffer)
|
|
1017
1040
|
if (result.res && result.res.status === 200) {
|
|
1018
|
-
|
|
1019
|
-
|
|
1041
|
+
if (oss_host && cdn_host) {
|
|
1042
|
+
const url = result.url.replace(oss_host, cdn_host)
|
|
1043
|
+
return ctx.SUCCESS(url)
|
|
1044
|
+
} else {
|
|
1045
|
+
const url = result.url
|
|
1046
|
+
return ctx.SUCCESS(url)
|
|
1047
|
+
}
|
|
1020
1048
|
} else {
|
|
1021
1049
|
throw new Error(result.res.statusMessage)
|
|
1022
1050
|
}
|
|
@@ -1200,7 +1228,6 @@ exports.checkPay = async (ctx) => {
|
|
|
1200
1228
|
const payResult = await checkOrder({
|
|
1201
1229
|
out_trade_no,
|
|
1202
1230
|
})
|
|
1203
|
-
|
|
1204
1231
|
if (payResult.trade_state_desc === '支付成功') {
|
|
1205
1232
|
const order_price = Number(payResult.total_fee) / 100
|
|
1206
1233
|
await app.service[orderModel].notify({
|