使用极验【行为验证】实现人机交互验证(1)

4.二次验证

async SecondCheckGt() {

let res = await postCheckGt(this, {

challenge: this.geetest_challenge,

validate: this.geetest_validate,

seccode: this.geetest_seccode,

gt_server_status: this.gt_server_status

});

let {code, message} = res;

if (code !== 200) {

this.this.showErrTips = true;

this.errMessage = message;

}

return res;

},

5.校验手机号

// 校验手机号

checkTelephone() {

let phoneReg = “”;

if (this.global_num == “+86”) {

phoneReg = /1[3,4,5,6,7,8,9][0-9]{9}$/; // 验证电话号码正则

} else {

phoneReg = /^([0-9]+|0)$/; //手机号必须为数字

}

if (!phoneReg.test(this.telephone)) {

this.showErrTips = true;

this.errMessage = “请输入正确的手机号”;

return false;

}

return true;

},

6.获取手机验证码

//图形验证码是否正确&发送短信

sendMessage() {

this.newPhone = this.global_num + “-” + this.telephone;

return postSmsCode(this, {

phone: this.newPhone,

smscode_type: 2, // 2为注册,

geetest_challenge: this.geetest_challenge

}).then(res => {

let {message, code} = res;

if (code !== 200) {

this.showErrTips = true;

this.errMessage = message;

return false;

}

return true;

});

},

7.极验封装方法geetest.js

“v0.4.7 Geetest Inc.”;

(function (window) {

“use strict”;

if (typeof window === ‘undefined’) {

throw new Error(‘Geetest requires browser environment’);

}

var document = window.document;

var Math = window.Math;

var head = document.getElementsByTagName(“Head”)[0];

function _Object(obj) {

this._obj = obj;

}

_Object.prototype = {

_each: function (process) {

var _obj = this._obj;

for (var k in _obj) {

if (_obj.hasOwnProperty(k)) {

process(k, _obj[k]);

}

}

return this;

}

};

function Config(config) {

var self = this;

new _Object(config)._each(function (key, value) {

self[key] = value;

});

}

Config.prototype = {

api_server: ‘api.geetest.com’,

protocol: ‘https://’,

typePath: ‘/gettype.php’,

fallback_config: {

slide: {

static_servers: [“static.geetest.com”, “dn-staticdown.qbox.me”],

type: ‘slide’,

slide: ‘/static/js/geetest.0.0.0.js’

},

fullpage: {

static_servers: [“static.geetest.com”, “dn-staticdown.qbox.me”],

type: ‘fullpage’,

fullpage: ‘/static/js/fullpage.0.0.0.js’

}

},

_get_fallback_config: function () {

var self = this;

if (isString(self.type)) {

return self.fallback_config[self.type];

} else if (self.new_captcha) {

return self.fallback_config.fullpage;

} else {

return self.fallback_config.slide;

}

},

_extend: function (obj) {

var self = this;

new _Object(obj)._each(function (key, value) {

self[key] = value;

})

}

};

var isNumber = function (value) {

return (typeof value === ‘number’);

};

var isString = function (value) {

return (typeof value === ‘string’);

};

var isBoolean = function (value) {

return (typeof value === ‘boolean’);

};

var isObject = function (value) {

return (typeof value === ‘object’ && value !== null);

};

var isFunction = function (value) {

return (typeof value === ‘function’);

};

var MOBILE = /Mobi/i.test(navigator.userAgent);

var pt = MOBILE ? 3 : 0;

var callbacks = {};

var status = {};

var nowDate = function () {

var date = new Date();

var year = date.getFullYear();

var month = date.getMonth() + 1;

var day = date.getDate();

var hours = date.getHours();

var minutes = date.getMinutes();

var seconds = date.getSeconds();

if (month >= 1 && month <= 9) {

month = ‘0’ + month;

}

if (day >= 0 && day <= 9) {

day = ‘0’ + day;

}

if (hours >= 0 && hours <= 9) {

hours = ‘0’ + hours;

}

if (minutes >= 0 && minutes <= 9) {

minutes = ‘0’ + minutes;

}

if (seconds >= 0 && seconds <= 9) {

seconds = ‘0’ + seconds;

}

var currentdate = year + ‘-’ + month + ‘-’ + day + " " + hours + “:” + minutes + “:” + seconds;

return currentdate;

}

var random = function () {

return parseInt(Math.random() * 10000) + (new Date()).valueOf();

};

var loadScript = function (url, cb) {

var script = document.createElement(“script”);

script.charset = “UTF-8”;

script.async = true;

script.onerror = function () {

cb(true);

};

var loaded = false;

script.onload = script.onreadystatechange = function () {

if (!loaded &&

(!script.readyState ||

“loaded” === script.readyState ||

“complete” === script.readyState)) {

loaded = true;

setTimeout(function () {

cb(false);

}, 0);

}

};

script.src = url;

head.appendChild(script);

};

var normalizeDomain = function (domain) {

// special domain: uems.sysu.edu.cn/jwxt/geetest/

// return domain.replace(/^https?😕/|/.*$/g, ‘’); uems.sysu.edu.cn

return domain.replace(/^https?😕/|/$/g, ‘’); // uems.sysu.edu.cn/jwxt/geetest

};

var normalizePath = function (path) {

path = path.replace(//+/g, ‘/’);

if (path.indexOf(‘/’) !== 0) {

path = ‘/’ + path;

}

return path;

};

var normalizeQuery = function (query) {

if (!query) {

return ‘’;

}

var q = ‘?’;

new _Object(query)._each(function (key, value) {

if (isString(value) || isNumber(value) || isBoolean(value)) {

q = q + encodeURIComponent(key) + ‘=’ + encodeURIComponent(value) + ‘&’;

}

});

if (q === ‘?’) {

q = ‘’;

}

return q.replace(/&$/, ‘’);

};

var makeURL = function (protocol, domain, path, query) {

domain = normalizeDomain(domain);

var url = normalizePath(path) + normalizeQuery(query);

if (domain) {

url = protocol + domain + url;

}

return url;

};

var load = function (config, send, protocol, domains, path, query, cb) {

var tryRequest = function (at) {

var url = makeURL(protocol, domains[at], path, query);

loadScript(url, function (err) {

if (err) {

if (at >= domains.length - 1) {

cb(true);

// report gettype error

if (send) {

config.error_code = 508;

var url = protocol + domains[at] + path;

reportError(config, url);

}

} else {

tryRequest(at + 1);

}

} else {

cb(false);

}

});

};

tryRequest(0);

};

var jsonp = function (domains, path, config, callback) {

if (isObject(config.getLib)) {

config._extend(config.getLib);

callback(config);

return;

}

if (config.offline) {

callback(config._get_fallback_config());

return;

}

var cb = “geetest_” + random();

window[cb] = function (data) {

if (data.status == ‘success’) {

callback(data.data);

} else if (!data.status) {

callback(data);

} else {

callback(config._get_fallback_config());

}

window[cb] = undefined;

try {

delete window[cb];

} catch (e) {

}

};

load(config, true, config.protocol, domains, path, {

gt: config.gt,

callback: cb

}, function (err) {

if (err) {

callback(config._get_fallback_config());

}

});

};

var reportError = function (config, url) {

load(config, false, config.protocol, [‘monitor.geetest.com’], ‘/monitor/send’, {

time: nowDate(),

captcha_id: config.gt,

challenge: config.challenge,

pt: pt,

exception_url: url,

error_code: config.error_code

}, function (err) {})

}

var throwError = function (errorType, config) {

var errors = {

networkError: ‘网络错误’,

gtTypeError: ‘gt字段不是字符串类型’

};

if (typeof config.onError === ‘function’) {

config.onError(errors[errorType]);

} else {
自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。

深知大多数前端工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则几千的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!

因此收集整理了一份《2024年Web前端开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。

img

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上前端开发知识点,真正体系化!

由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!

如果你觉得这些内容对你有帮助,可以扫码获取!!(备注:前端)

最后

你要问前端开发难不难,我就得说计算机领域里常说的一句话,这句话就是『难的不会,会的不难』,对于不熟悉某领域技术的人来说,因为不了解所以产生神秘感,神秘感就会让人感觉很难,也就是『难的不会』;当学会这项技术之后,知道什么什么技术能做到什么做不到,只是做起来花多少时间的问题而已,没啥难的,所以就是『会的不难』。

我特地针对初学者整理一套前端学习资料分享给大家,戳这里即可领取

前端路线图

何学起的朋友,同时减轻大家的负担。**

[外链图片转存中…(img-Rqd2AhrU-1712596022001)]

[外链图片转存中…(img-Bkc2dgLe-1712596022001)]

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上前端开发知识点,真正体系化!

[外链图片转存中…(img-Oc83T8qd-1712596022002)]

由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!

如果你觉得这些内容对你有帮助,可以扫码获取!!(备注:前端)

最后

你要问前端开发难不难,我就得说计算机领域里常说的一句话,这句话就是『难的不会,会的不难』,对于不熟悉某领域技术的人来说,因为不了解所以产生神秘感,神秘感就会让人感觉很难,也就是『难的不会』;当学会这项技术之后,知道什么什么技术能做到什么做不到,只是做起来花多少时间的问题而已,没啥难的,所以就是『会的不难』。

我特地针对初学者整理一套前端学习资料分享给大家,戳这里即可领取

[外链图片转存中…(img-RPkBs8of-1712596022002)]

vue.js的36个技巧


  1. 1 ↩︎

  • 24
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值