q-koa 10.5.3 → 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.
@@ -1203,6 +1203,7 @@ exports.refund = async (ctx) => {
1203
1203
  pay_config = 'weixin_pay',
1204
1204
  is_new_pay = false,
1205
1205
  out_trade_no,
1206
+ type,
1206
1207
  } = ctx.request.body
1207
1208
 
1208
1209
  const fn = is_new_pay ? 'refund_new' : 'refund'
@@ -1216,6 +1217,7 @@ exports.refund = async (ctx) => {
1216
1217
  config,
1217
1218
  pay_config,
1218
1219
  out_trade_no,
1220
+ type,
1219
1221
  })
1220
1222
  ctx.SUCCESS('ok')
1221
1223
  }
@@ -1322,6 +1324,7 @@ exports.checkPay = async (ctx) => {
1322
1324
  prefix,
1323
1325
  config = 'weixin_mp',
1324
1326
  pay_config = 'weixin_pay',
1327
+ type = 'MP-WEIXIN',
1325
1328
  out_trade_no: _out_trade_no,
1326
1329
  } = ctx.request.body
1327
1330
 
@@ -1343,19 +1346,11 @@ exports.checkPay = async (ctx) => {
1343
1346
  partner_key: key.length > 10 ? key : partner_key, // 微信商户平台API密钥
1344
1347
  })
1345
1348
 
1346
- const checkOrder = (obj) => {
1347
- return new Promise((resolve, reject) => {
1348
- wxpay.queryOrder(obj, function (err, order) {
1349
- if (err) throw new Error(err)
1350
- resolve(order)
1351
- })
1352
- })
1353
- }
1354
1349
  const orderPrefix = prefix ? `${prefix}-` : ''
1355
1350
  const out_trade_no = _out_trade_no
1356
1351
  ? _out_trade_no
1357
- : `${key}_${orderPrefix}${id}_MP-WEIXIN`
1358
- const payResult = await checkOrder({
1352
+ : `${key}_${orderPrefix}${id}_${type}`
1353
+ const payResult = await wxpay.queryOrderSync({
1359
1354
  out_trade_no,
1360
1355
  })
1361
1356
  if (payResult.trade_state_desc === '支付成功') {
@@ -1379,6 +1374,7 @@ exports.checkRefund = async (ctx) => {
1379
1374
  const {
1380
1375
  id,
1381
1376
  prefix,
1377
+ type = 'MP-WEIXIN',
1382
1378
  config = 'weixin_mp',
1383
1379
  pay_config = 'weixin_pay',
1384
1380
  out_trade_no: _out_trade_no,
@@ -1414,7 +1410,7 @@ exports.checkRefund = async (ctx) => {
1414
1410
  const orderPrefix = prefix ? `${prefix}-` : ''
1415
1411
  const out_trade_no = _out_trade_no
1416
1412
  ? _out_trade_no
1417
- : `${key}_${orderPrefix}${id}_MP-WEIXIN`
1413
+ : `${key}_${orderPrefix}${id}_${type}`
1418
1414
 
1419
1415
  const result = await payObj.checkRefund({
1420
1416
  out_trade_no,
@@ -1548,3 +1544,133 @@ exports.messagePush = async (ctx) => {
1548
1544
  ctx.body = 'success'
1549
1545
  }
1550
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
+ }
@@ -13,7 +13,7 @@ exports.refund = async ({
13
13
  total_fee,
14
14
  refund_fee,
15
15
  price,
16
- type = '',
16
+ type = 'MP-WEIXIN',
17
17
  config = 'weixin_mp',
18
18
  pay_config = 'weixin_pay',
19
19
  out_trade_no: _out_trade_no,
@@ -41,8 +41,8 @@ exports.refund = async ({
41
41
  const out_trade_no = _out_trade_no
42
42
  ? _out_trade_no
43
43
  : prefix
44
- ? `${key}_${prefix}-${id}_MP-WEIXIN`
45
- : `${key}_${id}_MP-WEIXIN`
44
+ ? `${key}_${prefix}-${id}_${type}`
45
+ : `${key}_${id}_${type}`
46
46
  const orderDetail = await app.model[orderModel].findOne({
47
47
  where: {
48
48
  id,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "q-koa",
3
- "version": "10.5.3",
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",