q-koa 13.8.9 → 13.8.11

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.
@@ -29,13 +29,6 @@ exports.copyOther = async (ctx) => {
29
29
  const list = await app.model.setting.findAll()
30
30
 
31
31
  const findType = list.find((item) => item.code === type)
32
- if (findType && findType.parent_id) {
33
- await app.model.setting.upsert({
34
- id: findType.id,
35
- value: copyType.value,
36
- })
37
- return ctx.SUCCESS('ok')
38
- }
39
32
  const copyList = data.filter((item) => item.parent_id === copyType.id)
40
33
 
41
34
  if (!findType) {
@@ -52,24 +45,33 @@ exports.copyOther = async (ctx) => {
52
45
  }
53
46
  })
54
47
  )
55
- } else {
56
- await app.model.setting.destroy({
57
- where: {
58
- parent_id: findType.id,
59
- },
60
- })
48
+ return ctx.SUCCESS('ok')
49
+ }
61
50
 
62
- await app.model.setting.bulkCreate(
63
- copyList.map((item) => {
64
- const { parent, id, ...rest } = item
65
- return {
66
- ...rest,
67
- parent_id: findType.id,
68
- }
69
- })
70
- )
51
+ if (findType.parent_id) {
52
+ await app.model.setting.upsert({
53
+ id: findType.id,
54
+ value: copyType.value,
55
+ })
56
+ return ctx.SUCCESS('ok')
71
57
  }
72
58
 
59
+ await app.model.setting.destroy({
60
+ where: {
61
+ parent_id: findType.id,
62
+ },
63
+ })
64
+
65
+ await app.model.setting.bulkCreate(
66
+ copyList.map((item) => {
67
+ const { parent, id, ...rest } = item
68
+ return {
69
+ ...rest,
70
+ parent_id: findType.id,
71
+ }
72
+ })
73
+ )
74
+
73
75
  ctx.SUCCESS('ok')
74
76
  }
75
77
 
@@ -127,7 +127,7 @@ const hmacSha256 = (data, secret) => {
127
127
  return crypto.createHmac('sha256', secret).update(data).digest('hex')
128
128
  }
129
129
  const uploadPromise = async (url, formData) => {
130
- const response = await axios.post(url, formData, {
130
+ const response = await wxAxios.post(url, formData, {
131
131
  headers: formData.getHeaders(),
132
132
  })
133
133
  return response.data
@@ -145,7 +145,10 @@ const wxHttpsAgent = new https.Agent({
145
145
  rejectUnauthorized: true,
146
146
  })
147
147
 
148
- axios.defaults.httpsAgent = wxHttpsAgent
148
+ // 微信专用 axios 实例,避免修改全局 axios.defaults 影响其他模块
149
+ const wxAxios = axios.create({
150
+ httpsAgent: wxHttpsAgent,
151
+ })
149
152
 
150
153
  module.exports = class Singleton {
151
154
  static _instanceMap = new Map()
@@ -177,7 +180,7 @@ module.exports = class Singleton {
177
180
  }
178
181
  const url = util.format(getAccessTokenUrl, grant_type, appid, secrect)
179
182
 
180
- const result = await axios.get(url).then((res) => res.data)
183
+ const result = await wxAxios.get(url).then((res) => res.data)
181
184
  const { errcode, errmsg, access_token } = result
182
185
 
183
186
  if (errcode) {
@@ -191,7 +194,7 @@ module.exports = class Singleton {
191
194
  async getExpress() {
192
195
  const access_token = await this.getAccessToken()
193
196
  const url = util.format(getExpressUrl, access_token)
194
- const result = await axios.post(url).then((res) => res.data)
197
+ const result = await wxAxios.post(url).then((res) => res.data)
195
198
  if (result.errcode) {
196
199
  if (result.errcode === 40001) {
197
200
  cache.clear()
@@ -231,7 +234,7 @@ module.exports = class Singleton {
231
234
  service,
232
235
  }
233
236
 
234
- const result = await axios.post(url, formatOptions).then((res) => res.data)
237
+ const result = await wxAxios.post(url, formatOptions).then((res) => res.data)
235
238
  if (result.errcode) {
236
239
  if (result.errcode === 40001) {
237
240
  cache.clear()
@@ -263,7 +266,7 @@ module.exports = class Singleton {
263
266
  username,
264
267
  }
265
268
 
266
- const result = await axios.post(url, formatOptions).then((res) => res.data)
269
+ const result = await wxAxios.post(url, formatOptions).then((res) => res.data)
267
270
  if (result.errcode) {
268
271
  if (result.errcode === 40001) {
269
272
  cache.clear()
@@ -285,7 +288,7 @@ module.exports = class Singleton {
285
288
  username,
286
289
  role,
287
290
  }
288
- const result = await axios.post(url, formatOptions).then((res) => res.data)
291
+ const result = await wxAxios.post(url, formatOptions).then((res) => res.data)
289
292
  if (result.errcode) {
290
293
  if (result.errcode === 40001) {
291
294
  cache.clear()
@@ -335,7 +338,7 @@ module.exports = class Singleton {
335
338
  closeShare: 1,
336
339
  closeKf: 1,
337
340
  }
338
- const result = await axios.post(url, formatOptions).then((res) => res.data)
341
+ const result = await wxAxios.post(url, formatOptions).then((res) => res.data)
339
342
  if (result.errcode) {
340
343
  if (result.errcode === 40001) {
341
344
  cache.clear()
@@ -366,7 +369,7 @@ module.exports = class Singleton {
366
369
  start,
367
370
  limit,
368
371
  }
369
- const result = await axios.post(url, formatOptions).then((res) => res.data)
372
+ const result = await wxAxios.post(url, formatOptions).then((res) => res.data)
370
373
  if (result.errcode) {
371
374
  if (result.errcode === 40001) {
372
375
  cache.clear()
@@ -380,7 +383,7 @@ module.exports = class Singleton {
380
383
  async getPhoneNumber(code) {
381
384
  const access_token = await this.getAccessToken()
382
385
  const url = util.format(getPhoneNumberUrl, access_token)
383
- const result = await axios.post(url, { code }).then((res) => res.data)
386
+ const result = await wxAxios.post(url, { code }).then((res) => res.data)
384
387
  if (result.errcode) {
385
388
  if (result.errcode === 40001) {
386
389
  cache.clear()
@@ -405,7 +408,7 @@ module.exports = class Singleton {
405
408
  : '',
406
409
  }
407
410
 
408
- const result = await axios.post(url, payLoad).then((res) => res.data)
411
+ const result = await wxAxios.post(url, payLoad).then((res) => res.data)
409
412
 
410
413
  if (result.errcode) {
411
414
  if (result.errcode === 40001) {
@@ -421,7 +424,7 @@ module.exports = class Singleton {
421
424
  const access_token = await this.getAccessToken()
422
425
  const url = util.format(queryUrlLinkUrl, access_token)
423
426
 
424
- const result = await axios
427
+ const result = await wxAxios
425
428
  .post(url, {
426
429
  url_link,
427
430
  })
@@ -458,7 +461,7 @@ module.exports = class Singleton {
458
461
  is_permanent: true,
459
462
  }
460
463
 
461
- const result = await axios.post(url, payLoad).then((res) => res.data)
464
+ const result = await wxAxios.post(url, payLoad).then((res) => res.data)
462
465
 
463
466
  if (result.errcode) {
464
467
  if (result.errcode === 40001) {
@@ -486,7 +489,7 @@ module.exports = class Singleton {
486
489
  },
487
490
  }
488
491
 
489
- const result = await axios.post(url, payLoad).then((res) => res.data)
492
+ const result = await wxAxios.post(url, payLoad).then((res) => res.data)
490
493
 
491
494
  if (result.errcode) {
492
495
  if (result.errcode === 40001) {
@@ -512,7 +515,7 @@ module.exports = class Singleton {
512
515
  }
513
516
  const creatuuid = uuid.v1()
514
517
 
515
- const bufferResult = await axios
518
+ const bufferResult = await wxAxios
516
519
  .post(url, payLoad, {
517
520
  responseType: 'arraybuffer',
518
521
  })
@@ -548,7 +551,7 @@ module.exports = class Singleton {
548
551
  : '',
549
552
  }
550
553
 
551
- const bufferResult = await axios
554
+ const bufferResult = await wxAxios
552
555
  .post(url, payLoad, {
553
556
  responseType: 'arraybuffer',
554
557
  })
@@ -579,7 +582,7 @@ module.exports = class Singleton {
579
582
  }
580
583
  }),
581
584
  }
582
- const result = await axios.post(url, formatOptions).then((res) => res.data)
585
+ const result = await wxAxios.post(url, formatOptions).then((res) => res.data)
583
586
  if (result.errcode) {
584
587
  if (result.errcode === 40001) {
585
588
  cache.clear()
@@ -593,7 +596,7 @@ module.exports = class Singleton {
593
596
  async handleMessage(options) {
594
597
  const access_token = await this.getAccessToken()
595
598
  const url = util.format(handleMessageUrl, access_token)
596
- const result = await axios.post(url, options).then((res) => res.data)
599
+ const result = await wxAxios.post(url, options).then((res) => res.data)
597
600
  if (result.errcode) {
598
601
  if (result.errcode === 40001) {
599
602
  cache.clear()
@@ -611,7 +614,7 @@ module.exports = class Singleton {
611
614
  }
612
615
  const access_token = await this.getAccessToken()
613
616
  const url = util.format(handleTypingUrl, access_token)
614
- const result = await axios.post(url, options).then((res) => res.data)
617
+ const result = await wxAxios.post(url, options).then((res) => res.data)
615
618
  if (result.errcode) {
616
619
  if (result.errcode === 40001) {
617
620
  cache.clear()
@@ -628,7 +631,7 @@ module.exports = class Singleton {
628
631
  const access_token = await this.getAccessToken()
629
632
  const url = util.format(uploadFile, access_token, 'image')
630
633
  const fullUrl = imgUrl.startsWith('//') ? `http:${imgUrl}` : imgUrl
631
- const stream = (await axios.get(fullUrl, { responseType: 'stream' })).data
634
+ const stream = (await wxAxios.get(fullUrl, { responseType: 'stream' })).data
632
635
  const formData = new FormData()
633
636
  formData.append('media', stream)
634
637
  const uploadResult = await uploadPromise(url, formData)
@@ -645,7 +648,7 @@ module.exports = class Singleton {
645
648
  async invokeService(payLoad) {
646
649
  const access_token = await this.getAccessToken()
647
650
  const url = util.format(serviceMarketUrl, access_token)
648
- const result = await axios
651
+ const result = await wxAxios
649
652
  .post(url, {
650
653
  ...payLoad,
651
654
  })
@@ -663,7 +666,7 @@ module.exports = class Singleton {
663
666
  async createOrder(payLoad) {
664
667
  const access_token = await this.getAccessToken()
665
668
  const url = util.format(createOrderUrl, access_token)
666
- const result = await axios
669
+ const result = await wxAxios
667
670
  .post(url, {
668
671
  ...payLoad,
669
672
  })
@@ -682,7 +685,7 @@ module.exports = class Singleton {
682
685
  async getOrder(payLoad) {
683
686
  const access_token = await this.getAccessToken()
684
687
  const url = util.format(getOrderUrl, access_token)
685
- const result = await axios
688
+ const result = await wxAxios
686
689
  .post(url, {
687
690
  ...payLoad,
688
691
  })
@@ -701,7 +704,7 @@ module.exports = class Singleton {
701
704
  async refundOrder(payLoad) {
702
705
  const access_token = await this.getAccessToken()
703
706
  const url = util.format(refundOrderUrl, access_token)
704
- const result = await axios
707
+ const result = await wxAxios
705
708
  .post(url, {
706
709
  ...payLoad,
707
710
  })
@@ -721,7 +724,7 @@ module.exports = class Singleton {
721
724
  const access_token = await this.getAccessToken()
722
725
  const url = util.format(addGoodUrl, access_token)
723
726
  console.log('payLoad', payLoad)
724
- const result = await axios
727
+ const result = await wxAxios
725
728
  .post(url, {
726
729
  ...payLoad,
727
730
  })
@@ -741,7 +744,7 @@ module.exports = class Singleton {
741
744
  const access_token = await this.getAccessToken()
742
745
  const url = util.format(getCategoryUrl, access_token)
743
746
 
744
- const result = await axios
747
+ const result = await wxAxios
745
748
  .post(url, {
746
749
  ...payLoad,
747
750
  })
@@ -760,7 +763,7 @@ module.exports = class Singleton {
760
763
  const access_token = await this.getAccessToken()
761
764
  const url = util.format(getBrandListUrl, access_token)
762
765
 
763
- const result = await axios
766
+ const result = await wxAxios
764
767
  .post(url, {
765
768
  ...payLoad,
766
769
  })
@@ -779,7 +782,7 @@ module.exports = class Singleton {
779
782
  const access_token = await this.getAccessToken()
780
783
  const url = util.format(getShipTemplateUrl, access_token)
781
784
 
782
- const result = await axios
785
+ const result = await wxAxios
783
786
  .post(url, {
784
787
  ...payLoad,
785
788
  })
@@ -798,7 +801,7 @@ module.exports = class Singleton {
798
801
  const access_token = await this.getAccessToken()
799
802
  const url = util.format(uploadShipUrl, access_token)
800
803
 
801
- const result = await axios
804
+ const result = await wxAxios
802
805
  .post(url, {
803
806
  ...payLoad,
804
807
  })
@@ -817,7 +820,7 @@ module.exports = class Singleton {
817
820
  const access_token = await this.getAccessToken()
818
821
  const url = util.format(uploadPreShipUrl, access_token)
819
822
 
820
- const result = await axios
823
+ const result = await wxAxios
821
824
  .post(url, {
822
825
  ...payLoad,
823
826
  })
@@ -836,7 +839,7 @@ module.exports = class Singleton {
836
839
  const access_token = await this.getAccessToken()
837
840
  const url = util.format(getShipOrderListUrl, access_token)
838
841
 
839
- const result = await axios
842
+ const result = await wxAxios
840
843
  .post(url, {
841
844
  ...payLoad,
842
845
  })
@@ -862,7 +865,7 @@ module.exports = class Singleton {
862
865
  resp_type
863
866
  )
864
867
 
865
- const result = await axios
868
+ const result = await wxAxios
866
869
  .post(url, {
867
870
  ...rest,
868
871
  })
@@ -882,7 +885,7 @@ module.exports = class Singleton {
882
885
  const access_token = await this.getAccessToken()
883
886
  const url = util.format(setMsgJumpPathUrl, access_token)
884
887
 
885
- const result = await axios
888
+ const result = await wxAxios
886
889
  .post(url, {
887
890
  ...payLoad,
888
891
  })
@@ -901,7 +904,7 @@ module.exports = class Singleton {
901
904
  const access_token = await this.getAccessToken()
902
905
  const url = util.format(getDeliveryListUrl, access_token)
903
906
 
904
- const result = await axios
907
+ const result = await wxAxios
905
908
  .post(url, {
906
909
  ...payLoad,
907
910
  })
@@ -920,7 +923,7 @@ module.exports = class Singleton {
920
923
  const access_token = await this.getAccessToken()
921
924
  const url = util.format(getUserPortraitUrl, access_token)
922
925
 
923
- const result = await axios
926
+ const result = await wxAxios
924
927
  .post(url, {
925
928
  ...payLoad,
926
929
  })
@@ -955,7 +958,7 @@ module.exports = class Singleton {
955
958
  )
956
959
  }
957
960
 
958
- const result = await axios
961
+ const result = await wxAxios
959
962
  .post(url, {
960
963
  ...payLoad,
961
964
  })
@@ -977,7 +980,7 @@ module.exports = class Singleton {
977
980
  const access_token = await this.getAccessToken()
978
981
  const url = util.format(getCommentInfoUrl, commentId, access_token)
979
982
 
980
- const result = await axios.get(url).then((res) => res.data)
983
+ const result = await wxAxios.get(url).then((res) => res.data)
981
984
  if (result.errcode) {
982
985
  if (result.errcode === 40001) {
983
986
  cache.clear()
@@ -995,7 +998,7 @@ module.exports = class Singleton {
995
998
  const access_token = await this.getAccessToken()
996
999
  const url = util.format(createActivityUrl, access_token)
997
1000
 
998
- const result = await axios.get(url).then((res) => res.data)
1001
+ const result = await wxAxios.get(url).then((res) => res.data)
999
1002
  if (result.errcode) {
1000
1003
  if (result.errcode === 40001) {
1001
1004
  cache.clear()
@@ -1062,7 +1065,7 @@ module.exports = class Singleton {
1062
1065
  if (!postData.template_info.parameter_list.length) {
1063
1066
  throw new ServiceError('?parameter_list length 0')
1064
1067
  }
1065
- const result = await axios.post(url, postData).then((res) => res.data)
1068
+ const result = await wxAxios.post(url, postData).then((res) => res.data)
1066
1069
  if (result.errcode) {
1067
1070
  if (result.errcode === 40001) {
1068
1071
  cache.clear()
@@ -1083,7 +1086,7 @@ module.exports = class Singleton {
1083
1086
  }) {
1084
1087
  const weixinLoginUrl = `https://api.weixin.qq.com/sns/jscode2session?appid=${this.config.appid}&secret=${this.config.secrect}&js_code=${code}&grant_type=authorization_code`
1085
1088
 
1086
- const weixinResult = await axios.get(weixinLoginUrl).then((res) => res.data)
1089
+ const weixinResult = await wxAxios.get(weixinLoginUrl).then((res) => res.data)
1087
1090
 
1088
1091
  const { session_key } = weixinResult
1089
1092
 
@@ -1119,7 +1122,7 @@ module.exports = class Singleton {
1119
1122
  const pay_sig = hmacSha256(`${uri}&${JSON.stringify(signData)}`, app_key)
1120
1123
 
1121
1124
  const url = util.format(requestUrl, access_token, pay_sig)
1122
- const result = await axios.post(url, signData).then((res) => res.data)
1125
+ const result = await wxAxios.post(url, signData).then((res) => res.data)
1123
1126
  if (result.errcode) {
1124
1127
  if (result.errcode === 40001) {
1125
1128
  cache.clear()
@@ -1145,7 +1148,7 @@ module.exports = class Singleton {
1145
1148
  const pay_sig = hmacSha256(`${uri}&${JSON.stringify(signData)}`, app_key)
1146
1149
 
1147
1150
  const url = util.format(requestUrl, access_token, pay_sig)
1148
- const result = await axios.post(url, signData).then((res) => res.data)
1151
+ const result = await wxAxios.post(url, signData).then((res) => res.data)
1149
1152
  if (result.errcode) {
1150
1153
  if (result.errcode === 40001) {
1151
1154
  cache.clear()
@@ -1171,7 +1174,7 @@ module.exports = class Singleton {
1171
1174
  const pay_sig = hmacSha256(`${uri}&${JSON.stringify(signData)}`, app_key)
1172
1175
 
1173
1176
  const url = util.format(requestUrl, access_token, pay_sig)
1174
- const result = await axios.post(url, signData).then((res) => res.data)
1177
+ const result = await wxAxios.post(url, signData).then((res) => res.data)
1175
1178
  if (result.errcode) {
1176
1179
  if (result.errcode === 40001) {
1177
1180
  cache.clear()
@@ -1186,7 +1189,7 @@ module.exports = class Singleton {
1186
1189
  const access_token = await this.getAccessToken()
1187
1190
  const url = util.format(b2bPreStoreUrl, access_token)
1188
1191
 
1189
- const result = await axios
1192
+ const result = await wxAxios
1190
1193
  .post(url, {
1191
1194
  retail_info_list: list,
1192
1195
  })
@@ -1216,7 +1219,7 @@ module.exports = class Singleton {
1216
1219
  const pay_sig = hmacSha256(`${uri}&${JSON.stringify(signData)}`, app_key)
1217
1220
 
1218
1221
  const url = util.format(requestUrl, access_token, pay_sig)
1219
- const result = await axios.post(url, signData).then((res) => res.data)
1222
+ const result = await wxAxios.post(url, signData).then((res) => res.data)
1220
1223
  if (result.errcode) {
1221
1224
  if (result.errcode === 40001) {
1222
1225
  cache.clear()
@@ -1231,7 +1234,7 @@ module.exports = class Singleton {
1231
1234
  const access_token = await this.getAccessToken()
1232
1235
  const url = util.format(b2bSendMessageUrl, access_token)
1233
1236
 
1234
- const result = await axios
1237
+ const result = await wxAxios
1235
1238
  .post(url, {
1236
1239
  type,
1237
1240
  to_user_list,
@@ -11,7 +11,10 @@ const wxHttpsAgent = new https.Agent({
11
11
  rejectUnauthorized: true,
12
12
  })
13
13
 
14
- axios.defaults.httpsAgent = wxHttpsAgent
14
+ // 微信专用 axios 实例,避免修改全局 axios.defaults 影响其他模块
15
+ const wxAxios = axios.create({
16
+ httpsAgent: wxHttpsAgent,
17
+ })
15
18
  const { lodash } = require('q-koa')
16
19
  const getAccessTokenUrl =
17
20
  'https://api.weixin.qq.com/cgi-bin/token?grant_type=%s&appid=%s&secret=%s'
@@ -65,7 +68,7 @@ module.exports = class Singleton {
65
68
  }
66
69
  const url = util.format(getAccessTokenUrl, grant_type, appid, secrect)
67
70
 
68
- const result = await axios.get(url).then((res) => res.data)
71
+ const result = await wxAxios.get(url).then((res) => res.data)
69
72
  const { errcode, errmsg, access_token } = result
70
73
 
71
74
  if (errcode) {
@@ -79,7 +82,7 @@ module.exports = class Singleton {
79
82
  async getOpenList() {
80
83
  const access_token = await this.getAccessToken()
81
84
  const url = util.format(getOpenListUrl, access_token)
82
- const result = await axios.post(url).then((res) => res.data)
85
+ const result = await wxAxios.post(url).then((res) => res.data)
83
86
  if (result.errcode) {
84
87
  if (result.errcode === 40001) {
85
88
  cache.clear()
@@ -93,7 +96,7 @@ module.exports = class Singleton {
93
96
  async getUserInfo(openid) {
94
97
  const access_token = await this.getAccessToken()
95
98
  const url = util.format(getUserInfoUrl, access_token, openid)
96
- const result = await axios.post(url).then((res) => res.data)
99
+ const result = await wxAxios.post(url).then((res) => res.data)
97
100
  if (result.errcode) {
98
101
  if (result.errcode === 40001) {
99
102
  cache.clear()
@@ -113,7 +116,7 @@ module.exports = class Singleton {
113
116
  })
114
117
  const access_token = await this.getAccessToken()
115
118
  const url = util.format(getUserInfoListUrl, access_token)
116
- const result = await axios
119
+ const result = await wxAxios
117
120
  .post(url, {
118
121
  user_list,
119
122
  })
@@ -140,7 +143,7 @@ module.exports = class Singleton {
140
143
  }),
141
144
  }
142
145
 
143
- const result = await axios.post(url, formatOptions).then((res) => res.data)
146
+ const result = await wxAxios.post(url, formatOptions).then((res) => res.data)
144
147
  if (result.errcode) {
145
148
  if (result.errcode === 40001) {
146
149
  cache.clear()
@@ -154,7 +157,7 @@ module.exports = class Singleton {
154
157
  async getTemplate() {
155
158
  const access_token = await this.getAccessToken()
156
159
  const url = util.format(getTemplateUrl, access_token)
157
- const result = await axios.post(url).then((res) => res.data)
160
+ const result = await wxAxios.post(url).then((res) => res.data)
158
161
  if (result.errcode) {
159
162
  if (result.errcode === 40001) {
160
163
  cache.clear()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "q-koa",
3
- "version": "13.8.9",
3
+ "version": "13.8.11",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {