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

'use strict';

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

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}` +
                            `?imageView2/2/w/240/q/70/watermark/2/text/${uuid.v4()}/fontsize/120/dissolve/10`
                }
            };
        } else {
            return {
                code: 400,
                message: '生成二维码失败,请重新刷新!',
                data: {
                    text: 'yoho9636'
                }
            };
        }
    });
};