XWWitPark/witpark_server/util/utils.js
2024-09-12 08:10:00 +08:00

36 lines
790 B
JavaScript

'use strict'
const random = require('string-random')
const validePhone = function(tel) {
const judgePhone = /^((0\d{2,3}-\d{7,8})|(1[3584]\d{9}))$/;
const st = new RegExp(judgePhone);
if (!st.test(tel)) {
return false
}
return true
}
const checkCode = async function(fastify, tel, code) {
const { redis } = fastify
const res = await redis.get(tel)
if (null === res) {
return {ec: -1, err: '验证码失效'}
}
console.log(res, code)
if (parseInt(res) !== parseInt(code)) {
return {ec: -2, err: '验证码不正确'}
}
return {ec: 0, err: ''}
}
const getRandomInt = function(max) {
return random(max, {numbers: true, letters: false})
}
module.exports = {
validePhone,
getRandomInt,
checkCode
}