q-koa 10.8.0 → 10.8.2

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.
@@ -19,7 +19,10 @@ exports.password = {
19
19
  defaultValue: '',
20
20
  sortOrder: 2,
21
21
  set: function (value) {
22
- this.setDataValue('password', md5(value))
22
+ if (value.length === 32) {
23
+ this.setDataValue('password', md5(value))
24
+ } else {
25
+ }
23
26
  },
24
27
  }
25
28
 
@@ -1,6 +1,11 @@
1
1
  const Alipay = require('../../services/alipay')
2
2
 
3
3
  const { getAppByCtx, getConfig } = require('q-koa')
4
+
5
+ const path = require('path')
6
+ const fs = require('fs')
7
+ const AlipaySdk = require('alipay-sdk').default
8
+
4
9
  exports.h5_pay = async (ctx) => {
5
10
  const { app, appName } = getAppByCtx(ctx)
6
11
 
@@ -66,3 +71,70 @@ exports.notify = async (ctx) => {
66
71
  ctx.body = 'success'
67
72
  }
68
73
  }
74
+
75
+ exports.mp_pay = async (ctx) => {
76
+ const { app, appName } = getAppByCtx(ctx)
77
+ const appConfig = getConfig(app)
78
+ const { is_dev, site_host } = await appConfig.getObject('base')
79
+ const {
80
+ app_id,
81
+ alipay_public_key,
82
+ key,
83
+ is_sandbox,
84
+ ...rest
85
+ } = await appConfig.getObject('alipay')
86
+
87
+ const {
88
+ name,
89
+ out_trade_no: _out_trade_no,
90
+ prefix = '',
91
+ order_id,
92
+ type,
93
+ price,
94
+ is_admin = false,
95
+ buyer_id = '2088722007804916',
96
+ } = ctx.request.body
97
+
98
+ const gateway = is_sandbox
99
+ ? `https://openapi.alipaydev.com/gateway.do`
100
+ : 'https://openapi.alipay.com/gateway.do'
101
+
102
+ const notify_url = `https://${
103
+ site_host || 'api.kuashou.com'
104
+ }/${appName}/alipay/notify`
105
+
106
+ const alipaySdk = new AlipaySdk({
107
+ appId: app_id,
108
+ signType: 'RSA2', // 签名算法,默认 RSA2
109
+ gateway, // 支付宝网关地址 ,沙箱环境下使用时需要修改
110
+ alipayPublicKey: alipay_public_key,
111
+ privateKey: fs.readFileSync(
112
+ path.resolve(
113
+ __dirname,
114
+ `${process.cwd()}/app/${appName}/plugins/alipay/private-key.pem`
115
+ ),
116
+ 'ascii'
117
+ ),
118
+ notify_url,
119
+ })
120
+
121
+ const out_trade_no = _out_trade_no
122
+ ? _out_trade_no
123
+ : prefix
124
+ ? `${key.length > 10 ? appName : key}_${prefix}-${order_id}_${type}`
125
+ : `${key.length > 10 ? appName : key}_${order_id}_${type}`
126
+
127
+ const res = await alipaySdk.exec('alipay.trade.create', {
128
+ bizContent: {
129
+ out_trade_no,
130
+ total_amount: is_admin || is_dev ? 1 : Math.round(price * 100),
131
+ subject: name,
132
+ buyer_id,
133
+ },
134
+ })
135
+ if (res.code !== '10000') {
136
+ throw new Error(res.subMsg)
137
+ }
138
+ const { code, msg, tradeNo, ...other } = res
139
+ return ctx.SUCCESS(tradeNo)
140
+ }
@@ -1,4 +1,4 @@
1
- const { lodash, getAppByCtx, getConfig } = require('q-koa')
1
+ const { lodash, getAppByCtx, getConfig, moment } = require('q-koa')
2
2
 
3
3
  const axios = require('axios')
4
4
  const OAuth = require('wechat-oauth')
@@ -484,6 +484,16 @@ exports.mp_login = async (ctx) => {
484
484
  user: tokenResult,
485
485
  })
486
486
 
487
+ if (
488
+ result.updated_at &&
489
+ moment().diff(moment(result.updated_at), 'hours') > 24
490
+ ) {
491
+ app.model.user.upsert({
492
+ id: result.id,
493
+ updated_at: moment(),
494
+ })
495
+ }
496
+
487
497
  return ctx.SUCCESS({
488
498
  token,
489
499
  user: app.appConfig.loginData
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "q-koa",
3
- "version": "10.8.0",
3
+ "version": "10.8.2",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -16,6 +16,7 @@
16
16
  "author": "",
17
17
  "license": "ISC",
18
18
  "dependencies": {
19
+ "alipay-sdk": "^3.2.0",
19
20
  "@alicloud/pop-core": "^1.7.9",
20
21
  "@sigodenjs/wechatpay": "^2.1.1",
21
22
  "ali-oss": "^6.11.2",