robot-check.js
2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
'use strict';
const robotCheckService = require('../models/robot-check-service');
const captchaService = require('../../passport/controllers/captcha');
const simpleHeaderModel = require('../../../doraemon/models/simple-header');
const logger = global.yoho.logger;
const index = (req, res) => {
let remoteIp = req.yoho.clientIp || '';
logger.info(`limit remote ip: ${remoteIp}; ua: ${req.header('User-Agent')}; uid: ${req.user.uid}; reqId: ${req.reqID}`); // eslint-disable-line
return res.render('robot-check', {
module: '3party',
page: 'robot-check',
reqId: req.reqID,
simpleHeader: simpleHeaderModel.setSimpleHeaderData()
});
};
const check = (req, res, next) => {
if (req.session.apiRiskValidate && req.body.apiRiskValidate) {
return req.ctx(robotCheckService).verifyImgCheckRisk(req.yoho.udid, req.body.verifyCode).then(result => {
if (result.code === 200) {
return next();
} else {
logger.info('api risk img verify faild');
return res.json(result);
}
});
}
return captchaService.geeCheck(req, res, () => {
// 图形验证码关闭时通过极验证后解锁接口风控
if (req.session.apiRiskClear) {
delete req.session.apiRiskClear;
req.ctx(robotCheckService).verifyImgCheckRisk(req.yoho.udid, '1,2,3,4');
}
return next();
});
};
const img = captchaService.geeGenerate;
const isHuman = (req, res) => {
let remoteIp = req.yoho.clientIp;
if (remoteIp.indexOf(',') > 0) {
let arr = remoteIp.split(',');
remoteIp = arr[0];
}
const apiLimitValidate = req.session.apiLimitValidate || req.session.apiRiskValidate;
delete req.session.apiLimitValidate;
delete req.session.apiRiskValidate;
logger.warn('isHuman', remoteIp);
return req.ctx(robotCheckService).removeBlack(remoteIp, apiLimitValidate, req.headers.referer).then(() => {
return res.json({
code: 200
});
}).catch(() => {
return res.json({
code: 400
});
});
};
module.exports = {
index,
check,
isHuman,
img
};