q-koa 10.7.3 → 10.7.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.
|
@@ -862,6 +862,85 @@ exports.pc_pay = async (ctx) => {
|
|
|
862
862
|
return ctx.SUCCESS(result)
|
|
863
863
|
}
|
|
864
864
|
|
|
865
|
+
exports.app_pay = async (ctx) => {
|
|
866
|
+
const { app, appName } = getAppByCtx(ctx)
|
|
867
|
+
const {
|
|
868
|
+
name,
|
|
869
|
+
order_id,
|
|
870
|
+
price,
|
|
871
|
+
return_url,
|
|
872
|
+
prefix = '',
|
|
873
|
+
type,
|
|
874
|
+
out_trade_no: _out_trade_no,
|
|
875
|
+
is_admin = false,
|
|
876
|
+
config = 'weixin_mp',
|
|
877
|
+
pay_config = 'weixin_pay',
|
|
878
|
+
} = ctx.request.body
|
|
879
|
+
|
|
880
|
+
if (price === 0) throw new Error('价格不能为0')
|
|
881
|
+
|
|
882
|
+
if (
|
|
883
|
+
!ctx.request[`${appName}-user`] ||
|
|
884
|
+
!ctx.request[`${appName}-user`].open_user
|
|
885
|
+
) {
|
|
886
|
+
throw new Error('请先微信登录')
|
|
887
|
+
}
|
|
888
|
+
const appConfig = getConfig(app)
|
|
889
|
+
|
|
890
|
+
const { mchId, key, partner_key, appId: appid } = await appConfig.getObject(
|
|
891
|
+
pay_config
|
|
892
|
+
)
|
|
893
|
+
|
|
894
|
+
if (!appid) throw new Error(`appId不能存在`)
|
|
895
|
+
|
|
896
|
+
const { is_dev, site_host } = await appConfig.getObject('base')
|
|
897
|
+
|
|
898
|
+
const wxpay = WXPay({
|
|
899
|
+
appid,
|
|
900
|
+
mch_id: mchId,
|
|
901
|
+
partner_key: key.length > 10 ? key : partner_key, // 微信商户平台API密钥
|
|
902
|
+
})
|
|
903
|
+
|
|
904
|
+
const out_trade_no = _out_trade_no
|
|
905
|
+
? _out_trade_no
|
|
906
|
+
: prefix
|
|
907
|
+
? `${key.length > 10 ? appName : key}_${prefix}-${order_id}_${type}`
|
|
908
|
+
: `${key.length > 10 ? appName : key}_${order_id}_${type}`
|
|
909
|
+
|
|
910
|
+
const notify_url = `https://${
|
|
911
|
+
site_host || 'api.kuashou.com'
|
|
912
|
+
}/${appName}/weixin/notify`
|
|
913
|
+
|
|
914
|
+
const result = await wxpay.getBrandWCPayRequestParamsSync({
|
|
915
|
+
trade_type: 'APP',
|
|
916
|
+
body: name,
|
|
917
|
+
detail: '公众号支付测试',
|
|
918
|
+
out_trade_no,
|
|
919
|
+
total_fee: is_admin || is_dev ? 1 : Math.round(price * 100),
|
|
920
|
+
spbill_create_ip: '192.168.2.210',
|
|
921
|
+
notify_url,
|
|
922
|
+
})
|
|
923
|
+
|
|
924
|
+
const {
|
|
925
|
+
nonceStr: nonce_str,
|
|
926
|
+
package: prepay_id,
|
|
927
|
+
paySign: sign,
|
|
928
|
+
timeStamp: timestamp,
|
|
929
|
+
} = result
|
|
930
|
+
|
|
931
|
+
const returnObj = {
|
|
932
|
+
appid,
|
|
933
|
+
partnerid: mchId,
|
|
934
|
+
nonce_str,
|
|
935
|
+
prepay_id,
|
|
936
|
+
sign,
|
|
937
|
+
return_url,
|
|
938
|
+
timestamp,
|
|
939
|
+
}
|
|
940
|
+
|
|
941
|
+
return ctx.SUCCESS(returnObj)
|
|
942
|
+
}
|
|
943
|
+
|
|
865
944
|
exports.mp_pay = async (ctx) => {
|
|
866
945
|
const { app, appName } = getAppByCtx(ctx)
|
|
867
946
|
const {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "q-koa",
|
|
3
|
-
"version": "10.7.
|
|
3
|
+
"version": "10.7.4",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"sequelize": "^5.21.3",
|
|
53
53
|
"static-koa-router": "^1.0.3",
|
|
54
54
|
"wechat-oauth": "^1.5.0",
|
|
55
|
-
"weixin-pay-fork": "^1.0.
|
|
55
|
+
"weixin-pay-fork": "^1.0.5",
|
|
56
56
|
"node-uuid": "^1.4.8",
|
|
57
57
|
"sha1": "^1.1.1",
|
|
58
58
|
"redis": "^4.0.3",
|