q-koa 10.4.0 → 10.5.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.
@@ -1077,7 +1077,9 @@ exports.notify = async (ctx) => {
1077
1077
  }
1078
1078
  const model = prefix ? `${prefix}_order` : 'order'
1079
1079
  let transactionid = ''
1080
+ let openid = ''
1080
1081
  try {
1082
+ openid = result.xml.openid
1081
1083
  transactionid = result.xml.transaction_id
1082
1084
  } catch (e) {}
1083
1085
 
@@ -1090,6 +1092,7 @@ exports.notify = async (ctx) => {
1090
1092
  order_price,
1091
1093
  transactionid,
1092
1094
  out_trade_no: result.xml.out_trade_no,
1095
+ openid,
1093
1096
  })
1094
1097
  }
1095
1098
 
@@ -1368,6 +1371,56 @@ exports.checkPay = async (ctx) => {
1368
1371
  ctx.SUCCESS({ prefix, out_trade_no, ...payResult })
1369
1372
  }
1370
1373
 
1374
+ exports.checkRefund = async (ctx) => {
1375
+ const { app, appName, controller } = getAppByCtx(ctx)
1376
+
1377
+ const {
1378
+ id,
1379
+ prefix,
1380
+ config = 'weixin_mp',
1381
+ pay_config = 'weixin_pay',
1382
+ out_trade_no: _out_trade_no,
1383
+ } = ctx.request.body
1384
+
1385
+ const appConfig = getConfig(app)
1386
+ const { appId, mchId, key, partner_key } = await appConfig.getObject(
1387
+ pay_config
1388
+ )
1389
+
1390
+ const payObj = new WeixinPay({
1391
+ appId,
1392
+ mchId,
1393
+ key: key.length > 10 ? key : partner_key,
1394
+ })
1395
+
1396
+ if (_out_trade_no) {
1397
+ const result = await payObj.checkRefund({
1398
+ out_trade_no: _out_trade_no,
1399
+ })
1400
+ return ctx.SUCCESS(result)
1401
+ }
1402
+
1403
+ if (!id) return ctx.ERROR('?id')
1404
+ const orderModel = prefix ? `${prefix}_order` : 'order'
1405
+ const orderDetail = await app.model[orderModel].findOne({
1406
+ where: {
1407
+ id,
1408
+ },
1409
+ })
1410
+
1411
+ if (!orderDetail) return ctx.SUCCESS('找不到')
1412
+ const orderPrefix = prefix ? `${prefix}-` : ''
1413
+ const out_trade_no = _out_trade_no
1414
+ ? _out_trade_no
1415
+ : `${key}_${orderPrefix}${id}_MP-WEIXIN`
1416
+
1417
+ const result = await payObj.checkRefund({
1418
+ out_trade_no,
1419
+ })
1420
+
1421
+ ctx.SUCCESS(result)
1422
+ }
1423
+
1371
1424
  exports.checkPayNew = async (ctx) => {
1372
1425
  const { app, appName, controller } = getAppByCtx(ctx)
1373
1426
 
@@ -451,10 +451,13 @@ exports.pc_pay = async ({
451
451
  config = 'weixin_mp',
452
452
  pay_config = 'weixin_pay',
453
453
  out_trade_no: _out_trade_no,
454
- is_admin,
454
+ is_admin = false,
455
455
  type = 'PC-WEIXIN',
456
- prefix,
456
+ prefix = '',
457
457
  }) => {
458
+ if (!order_id) throw new Error('缺order_id')
459
+ if (!price) throw new Error('缺price')
460
+ if (!name) throw new Error('缺name')
458
461
  const { app, appName } = getAppByCtx(ctx)
459
462
  const appConfig = getConfig(app)
460
463
  const app_id = (await appConfig.getObject(config)).app_id
@@ -41,15 +41,20 @@ const getOrderUrl =
41
41
  const refundOrderUrl =
42
42
  'https://api.weixin.qq.com/shop/pay/refundorder?access_token=%s'
43
43
 
44
- const addGoodUrl = 'https://api.weixin.qq.com/shop/spu/add?access_token=%s'
44
+ const addGoodUrl =
45
+ 'https://api.weixin.qq.com/channels/ec/product/add?access_token=%s'
45
46
 
46
- const getCategoryUrl = 'https://api.weixin.qq.com/shop/cat/get?access_token=%s'
47
+ const getCategoryUrl =
48
+ 'https://api.weixin.qq.com/channels/ec/category/all?access_token=%s'
47
49
 
48
50
  const getBrandListUrl =
49
51
  'https://api.weixin.qq.com/shop/account/get_brand_list?access_token=%s'
50
52
 
51
53
  const uploadImageUrl =
52
- 'https://api.weixin.qq.com/channels/ec/basics/img/upload?access_token=%s'
54
+ 'https://api.weixin.qq.com/channels/ec/basics/img/upload?access_token=%s&upload_type=%s&resp_type=%s'
55
+
56
+ const getShipTemplateUrl =
57
+ 'https://api.weixin.qq.com/channels/ec/merchant/getfreighttemplatelist?access_token=%s'
53
58
 
54
59
  const fsPromise = require('fs/promises')
55
60
  const LRU = require('lru-cache')
@@ -581,6 +586,7 @@ module.exports = class Singleton {
581
586
  async addGood(payLoad) {
582
587
  const access_token = await this.getAccessToken()
583
588
  const url = util.format(addGoodUrl, access_token)
589
+ console.log('payLoad', payLoad)
584
590
  const result = await axios
585
591
  .post(url, {
586
592
  ...payLoad,
@@ -613,7 +619,7 @@ module.exports = class Singleton {
613
619
  }
614
620
  throw new Error(`${result.errcode};${result.errmsg}`)
615
621
  }
616
- return result.third_cat_list
622
+ return result
617
623
  }
618
624
 
619
625
  async getBrandList(payLoad) {
@@ -635,14 +641,42 @@ module.exports = class Singleton {
635
641
  return result.data
636
642
  }
637
643
 
644
+ async getShipTemplate(payLoad) {
645
+ const access_token = await this.getAccessToken()
646
+ const url = util.format(getShipTemplateUrl, access_token)
647
+
648
+ const result = await axios
649
+ .post(url, {
650
+ ...payLoad,
651
+ })
652
+ .then((res) => res.data)
653
+ if (result.errcode) {
654
+ if (result.errcode === 40001) {
655
+ cache.reset()
656
+ return await this.getShipTemplate(payLoad)
657
+ }
658
+ throw new Error(`${result.errcode};${result.errmsg}`)
659
+ }
660
+ return result
661
+ }
662
+
638
663
  async uploadImage(payLoad) {
639
664
  const access_token = await this.getAccessToken()
640
- const url = util.format(uploadImageUrl, access_token)
665
+ const { upload_type, resp_type, ...rest } = payLoad
666
+
667
+ const url = util.format(
668
+ uploadImageUrl,
669
+ access_token,
670
+ upload_type,
671
+ resp_type
672
+ )
673
+
674
+ const result = await axios
675
+ .post(url, {
676
+ ...rest,
677
+ })
678
+ .then((res) => res.data)
641
679
 
642
- const result = await uploadPromise({
643
- url,
644
- formData: payLoad,
645
- })
646
680
  if (result.errcode) {
647
681
  if (result.errcode === 40001) {
648
682
  cache.reset()
@@ -650,7 +684,7 @@ module.exports = class Singleton {
650
684
  }
651
685
  throw new Error(`${result.errcode};${result.errmsg}`)
652
686
  }
653
- return result.img_info
687
+ return result.pic_file
654
688
  }
655
689
 
656
690
  getConfig() {
@@ -26,6 +26,10 @@ module.exports = class WeixinPay {
26
26
  return await this.pay.unifiedOrder(config)
27
27
  }
28
28
 
29
+ async checkRefund(payLoad) {
30
+ return await this.pay.refundQuery(payLoad)
31
+ }
32
+
29
33
  async getXMLBody(data) {
30
34
  return await getXMLBody(data, {
31
35
  limit: '1mb',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "q-koa",
3
- "version": "10.4.0",
3
+ "version": "10.5.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {