Blame view

apps/passport/models/imgcheck.js 2.46 KB
陈轩 authored
1
'use strict';
郭成尧 authored
2
const PAGE = 'H5';
毕凯 authored
3
const logger = global.yoho.logger;
郭成尧 authored
4
const serviceAPI = global.yoho.ServiceAPI.ApiUrl;
yyq authored
5
const ApiUrl = global.yoho.API.ApiUrl;
htoooth authored
6
const config = global.yoho.config;
yyq authored
7 8
const sign = global.yoho.sign;
const querystring = require('querystring');
陈轩 authored
9
郭成尧 authored
10 11 12 13
module.exports = class extends global.yoho.BaseModel {
    constructor(ctx) {
        super(ctx);
    }
14
郭成尧 authored
15 16 17 18
    /**
     * 获取图片
     */
    gen(udid) {
陈峰 authored
19 20 21 22 23 24 25 26
        if (udid) {
            let params = {
                udid: udid,
                fromPage: PAGE,
                client_type: config.app,
                app_version: config.appVersion
            };
            const headers = {};
郭成尧 authored
27
陈峰 authored
28 29 30 31 32 33
            if (!global.isProduction && config.yohoVerifyUdid) {
                params.udid = global.yoho.verify.udid;
                params = global.yoho.sign.apiSign(params);
                const verifySign = global.yoho.verify ? global.yoho.verify.sign(params) : '';

                headers['x-yoho-verify'] = verifySign;
郭成尧 authored
34
            }
陈峰 authored
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
            const result = {
                code: 200,
                data: {
                    url: `${serviceAPI}passport/img-check?${querystring.stringify(params)}`
                },
                headers
            };

            return Promise.resolve(result);
        } else {
            return Promise.reject({
                code: 400,
                message: '生成二维码失败,请重新刷新!'
            });
        }
郭成尧 authored
50
    }
51
郭成尧 authored
52 53 54 55 56 57 58 59 60 61 62
    /**
     * 校验
     */
    check(udid, captcha) {
        return this.get({
            data: {
                method: 'app.verified.graphic',
                udid: udid,
                fromPage: PAGE,
                degrees: captcha
            }
毕凯 authored
63
        }).then(result => {
64
            logger.info(`app.verified.graphic result: ${JSON.stringify(result)}`);
毕凯 authored
65
            return result;
郭成尧 authored
66 67
        });
    }
郭成尧 authored
68 69 70 71

    /**
     * 是否需要验证码
     */
毕凯 authored
72
    isNeedImgCheck(udid) {
郭成尧 authored
73 74
        return this.get({
            api: global.yoho.ServiceAPI,
毕凯 authored
75 76 77 78 79 80 81 82
            url: 'smart/way',
            data: {
                udid: udid,
                fromPage: PAGE
            }
        }).then(result => {
            logger.info(`smart/way ${udid} result: ${JSON.stringify(result)}`);
            return result;
郭成尧 authored
83 84
        });
    }
yyq authored
85 86

    getRiskCheckImg(udid) {
yyq authored
87 88
        return Promise.resolve(`${ApiUrl}?${querystring.stringify(sign.apiSign({
            method: 'app.graphic.img',
yyq authored
89 90 91 92
            udid,
            fromPage: PAGE
        }))}`);
    }
陈轩 authored
93
};