'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 }