refresh-captcha.js 806 字节
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
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)

DCloud_JSON's avatar
DCloud_JSON 已提交
21 22
  const { deviceId, platform } = this.getUniversalClientInfo()

23 24 25 26 27 28 29 30 31 32
  const {
    scene
  } = params
  if (!(Object.values(CAPTCHA_SCENE).includes(scene))) {
    throw {
      errCode: ERROR.INVALID_PARAM
    }
  }
  return this.uniCaptcha.refresh({
    deviceId,
DCloud_JSON's avatar
DCloud_JSON 已提交
33 34
    scene,
    uniPlatform: platform
35 36
  })
}