captcha-api.js
472 Bytes
/**
* Created by TaoHuang on 2016/12/12.
*/
'use strict';
const _ = require('lodash');
const CAPTCHA = require('../data/captcha.json');
const length = CAPTCHA.length - 1 || -1;
exports.gen = () => {
if (length !== -1) {
return Promise.resolve({
code: 200,
data: CAPTCHA[_.random(0, length)]
});
} else {
return Promise.reject({
code: 400,
message: '验证码错误'
});
}
};