captcha-service.js 822 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}?imageView/2/w/240`
                }
            };
        } else {
            return {
                code: 400,
                message: '生成二维码失败,请重新刷新!',
                data: {
                    text: 'yoho9636'
                }
            };
        }
    });
};