q-koa 10.6.0 → 10.6.1

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.
@@ -1550,115 +1550,64 @@ exports.messagePush = async (ctx) => {
1550
1550
  exports.profitsharing = async (ctx) => {
1551
1551
  const { app, appName } = getAppByCtx(ctx)
1552
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',
1553
+ transaction_id,
1554
+ out_order_no,
1555
+ type,
1556
+ amount,
1557
+ openid,
1558
+ description,
1559
+ config,
1560
+ pay_config,
1561
1561
  } = ctx.request.body
1562
+
1562
1563
  if (!amount) return ctx.ERROR('?amount分')
1563
1564
  if (!transaction_id) return ctx.ERROR('?transaction_id')
1564
1565
  if (!out_order_no) return ctx.ERROR('?out_order_no')
1565
1566
  if (!openid) return ctx.ERROR('?openid')
1566
1567
 
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({
1568
+ const res = await app.service.weixin.profitsharing({
1569
+ ctx,
1586
1570
  transaction_id,
1587
1571
  out_order_no,
1588
- receivers: [
1589
- {
1590
- type,
1591
- account: openid,
1592
- description,
1593
- amount,
1594
- },
1595
- ],
1572
+ type,
1573
+ openid,
1574
+ description,
1575
+ amount,
1576
+ config,
1577
+ pay_config,
1596
1578
  })
1597
1579
  return ctx.SUCCESS(res)
1598
1580
  }
1599
1581
 
1600
1582
  exports.addreceiver = async (ctx) => {
1601
1583
  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
1584
+ const { type, openid, relation_type, config, pay_config } = ctx.request.body
1609
1585
 
1610
1586
  if (!openid) return ctx.ERROR('?openid')
1611
1587
 
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
- },
1588
+ const res = await app.service.weixin.addreceiver({
1589
+ ctx,
1590
+ type,
1591
+ openid,
1592
+ relation_type,
1593
+ config,
1594
+ pay_config,
1630
1595
  })
1631
1596
  return ctx.SUCCESS(res)
1632
1597
  }
1633
1598
 
1634
1599
  exports.removereceiver = async (ctx) => {
1635
1600
  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
1601
+ const { type, openid, config, pay_config } = ctx.request.body
1642
1602
 
1643
1603
  if (!openid) return ctx.ERROR('?openid')
1644
1604
 
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
- },
1605
+ const res = await app.service.weixin.removereceiver({
1606
+ ctx,
1607
+ type,
1608
+ openid,
1609
+ config,
1610
+ pay_config,
1662
1611
  })
1663
1612
  return ctx.SUCCESS(res)
1664
1613
  }
@@ -19,6 +19,7 @@ exports.refund = async ({
19
19
  out_trade_no: _out_trade_no,
20
20
  ...rest
21
21
  }) => {
22
+ if (!ctx) throw new Error('?ctx')
22
23
  const { app, appName } = getAppByCtx(ctx)
23
24
  const appConfig = getConfig(app)
24
25
  const { mchId, key, appId, partner_key } = await appConfig.getObject(
@@ -94,6 +95,7 @@ exports.refund_new = async ({
94
95
  out_trade_no: _out_trade_no,
95
96
  ...rest
96
97
  }) => {
98
+ if (!ctx) throw new Error('?ctx')
97
99
  const { app, appName } = getAppByCtx(ctx)
98
100
  const appConfig = getConfig(app)
99
101
 
@@ -162,6 +164,7 @@ exports.cash = async ({
162
164
  number,
163
165
  pay_config = 'weixin_pay',
164
166
  }) => {
167
+ if (!ctx) throw new Error('?ctx')
165
168
  const { app, appName } = getAppByCtx(ctx)
166
169
  const appConfig = getConfig(app)
167
170
 
@@ -455,6 +458,7 @@ exports.pc_pay = async ({
455
458
  type = 'PC-WEIXIN',
456
459
  prefix = '',
457
460
  }) => {
461
+ if (!ctx) throw new Error('?ctx')
458
462
  if (!order_id) throw new Error('缺order_id')
459
463
  if (!price) throw new Error('缺price')
460
464
  if (!name) throw new Error('缺name')
@@ -509,3 +513,114 @@ exports.pc_pay = async ({
509
513
  site_host || 'api.kuashou.com'
510
514
  }/${appName}/common/createQr?url=${result.code_url}`
511
515
  }
516
+
517
+ exports.profitsharing = async ({
518
+ ctx,
519
+ transaction_id = '',
520
+ out_order_no = '',
521
+ type = 'PERSONAL_OPENID',
522
+ amount = 0,
523
+ openid = '',
524
+ description = '手续费',
525
+ config = 'weixin_mp',
526
+ pay_config = 'weixin_pay',
527
+ }) => {
528
+ if (!ctx) throw new Error('?ctx')
529
+ const { app, appName } = getAppByCtx(ctx)
530
+
531
+ const appConfig = getConfig(app)
532
+
533
+ const { mchId, key, partner_key } = await appConfig.getObject(pay_config)
534
+
535
+ const app_id = (await appConfig.getObject(config)).app_id
536
+
537
+ const wxpay = WXPay({
538
+ appid: app_id,
539
+ mch_id: mchId,
540
+ partner_key: key.length > 10 ? key : partner_key, // 微信商户平台API密钥
541
+ pfx: await fsPromise.readFile(
542
+ path.resolve(
543
+ __dirname,
544
+ `${process.cwd()}/app/${appName}/plugins/weixin/${key}/apiclient_cert.p12`
545
+ )
546
+ ),
547
+ })
548
+
549
+ const res = await wxpay.profitsharingSync({
550
+ transaction_id,
551
+ out_order_no,
552
+ receivers: [
553
+ {
554
+ type,
555
+ account: openid,
556
+ description,
557
+ amount,
558
+ },
559
+ ],
560
+ })
561
+ return res
562
+ }
563
+
564
+ exports.addreceiver = async ({
565
+ ctx,
566
+ type = 'PERSONAL_OPENID',
567
+ openid = '',
568
+ relation_type = 'USER',
569
+ config = 'weixin_mp',
570
+ pay_config = 'weixin_pay',
571
+ }) => {
572
+ if (!ctx) throw new Error('?ctx')
573
+ const { app, appName } = getAppByCtx(ctx)
574
+
575
+ const appConfig = getConfig(app)
576
+
577
+ const { mchId, key, partner_key } = await appConfig.getObject(pay_config)
578
+
579
+ const app_id = (await appConfig.getObject(config)).app_id
580
+
581
+ const wxpay = WXPay({
582
+ appid: app_id,
583
+ mch_id: mchId,
584
+ partner_key: key.length > 10 ? key : partner_key, // 微信商户平台API密钥
585
+ })
586
+
587
+ const res = await wxpay.addreceiverSync({
588
+ receiver: {
589
+ type,
590
+ account: openid,
591
+ relation_type,
592
+ },
593
+ })
594
+ return res
595
+ }
596
+
597
+ exports.removereceiver = async ({
598
+ ctx,
599
+ type = 'PERSONAL_OPENID',
600
+ openid = '',
601
+ config = 'weixin_mp',
602
+ pay_config = 'weixin_pay',
603
+ }) => {
604
+ if (!ctx) throw new Error('?ctx')
605
+ const { app, appName } = getAppByCtx(ctx)
606
+
607
+ const appConfig = getConfig(app)
608
+
609
+ const { mchId, key, partner_key } = await appConfig.getObject(pay_config)
610
+
611
+ const app_id = (await appConfig.getObject(config)).app_id
612
+
613
+ const wxpay = WXPay({
614
+ appid: app_id,
615
+ mch_id: mchId,
616
+ partner_key: key.length > 10 ? key : partner_key, // 微信商户平台API密钥
617
+ })
618
+
619
+ const res = await wxpay.removereceiverSync({
620
+ receiver: {
621
+ type,
622
+ account: openid,
623
+ },
624
+ })
625
+ return res
626
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "q-koa",
3
- "version": "10.6.0",
3
+ "version": "10.6.1",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {