代码拉取完成,页面将自动刷新
import {
getSmsCode
} from '../../share/index'
import {
PublicErrorCode
} from '../utils/config'
export default async function ({
mobile,
code,
type,
templateId
}) {
if (!mobile) {
return {
code: PublicErrorCode.PARAM_REQUIRED,
messageValues: {
param: this.t('mobile')
}
}
}
if (!code) {
code = getSmsCode()
}
if (!type) {
return {
code: PublicErrorCode.PARAM_REQUIRED,
messageValues: {
param: this.t('verify-code-type')
}
}
}
const config = this._getConfig()
let smsConfig = config && config.service && config.service.sms
if (!smsConfig) {
throw new Error(this.t('config-param-required', {
param: 'service.sms'
}))
}
smsConfig = Object.assign({
codeExpiresIn: 300
}, smsConfig)
const {
name,
smsKey,
smsSecret,
codeExpiresIn
} = smsConfig
let action
switch (type) {
case 'login':
action = this.t('login')
break
default:
action = this.t('verify-mobile')
break
}
try {
const data = {
name,
code,
action,
expMinute: '' + Math.round(codeExpiresIn / 60)
}
if (name) {
data.name = name
}
await uniCloud.sendSms({
smsKey,
smsSecret,
phone: mobile,
templateId: templateId || 'uniID_code',
data
})
const setCodeRes = await this.setVerifyCode({
mobile,
code,
expiresIn: codeExpiresIn,
type
})
if (setCodeRes.code >= 0) {
return setCodeRes
}
return {
code: 0,
msg: ''
}
} catch (e) {
console.error(e)
return {
code: 50301
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。