q-koa 10.3.0 → 10.4.2
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.
|
@@ -838,7 +838,6 @@ exports.pc_pay = async (ctx) => {
|
|
|
838
838
|
order_id,
|
|
839
839
|
price,
|
|
840
840
|
prefix = '',
|
|
841
|
-
type = 'PC-WEIXIN',
|
|
842
841
|
out_trade_no: _out_trade_no,
|
|
843
842
|
is_admin = false,
|
|
844
843
|
config = 'weixin_mp',
|
|
@@ -846,77 +845,8 @@ exports.pc_pay = async (ctx) => {
|
|
|
846
845
|
} = ctx.request.body
|
|
847
846
|
|
|
848
847
|
if (price === 0) throw new Error('价格不能为0')
|
|
849
|
-
|
|
850
|
-
const appConfig = getConfig(app)
|
|
851
|
-
|
|
852
|
-
const { mchId, key, partner_key } = await appConfig.getObject(pay_config)
|
|
853
|
-
|
|
854
|
-
const { is_dev, site_host } = await appConfig.getObject('base')
|
|
855
|
-
// 公众号支付用 服务号 appid,其他用小程序 appid
|
|
856
|
-
const app_id = (await appConfig.getObject(config)).app_id
|
|
857
|
-
|
|
858
|
-
const wxpay = WXPay({
|
|
859
|
-
appid: app_id,
|
|
860
|
-
mch_id: mchId,
|
|
861
|
-
partner_key: key.length > 10 ? key : partner_key, // 微信商户平台API密钥
|
|
862
|
-
})
|
|
863
|
-
|
|
864
|
-
const pay = (options) =>
|
|
865
|
-
new Promise((resolve, reject) => {
|
|
866
|
-
wxpay.createUnifiedOrder(options, (err, result) => {
|
|
867
|
-
if (err) return reject(err)
|
|
868
|
-
return resolve(result)
|
|
869
|
-
})
|
|
870
|
-
})
|
|
871
|
-
|
|
872
|
-
const out_trade_no = _out_trade_no
|
|
873
|
-
? _out_trade_no
|
|
874
|
-
: prefix
|
|
875
|
-
? `${key.length > 10 ? appName : key}_${prefix}-${order_id}_${type}`
|
|
876
|
-
: `${key.length > 10 ? appName : key}_${order_id}_${type}`
|
|
877
|
-
|
|
878
|
-
const notify_url = `https://${
|
|
879
|
-
site_host || 'api.kuashou.com'
|
|
880
|
-
}/${appName}/weixin/notify`
|
|
881
|
-
|
|
882
|
-
const result = await pay({
|
|
883
|
-
body: name,
|
|
884
|
-
detail: '公众号支付测试',
|
|
885
|
-
out_trade_no,
|
|
886
|
-
trade_type: 'NATIVE',
|
|
887
|
-
total_fee: is_admin || is_dev ? 1 : Math.round(price * 100),
|
|
888
|
-
spbill_create_ip: '192.168.2.210',
|
|
889
|
-
notify_url,
|
|
890
|
-
})
|
|
891
|
-
|
|
892
|
-
if (result.result_code === 'FAIL') throw new Error(result.err_code_des)
|
|
893
|
-
|
|
894
|
-
return ctx.SUCCESS(
|
|
895
|
-
`https://${site_host || 'api.kuashou.com'}/${appName}/common/createQr?url=${
|
|
896
|
-
result.code_url
|
|
897
|
-
}`
|
|
898
|
-
)
|
|
899
|
-
}
|
|
900
|
-
|
|
901
|
-
exports.pc_pay = async (ctx) => {
|
|
902
|
-
const { app, appName } = getAppByCtx(ctx)
|
|
903
|
-
const {
|
|
904
|
-
name,
|
|
905
|
-
order_id,
|
|
906
|
-
price,
|
|
907
|
-
prefix = '',
|
|
908
|
-
out_trade_no: _out_trade_no,
|
|
909
|
-
is_admin = false,
|
|
910
|
-
config = 'weixin_mp',
|
|
911
|
-
pay_config = 'weixin_pay',
|
|
912
|
-
} = ctx.request.body
|
|
913
|
-
|
|
914
|
-
if (price === 0) throw new Error('价格不能为0')
|
|
915
|
-
|
|
916
|
-
if (!app.service.weixin) throw new Error(`weixin可能没有service.js`)
|
|
917
848
|
const result = await app.service.weixin.pc_pay({
|
|
918
|
-
|
|
919
|
-
appName,
|
|
849
|
+
ctx,
|
|
920
850
|
name,
|
|
921
851
|
order_id,
|
|
922
852
|
price,
|
|
@@ -1147,7 +1077,9 @@ exports.notify = async (ctx) => {
|
|
|
1147
1077
|
}
|
|
1148
1078
|
const model = prefix ? `${prefix}_order` : 'order'
|
|
1149
1079
|
let transactionid = ''
|
|
1080
|
+
let openid = ''
|
|
1150
1081
|
try {
|
|
1082
|
+
openid = result.xml.openid
|
|
1151
1083
|
transactionid = result.xml.transaction_id
|
|
1152
1084
|
} catch (e) {}
|
|
1153
1085
|
|
|
@@ -1160,6 +1092,7 @@ exports.notify = async (ctx) => {
|
|
|
1160
1092
|
order_price,
|
|
1161
1093
|
transactionid,
|
|
1162
1094
|
out_trade_no: result.xml.out_trade_no,
|
|
1095
|
+
openid,
|
|
1163
1096
|
})
|
|
1164
1097
|
}
|
|
1165
1098
|
|
|
@@ -444,25 +444,26 @@ exports.funds_order_refund = async ({ app, result }) => {
|
|
|
444
444
|
}
|
|
445
445
|
|
|
446
446
|
exports.pc_pay = async ({
|
|
447
|
-
|
|
448
|
-
appName,
|
|
447
|
+
ctx,
|
|
449
448
|
name,
|
|
450
449
|
order_id,
|
|
451
450
|
price,
|
|
452
|
-
config,
|
|
453
|
-
pay_config,
|
|
451
|
+
config = 'weixin_mp',
|
|
452
|
+
pay_config = 'weixin_pay',
|
|
454
453
|
out_trade_no: _out_trade_no,
|
|
455
|
-
is_admin,
|
|
454
|
+
is_admin = false,
|
|
456
455
|
type = 'PC-WEIXIN',
|
|
457
|
-
prefix,
|
|
456
|
+
prefix = '',
|
|
458
457
|
}) => {
|
|
458
|
+
if (!order_id) throw new Error('缺order_id')
|
|
459
|
+
if (!price) throw new Error('缺price')
|
|
460
|
+
if (!name) throw new Error('缺name')
|
|
461
|
+
const { app, appName } = getAppByCtx(ctx)
|
|
459
462
|
const appConfig = getConfig(app)
|
|
460
|
-
|
|
463
|
+
const app_id = (await appConfig.getObject(config)).app_id
|
|
461
464
|
const { mchId, key, partner_key } = await appConfig.getObject(pay_config)
|
|
462
465
|
|
|
463
466
|
const { is_dev, site_host } = await appConfig.getObject('base')
|
|
464
|
-
// 公众号支付用 服务号 appid,其他用小程序 appid
|
|
465
|
-
const app_id = (await appConfig.getObject(config)).app_id
|
|
466
467
|
|
|
467
468
|
const wxpay = WXPay({
|
|
468
469
|
appid: app_id,
|
|
@@ -497,10 +498,12 @@ exports.pc_pay = async ({
|
|
|
497
498
|
spbill_create_ip: '192.168.2.210',
|
|
498
499
|
notify_url,
|
|
499
500
|
})
|
|
500
|
-
|
|
501
501
|
if (result.return_code === 'FAIL') {
|
|
502
502
|
throw new Error(result.return_msg)
|
|
503
503
|
}
|
|
504
|
+
if (result.result_code === 'FAIL') {
|
|
505
|
+
throw new Error(result.err_code_des)
|
|
506
|
+
}
|
|
504
507
|
|
|
505
508
|
return `https://${
|
|
506
509
|
site_host || 'api.kuashou.com'
|