63 lines
1.6 KiB
JavaScript
63 lines
1.6 KiB
JavaScript
|
'use strict'
|
||
|
|
||
|
const { validePhone, getRandomInt } = require("../util/utils");
|
||
|
|
||
|
|
||
|
const swiper = async function (request, reply) {
|
||
|
const query = request.query
|
||
|
console.log(query['id'] === undefined);
|
||
|
|
||
|
const images = [
|
||
|
{
|
||
|
link: 'http://127.0.0.1:3000/v1/api/',
|
||
|
url: 'http://127.0.0.1:3000/static/deng1.png'
|
||
|
},
|
||
|
{
|
||
|
link: 'http://127.0.0.1:3000/v1/api/',
|
||
|
url: 'http://127.0.0.1:3000/static/deng1.png'
|
||
|
},
|
||
|
{
|
||
|
link: 'http://127.0.0.1:3000/v1/api/',
|
||
|
url: 'http://127.0.0.1:3000/static/deng1.png'
|
||
|
},
|
||
|
{
|
||
|
link: 'http://127.0.0.1:3000/v1/api/',
|
||
|
url: 'http://127.0.0.1:3000/static/deng1.png'
|
||
|
},
|
||
|
{
|
||
|
link: 'http://127.0.0.1:3000/v1/api/',
|
||
|
url: 'http://127.0.0.1:3000/static/deng1.png'
|
||
|
}
|
||
|
]
|
||
|
const data = {
|
||
|
errno: 0,
|
||
|
banner : images
|
||
|
}
|
||
|
return data
|
||
|
}
|
||
|
|
||
|
const generatorCode = async function (fastify, request, reply) {
|
||
|
const query = request.query
|
||
|
const tel = query['tel']
|
||
|
if (!validePhone(tel)) {
|
||
|
console.log('tel is valid', tel)
|
||
|
return { 'errno': 600, 'message': '手机号不正确'}
|
||
|
}
|
||
|
|
||
|
const code = getRandomInt(4)
|
||
|
console.log('code=', code)
|
||
|
const { redis } = fastify
|
||
|
const res = await redis.set(tel, code, 'EX', 300)
|
||
|
if (res !== 'OK') {
|
||
|
return { 'errno': 601, 'message': res}
|
||
|
}
|
||
|
console.log('验证码:', code, "5分钟有效")
|
||
|
console.log(res)
|
||
|
return { 'errno': 0, 'message': ''}
|
||
|
}
|
||
|
|
||
|
module.exports = {
|
||
|
swiper,
|
||
|
generatorCode
|
||
|
}
|