captcha-service.js 719 Bytes
/**
 * Created by TaoHuang on 2016/7/1.
 */

'use strict';

const api = require('./captcha-api');

exports.generateCaptcha = () => {
    return api.gen().then((result) => {
        if (result.code === 200) {
            let codeStr = result.data.degrees.map((rotate) => {
                return (4 - rotate / 90 % 4) % 4;
            }).join('');

            return {
                code: 200,
                data: {
                    text: codeStr,
                    images: result.data.verifiedGraphicCode
                }
            };
        } else {
            return {
                code: 400,
                message: '生成二维码失败,请重新刷新!'
            };
        }
    });
};