q-koa 10.5.4 → 10.6.0
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.
|
@@ -11,6 +11,8 @@ const WXBizDataCrypt = require('../../services/weixinCrypt')
|
|
|
11
11
|
const weixinArticle = require('../../services/weixinArticle')
|
|
12
12
|
const fxp = require('fast-xml-parser')
|
|
13
13
|
const crypto = require('crypto')
|
|
14
|
+
const path = require('path')
|
|
15
|
+
const fsPromise = require('fs/promises')
|
|
14
16
|
const { getAppConfig } = require('../../utils')
|
|
15
17
|
|
|
16
18
|
const check = ({ timestamp, nonce, signature, token }) => {
|
|
@@ -1324,6 +1326,7 @@ exports.checkPay = async (ctx) => {
|
|
|
1324
1326
|
prefix,
|
|
1325
1327
|
config = 'weixin_mp',
|
|
1326
1328
|
pay_config = 'weixin_pay',
|
|
1329
|
+
type = 'MP-WEIXIN',
|
|
1327
1330
|
out_trade_no: _out_trade_no,
|
|
1328
1331
|
} = ctx.request.body
|
|
1329
1332
|
|
|
@@ -1345,19 +1348,11 @@ exports.checkPay = async (ctx) => {
|
|
|
1345
1348
|
partner_key: key.length > 10 ? key : partner_key, // 微信商户平台API密钥
|
|
1346
1349
|
})
|
|
1347
1350
|
|
|
1348
|
-
const checkOrder = (obj) => {
|
|
1349
|
-
return new Promise((resolve, reject) => {
|
|
1350
|
-
wxpay.queryOrder(obj, function (err, order) {
|
|
1351
|
-
if (err) throw new Error(err)
|
|
1352
|
-
resolve(order)
|
|
1353
|
-
})
|
|
1354
|
-
})
|
|
1355
|
-
}
|
|
1356
1351
|
const orderPrefix = prefix ? `${prefix}-` : ''
|
|
1357
1352
|
const out_trade_no = _out_trade_no
|
|
1358
1353
|
? _out_trade_no
|
|
1359
|
-
: `${key}_${orderPrefix}${id}
|
|
1360
|
-
const payResult = await
|
|
1354
|
+
: `${key}_${orderPrefix}${id}_${type}`
|
|
1355
|
+
const payResult = await wxpay.queryOrderSync({
|
|
1361
1356
|
out_trade_no,
|
|
1362
1357
|
})
|
|
1363
1358
|
if (payResult.trade_state_desc === '支付成功') {
|
|
@@ -1381,6 +1376,7 @@ exports.checkRefund = async (ctx) => {
|
|
|
1381
1376
|
const {
|
|
1382
1377
|
id,
|
|
1383
1378
|
prefix,
|
|
1379
|
+
type = 'MP-WEIXIN',
|
|
1384
1380
|
config = 'weixin_mp',
|
|
1385
1381
|
pay_config = 'weixin_pay',
|
|
1386
1382
|
out_trade_no: _out_trade_no,
|
|
@@ -1416,7 +1412,7 @@ exports.checkRefund = async (ctx) => {
|
|
|
1416
1412
|
const orderPrefix = prefix ? `${prefix}-` : ''
|
|
1417
1413
|
const out_trade_no = _out_trade_no
|
|
1418
1414
|
? _out_trade_no
|
|
1419
|
-
: `${key}_${orderPrefix}${id}
|
|
1415
|
+
: `${key}_${orderPrefix}${id}_${type}`
|
|
1420
1416
|
|
|
1421
1417
|
const result = await payObj.checkRefund({
|
|
1422
1418
|
out_trade_no,
|
|
@@ -1550,3 +1546,119 @@ exports.messagePush = async (ctx) => {
|
|
|
1550
1546
|
ctx.body = 'success'
|
|
1551
1547
|
}
|
|
1552
1548
|
}
|
|
1549
|
+
|
|
1550
|
+
exports.profitsharing = async (ctx) => {
|
|
1551
|
+
const { app, appName } = getAppByCtx(ctx)
|
|
1552
|
+
const {
|
|
1553
|
+
transaction_id = '',
|
|
1554
|
+
out_order_no = '',
|
|
1555
|
+
type = 'PERSONAL_OPENID',
|
|
1556
|
+
amount = 0,
|
|
1557
|
+
openid = '',
|
|
1558
|
+
description = '手续费',
|
|
1559
|
+
config = 'weixin_mp',
|
|
1560
|
+
pay_config = 'weixin_pay',
|
|
1561
|
+
} = ctx.request.body
|
|
1562
|
+
if (!amount) return ctx.ERROR('?amount分')
|
|
1563
|
+
if (!transaction_id) return ctx.ERROR('?transaction_id')
|
|
1564
|
+
if (!out_order_no) return ctx.ERROR('?out_order_no')
|
|
1565
|
+
if (!openid) return ctx.ERROR('?openid')
|
|
1566
|
+
|
|
1567
|
+
const appConfig = getConfig(app)
|
|
1568
|
+
|
|
1569
|
+
const { mchId, key, partner_key } = await appConfig.getObject(pay_config)
|
|
1570
|
+
|
|
1571
|
+
const app_id = (await appConfig.getObject(config)).app_id
|
|
1572
|
+
|
|
1573
|
+
const wxpay = WXPay({
|
|
1574
|
+
appid: app_id,
|
|
1575
|
+
mch_id: mchId,
|
|
1576
|
+
partner_key: key.length > 10 ? key : partner_key, // 微信商户平台API密钥
|
|
1577
|
+
pfx: await fsPromise.readFile(
|
|
1578
|
+
path.resolve(
|
|
1579
|
+
__dirname,
|
|
1580
|
+
`${process.cwd()}/app/${appName}/plugins/weixin/${key}/apiclient_cert.p12`
|
|
1581
|
+
)
|
|
1582
|
+
),
|
|
1583
|
+
})
|
|
1584
|
+
|
|
1585
|
+
const res = await wxpay.profitsharingSync({
|
|
1586
|
+
transaction_id,
|
|
1587
|
+
out_order_no,
|
|
1588
|
+
receivers: [
|
|
1589
|
+
{
|
|
1590
|
+
type,
|
|
1591
|
+
account: openid,
|
|
1592
|
+
description,
|
|
1593
|
+
amount,
|
|
1594
|
+
},
|
|
1595
|
+
],
|
|
1596
|
+
})
|
|
1597
|
+
return ctx.SUCCESS(res)
|
|
1598
|
+
}
|
|
1599
|
+
|
|
1600
|
+
exports.addreceiver = async (ctx) => {
|
|
1601
|
+
const { app, appName } = getAppByCtx(ctx)
|
|
1602
|
+
const {
|
|
1603
|
+
type = 'PERSONAL_OPENID',
|
|
1604
|
+
openid = '',
|
|
1605
|
+
relation_type = 'USER',
|
|
1606
|
+
config = 'weixin_mp',
|
|
1607
|
+
pay_config = 'weixin_pay',
|
|
1608
|
+
} = ctx.request.body
|
|
1609
|
+
|
|
1610
|
+
if (!openid) return ctx.ERROR('?openid')
|
|
1611
|
+
|
|
1612
|
+
const appConfig = getConfig(app)
|
|
1613
|
+
|
|
1614
|
+
const { mchId, key, partner_key } = await appConfig.getObject(pay_config)
|
|
1615
|
+
|
|
1616
|
+
const app_id = (await appConfig.getObject(config)).app_id
|
|
1617
|
+
|
|
1618
|
+
const wxpay = WXPay({
|
|
1619
|
+
appid: app_id,
|
|
1620
|
+
mch_id: mchId,
|
|
1621
|
+
partner_key: key.length > 10 ? key : partner_key, // 微信商户平台API密钥
|
|
1622
|
+
})
|
|
1623
|
+
|
|
1624
|
+
const res = await wxpay.addreceiverSync({
|
|
1625
|
+
receiver: {
|
|
1626
|
+
type,
|
|
1627
|
+
account: openid,
|
|
1628
|
+
relation_type,
|
|
1629
|
+
},
|
|
1630
|
+
})
|
|
1631
|
+
return ctx.SUCCESS(res)
|
|
1632
|
+
}
|
|
1633
|
+
|
|
1634
|
+
exports.removereceiver = async (ctx) => {
|
|
1635
|
+
const { app, appName } = getAppByCtx(ctx)
|
|
1636
|
+
const {
|
|
1637
|
+
type = 'PERSONAL_OPENID',
|
|
1638
|
+
openid = '',
|
|
1639
|
+
config = 'weixin_mp',
|
|
1640
|
+
pay_config = 'weixin_pay',
|
|
1641
|
+
} = ctx.request.body
|
|
1642
|
+
|
|
1643
|
+
if (!openid) return ctx.ERROR('?openid')
|
|
1644
|
+
|
|
1645
|
+
const appConfig = getConfig(app)
|
|
1646
|
+
|
|
1647
|
+
const { mchId, key, partner_key } = await appConfig.getObject(pay_config)
|
|
1648
|
+
|
|
1649
|
+
const app_id = (await appConfig.getObject(config)).app_id
|
|
1650
|
+
|
|
1651
|
+
const wxpay = WXPay({
|
|
1652
|
+
appid: app_id,
|
|
1653
|
+
mch_id: mchId,
|
|
1654
|
+
partner_key: key.length > 10 ? key : partner_key, // 微信商户平台API密钥
|
|
1655
|
+
})
|
|
1656
|
+
|
|
1657
|
+
const res = await wxpay.removereceiverSync({
|
|
1658
|
+
receiver: {
|
|
1659
|
+
type,
|
|
1660
|
+
account: openid,
|
|
1661
|
+
},
|
|
1662
|
+
})
|
|
1663
|
+
return ctx.SUCCESS(res)
|
|
1664
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "q-koa",
|
|
3
|
-
"version": "10.
|
|
3
|
+
"version": "10.6.0",
|
|
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.2",
|
|
56
56
|
"node-uuid": "^1.4.8",
|
|
57
57
|
"sha1": "^1.1.1",
|
|
58
58
|
"redis": "^4.0.3",
|