q-koa 13.3.3 → 13.3.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.
@@ -23,6 +23,20 @@ exports.clear = async (ctx) => {
23
23
  const key =
24
24
  ctx.request.method === 'POST' ? ctx.request.body.key : ctx.query.key
25
25
 
26
+ if (!key) return ctx.ERROR('缺key')
27
+ app.cache.set(key, '')
28
+ app.service.cache.init({ app, appName, model: key })
29
+ const url = `${app.appConfig.ip}:${app.appConfig.port}`
30
+ app.service.log.push({ app, message: `${url}缓存${key}清除` })
31
+
32
+ ctx.SUCCESS('ok')
33
+ }
34
+
35
+ exports.init = async (ctx) => {
36
+ const { app, appName } = getAppByCtx(ctx)
37
+ const key =
38
+ ctx.request.method === 'POST' ? ctx.request.body.key : ctx.query.key
39
+
26
40
  if (!key) return ctx.ERROR('缺key')
27
41
  app.cache.set(key, '')
28
42
 
@@ -1,4 +1,10 @@
1
+ const axios = require('axios')
2
+
1
3
  exports.init = async ({ app, appName, model = '' }) => {
4
+ const hasCache = app.cache.get(model) || ''
5
+ if (!hasCache) {
6
+ console.log('hear clear cache', model)
7
+ }
2
8
  const cacheModel = app.appConfig.cacheModel.filter((m) =>
3
9
  model ? m === model : true
4
10
  )
@@ -15,4 +21,28 @@ exports.init = async ({ app, appName, model = '' }) => {
15
21
  return promiseFn(model)
16
22
  })
17
23
  )
24
+
25
+ if (model && app.appConfig.appName && app.appConfig.productionHost) {
26
+ const ipHost = (
27
+ Array.isArray(app.appConfig.productionHost)
28
+ ? app.appConfig.productionHost
29
+ : [app.appConfig.productionHost]
30
+ )
31
+ .filter((url) => {
32
+ return url.match(
33
+ /^(http:\/\/|https:\/\/)?(\d{1,3}\.){3}\d{1,3}:\d{1,5}/
34
+ )
35
+ })
36
+ .filter((host) =>
37
+ app.appConfig.ip ? !host.includes(app.appConfig.ip) : false
38
+ )
39
+
40
+ Promise.all(
41
+ ipHost.map((host) => {
42
+ return axios
43
+ .get(`${host}/${app.appConfig.appName}/cache/init?key=${model}`)
44
+ .then((res) => res.data)
45
+ })
46
+ )
47
+ }
18
48
  }
@@ -1012,7 +1012,6 @@ exports.mp_pay = async (ctx) => {
1012
1012
  pay_config = 'weixin_pay',
1013
1013
  profit_sharing = 'N',
1014
1014
  } = ctx.request.body
1015
-
1016
1015
  if (price === 0) throw new Error('价格不能为0')
1017
1016
 
1018
1017
  if (type === 'H5-WEIXIN') {
@@ -1030,8 +1029,14 @@ exports.mp_pay = async (ctx) => {
1030
1029
  }
1031
1030
  const appConfig = getConfig(app)
1032
1031
 
1033
- const { mchId, key, partner_key } = await appConfig.getObject(pay_config)
1032
+ const {
1033
+ mchId,
1034
+ key,
1035
+ pay_key: _pay_key,
1036
+ partner_key,
1037
+ } = await appConfig.getObject(pay_config)
1034
1038
 
1039
+ const pay_key = _pay_key || key || appName
1035
1040
  const { is_dev, site_host } = await appConfig.getObject('base')
1036
1041
  // 公众号支付用 服务号 appid,其他用小程序 appid
1037
1042
  const app_id =
@@ -1042,7 +1047,7 @@ exports.mp_pay = async (ctx) => {
1042
1047
  const wxpay = WXPay({
1043
1048
  appid: app_id,
1044
1049
  mch_id: mchId,
1045
- partner_key: key.length > 10 ? key : partner_key, // 微信商户平台API密钥
1050
+ partner_key, // 微信商户平台API密钥
1046
1051
  })
1047
1052
 
1048
1053
  const userDetail =
@@ -1053,13 +1058,12 @@ exports.mp_pay = async (ctx) => {
1053
1058
  const out_trade_no = _out_trade_no
1054
1059
  ? _out_trade_no
1055
1060
  : prefix
1056
- ? `${key.length > 10 ? appName : key}_${prefix}-${order_id}_${type}`
1057
- : `${key.length > 10 ? appName : key}_${order_id}_${type}`
1061
+ ? `${pay_key}_${prefix}-${order_id}_${type}`
1062
+ : `${pay_key}_${order_id}_${type}`
1058
1063
 
1059
1064
  const notify_url = `https://${
1060
1065
  site_host || 'api.kuashou.com'
1061
1066
  }/${appName}/weixin/notify`
1062
-
1063
1067
  const prePayResult = await wxpay.getBrandWCPayRequestParamsSync({
1064
1068
  openid: userDetail.openid,
1065
1069
  body: name,
@@ -1113,6 +1117,12 @@ exports.mp_pay = async (ctx) => {
1113
1117
  return ctx.SUCCESS('ok')
1114
1118
  }
1115
1119
  if (payResult.return_msg) {
1120
+ consoleconsole.log({
1121
+ mchId,
1122
+ key,
1123
+ pay_key: _pay_key,
1124
+ partner_key,
1125
+ })
1116
1126
  throw new Error(
1117
1127
  payResult.return_msg === '签名错误,请检查后再试'
1118
1128
  ? payResult.return_msg + '(商户号/APIv2/关联)'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "q-koa",
3
- "version": "13.3.3",
3
+ "version": "13.3.5",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {