q-koa 8.1.3 → 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
|
@@ -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({
|