q-koa 10.7.1 → 10.7.4

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.
@@ -32,13 +32,15 @@ exports.header = {
32
32
  }
33
33
  },
34
34
  get: function () {
35
+ const value = this.getDataValue('header')
35
36
  try {
36
- const value = this.getDataValue('header')
37
37
  const dataValue =
38
38
  typeof value === 'object' ? value || {} : JSON.parse(value)
39
39
  return dataValue
40
40
  } catch {
41
- return {}
41
+ return {
42
+ text: value,
43
+ }
42
44
  }
43
45
  },
44
46
  extra: {
@@ -56,17 +58,21 @@ exports.body = {
56
58
  const dataValue = typeof value === 'object' ? value : JSON.parse(value)
57
59
  this.setDataValue('body', dataValue)
58
60
  } catch {
59
- throw new Error('body值不合法')
61
+ this.setDataValue('body', {
62
+ text: value,
63
+ })
60
64
  }
61
65
  },
62
66
  get: function () {
67
+ const value = this.getDataValue('body')
63
68
  try {
64
- const value = this.getDataValue('body')
65
69
  const dataValue =
66
70
  typeof value === 'object' ? value || {} : JSON.parse(value)
67
71
  return dataValue
68
72
  } catch {
69
- return {}
73
+ return {
74
+ text: value,
75
+ }
70
76
  }
71
77
  },
72
78
  extra: {
@@ -29,7 +29,8 @@ exports.type = {
29
29
  'rich-text',
30
30
  'date',
31
31
  'datetime',
32
- 'list'
32
+ 'list',
33
+ 'json'
33
34
  ),
34
35
  comment: 'type类型',
35
36
  allowNull: true,
@@ -50,6 +51,15 @@ exports.value = {
50
51
  switch (type) {
51
52
  case 'switch':
52
53
  return Boolean(Number(this.getDataValue('value')))
54
+ case 'json':
55
+ try {
56
+ const value = JSON.parse(this.getDataValue('value'))
57
+ return value
58
+ } catch (e) {
59
+ return {
60
+ text: this.getDataValue('value'),
61
+ }
62
+ }
53
63
  case 'list':
54
64
  try {
55
65
  const value = JSON.parse(this.getDataValue('value'))
@@ -47,23 +47,6 @@ exports.refund = async ({
47
47
  }/${appName}/toutiao/refund_notify`,
48
48
  }
49
49
 
50
- const signResult = (params, salt) => {
51
- var skip_arr = ['thirdparty_id', 'app_id', 'sign']
52
- var paramArray = new Array()
53
- for (var k in params) {
54
- if (skip_arr.indexOf(k) != -1) {
55
- continue
56
- }
57
- if (params[k] == '') {
58
- continue
59
- }
60
- paramArray.push(params[k])
61
- }
62
- paramArray.push(salt)
63
- paramArray.sort()
64
- var signStr = paramArray.join('&')
65
- return md5(signStr)
66
- }
67
50
  const res = await axios
68
51
  .post(url, {
69
52
  ...data,
@@ -862,6 +862,85 @@ exports.pc_pay = async (ctx) => {
862
862
  return ctx.SUCCESS(result)
863
863
  }
864
864
 
865
+ exports.app_pay = async (ctx) => {
866
+ const { app, appName } = getAppByCtx(ctx)
867
+ const {
868
+ name,
869
+ order_id,
870
+ price,
871
+ return_url,
872
+ prefix = '',
873
+ type,
874
+ out_trade_no: _out_trade_no,
875
+ is_admin = false,
876
+ config = 'weixin_mp',
877
+ pay_config = 'weixin_pay',
878
+ } = ctx.request.body
879
+
880
+ if (price === 0) throw new Error('价格不能为0')
881
+
882
+ if (
883
+ !ctx.request[`${appName}-user`] ||
884
+ !ctx.request[`${appName}-user`].open_user
885
+ ) {
886
+ throw new Error('请先微信登录')
887
+ }
888
+ const appConfig = getConfig(app)
889
+
890
+ const { mchId, key, partner_key, appId: appid } = await appConfig.getObject(
891
+ pay_config
892
+ )
893
+
894
+ if (!appid) throw new Error(`appId不能存在`)
895
+
896
+ const { is_dev, site_host } = await appConfig.getObject('base')
897
+
898
+ const wxpay = WXPay({
899
+ appid,
900
+ mch_id: mchId,
901
+ partner_key: key.length > 10 ? key : partner_key, // 微信商户平台API密钥
902
+ })
903
+
904
+ const out_trade_no = _out_trade_no
905
+ ? _out_trade_no
906
+ : prefix
907
+ ? `${key.length > 10 ? appName : key}_${prefix}-${order_id}_${type}`
908
+ : `${key.length > 10 ? appName : key}_${order_id}_${type}`
909
+
910
+ const notify_url = `https://${
911
+ site_host || 'api.kuashou.com'
912
+ }/${appName}/weixin/notify`
913
+
914
+ const result = await wxpay.getBrandWCPayRequestParamsSync({
915
+ trade_type: 'APP',
916
+ body: name,
917
+ detail: '公众号支付测试',
918
+ out_trade_no,
919
+ total_fee: is_admin || is_dev ? 1 : Math.round(price * 100),
920
+ spbill_create_ip: '192.168.2.210',
921
+ notify_url,
922
+ })
923
+
924
+ const {
925
+ nonceStr: nonce_str,
926
+ package: prepay_id,
927
+ paySign: sign,
928
+ timeStamp: timestamp,
929
+ } = result
930
+
931
+ const returnObj = {
932
+ appid,
933
+ partnerid: mchId,
934
+ nonce_str,
935
+ prepay_id,
936
+ sign,
937
+ return_url,
938
+ timestamp,
939
+ }
940
+
941
+ return ctx.SUCCESS(returnObj)
942
+ }
943
+
865
944
  exports.mp_pay = async (ctx) => {
866
945
  const { app, appName } = getAppByCtx(ctx)
867
946
  const {
@@ -18,7 +18,15 @@ exports.getName = (config) => (type) => {
18
18
 
19
19
  exports.getList = (config) => (type) => {
20
20
  const obj = config.find((i) => i.code === type)
21
- if (!obj) throw new Error(`找不到${type}相关设置`)
21
+ if (!obj) {
22
+ if (process.env.NODE_ENV === 'production') {
23
+ throw new Error(`找不到${type}相关设置`)
24
+ } else {
25
+ console.error(`找不到${type}相关设置`)
26
+ }
27
+ return []
28
+ }
29
+
22
30
  const list = config.filter((i) => i.parent_id === obj.id)
23
31
  return list
24
32
  }
@@ -72,7 +80,14 @@ exports.getObject = (config, app) => async (type) => {
72
80
  }
73
81
  }
74
82
  }
75
- if (!flag) throw new Error(`找不到${type}相关设置`)
83
+ if (!flag) {
84
+ if (process.env.NODE_ENV === 'production') {
85
+ throw new Error(`找不到${type}相关设置`)
86
+ } else {
87
+ console.error(`找不到${type}相关设置`)
88
+ }
89
+ return temObj
90
+ }
76
91
  return temObj
77
92
  }
78
93
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "q-koa",
3
- "version": "10.7.1",
3
+ "version": "10.7.4",
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.4",
55
+ "weixin-pay-fork": "^1.0.5",
56
56
  "node-uuid": "^1.4.8",
57
57
  "sha1": "^1.1.1",
58
58
  "redis": "^4.0.3",