q-koa 8.1.3 → 8.1.6
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
|
@@ -255,7 +255,7 @@ class APP {
|
|
|
255
255
|
starter.on('loadAll', async () => {
|
|
256
256
|
const appName = this.config.includes[0]
|
|
257
257
|
this.server = this.app.listen(this.port, () => {
|
|
258
|
-
console.log(
|
|
258
|
+
console.log(`${moment().format('HH:mm:ss')} server is running at http://localhost:${this.port}`)
|
|
259
259
|
console.log(
|
|
260
260
|
`first app is http://localhost:3001/${appName}/setting/findOne`
|
|
261
261
|
)
|
|
@@ -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
|
+
}
|
|
@@ -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({
|
|
@@ -320,7 +320,7 @@ module.exports = class Singleton {
|
|
|
320
320
|
if (result.errcode) {
|
|
321
321
|
if (result.errcode === 40001) {
|
|
322
322
|
cache.reset()
|
|
323
|
-
return await this.
|
|
323
|
+
return await this.createUrlLink(options)
|
|
324
324
|
}
|
|
325
325
|
throw new Error(`${result.errcode};${result.errmsg}`)
|
|
326
326
|
}
|
|
@@ -348,7 +348,7 @@ module.exports = class Singleton {
|
|
|
348
348
|
if (result.errcode) {
|
|
349
349
|
if (result.errcode === 40001) {
|
|
350
350
|
cache.reset()
|
|
351
|
-
return await this.
|
|
351
|
+
return await this.createUrlscheme(options)
|
|
352
352
|
}
|
|
353
353
|
throw new Error(`${result.errcode};${result.errmsg}`)
|
|
354
354
|
}
|