cshenfu
2023-06-14 de93aa62c83d6afb9f70cd5a22838375db0a8cbc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const {
  CAPTCHA_SCENE
} = require('../../common/constants')
const {
  ERROR
} = require('../../common/error')
 
/**
 * 刷新图形验证码
 * @tutorial https://uniapp.dcloud.net.cn/uniCloud/uni-id-pages.html#refresh-captcha
 * @param {Object} params
 * @param {String} params.scene   图形验证码使用场景
 * @returns
 */
module.exports = async function (params = {}) {
  const schema = {
    scene: 'string'
  }
  this.middleware.validate(params, schema)
 
  const deviceId = this.getUniversalClientInfo().deviceId
  const {
    scene
  } = params
  if (!(Object.values(CAPTCHA_SCENE).includes(scene))) {
    throw {
      errCode: ERROR.INVALID_PARAM
    }
  }
  return this.uniCaptcha.refresh({
    deviceId,
    scene
  })
}