q-koa 10.5.4 → 10.5.5

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.
@@ -1324,6 +1324,7 @@ exports.checkPay = async (ctx) => {
1324
1324
  prefix,
1325
1325
  config = 'weixin_mp',
1326
1326
  pay_config = 'weixin_pay',
1327
+ type = 'MP-WEIXIN',
1327
1328
  out_trade_no: _out_trade_no,
1328
1329
  } = ctx.request.body
1329
1330
 
@@ -1345,19 +1346,11 @@ exports.checkPay = async (ctx) => {
1345
1346
  partner_key: key.length > 10 ? key : partner_key, // 微信商户平台API密钥
1346
1347
  })
1347
1348
 
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
1349
  const orderPrefix = prefix ? `${prefix}-` : ''
1357
1350
  const out_trade_no = _out_trade_no
1358
1351
  ? _out_trade_no
1359
- : `${key}_${orderPrefix}${id}_MP-WEIXIN`
1360
- const payResult = await checkOrder({
1352
+ : `${key}_${orderPrefix}${id}_${type}`
1353
+ const payResult = await wxpay.queryOrderSync({
1361
1354
  out_trade_no,
1362
1355
  })
1363
1356
  if (payResult.trade_state_desc === '支付成功') {
@@ -1381,6 +1374,7 @@ exports.checkRefund = async (ctx) => {
1381
1374
  const {
1382
1375
  id,
1383
1376
  prefix,
1377
+ type = 'MP-WEIXIN',
1384
1378
  config = 'weixin_mp',
1385
1379
  pay_config = 'weixin_pay',
1386
1380
  out_trade_no: _out_trade_no,
@@ -1416,7 +1410,7 @@ exports.checkRefund = async (ctx) => {
1416
1410
  const orderPrefix = prefix ? `${prefix}-` : ''
1417
1411
  const out_trade_no = _out_trade_no
1418
1412
  ? _out_trade_no
1419
- : `${key}_${orderPrefix}${id}_MP-WEIXIN`
1413
+ : `${key}_${orderPrefix}${id}_${type}`
1420
1414
 
1421
1415
  const result = await payObj.checkRefund({
1422
1416
  out_trade_no,
@@ -1550,3 +1544,133 @@ exports.messagePush = async (ctx) => {
1550
1544
  ctx.body = 'success'
1551
1545
  }
1552
1546
  }
1547
+
1548
+ exports.profitsharing = async (ctx) => {
1549
+ const { app, appName } = getAppByCtx(ctx)
1550
+ const {
1551
+ transaction_id = '',
1552
+ out_order_no = '',
1553
+ type = 'PERSONAL_OPENID',
1554
+ amount = 0,
1555
+ openid = '',
1556
+ description = '手续费',
1557
+ config = 'weixin_mp',
1558
+ pay_config = 'weixin_pay',
1559
+ } = ctx.request.body
1560
+ if (!amount) return ctx.ERROR('?amount分')
1561
+ if (!transaction_id) return ctx.ERROR('?transaction_id')
1562
+ if (!out_order_no) return ctx.ERROR('?out_order_no')
1563
+ if (!openid) return ctx.ERROR('?openid')
1564
+
1565
+ const appConfig = getConfig(app)
1566
+
1567
+ const { mchId, key, partner_key } = await appConfig.getObject(pay_config)
1568
+
1569
+ const { is_dev, site_host } = await appConfig.getObject('base')
1570
+ // 公众号支付用 服务号 appid,其他用小程序 appid
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 fs.readFileSync(
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
+ pfx: await fs.readFileSync(
1623
+ path.resolve(
1624
+ __dirname,
1625
+ `${process.cwd()}/app/${appName}/plugins/weixin/${key}/apiclient_cert.p12`
1626
+ )
1627
+ ),
1628
+ })
1629
+
1630
+ const res = await wxpay.addreceiverSync({
1631
+ receiver: {
1632
+ type,
1633
+ account: openid,
1634
+ relation_type,
1635
+ },
1636
+ })
1637
+ return ctx.SUCCESS(res)
1638
+ }
1639
+
1640
+ exports.removereceiver = async (ctx) => {
1641
+ const { app, appName } = getAppByCtx(ctx)
1642
+ const {
1643
+ type = 'PERSONAL_OPENID',
1644
+ openid = '',
1645
+ config = 'weixin_mp',
1646
+ pay_config = 'weixin_pay',
1647
+ } = ctx.request.body
1648
+
1649
+ if (!openid) return ctx.ERROR('?openid')
1650
+
1651
+ const appConfig = getConfig(app)
1652
+
1653
+ const { mchId, key, partner_key } = await appConfig.getObject(pay_config)
1654
+
1655
+ const app_id = (await appConfig.getObject(config)).app_id
1656
+
1657
+ const wxpay = WXPay({
1658
+ appid: app_id,
1659
+ mch_id: mchId,
1660
+ partner_key: key.length > 10 ? key : partner_key, // 微信商户平台API密钥
1661
+ pfx: await fs.readFileSync(
1662
+ path.resolve(
1663
+ __dirname,
1664
+ `${process.cwd()}/app/${appName}/plugins/weixin/${key}/apiclient_cert.p12`
1665
+ )
1666
+ ),
1667
+ })
1668
+
1669
+ const res = await wxpay.removereceiverSync({
1670
+ receiver: {
1671
+ type,
1672
+ account: openid,
1673
+ },
1674
+ })
1675
+ return ctx.SUCCESS(res)
1676
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "q-koa",
3
- "version": "10.5.4",
3
+ "version": "10.5.5",
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.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",