防刷(单独版)
优质
小牛编辑
144浏览
2023-12-01
说明
函数说明:
- 主要检测用户是否是可疑用户或恶意用户,并弹出验证框。支持yy,duowan,4366域。现防刷方式分为 验证码 与 端机器码 方式。
- 验证码 方式主要用于浏览器、盒子大厅、游戏大厅等环境。 活动配置选择防刷方式为:防刷组件(后台计算签名)
- 端机器码 方式以前主要用于砸蛋客户端,但新版砸蛋已改用 验证码 方式,所以 端机器码 方式就不做详解了。
验证码 方式
引用:
<script type="text/javascript" src="http://gamesz.yy.com/s/jquery/jquery.js"></script>
<script type="text/javascript" src="http://f2e.duowan.com/s/lib/sdk/js/act/f2e.anti.js"></script>
调用方法:
- $.f2eAnti.init(options);
参数说明:
参数名 | 类型 | 说明 | 备注 |
---|---|---|---|
appId | int | 防刷ID,默认为2 | |
manual | boolean | 手动调用,默认为false | |
callback | function | 回调函数 |
脚本
<script>
//默认
$.f2eAnti.init();
//自定义
$.f2eAnti.init({
appId:14,
manual:true,
callback:function(){
alert(1)
}
});
</script>
Task3 处理方法
当调用 joinAndFinish.do 方法时,需要获取 cookie中的 webdtmid 与 webdtsg 的值,并组合成 josn 格式字符串。以下是参考代码:
<script>
/**
* json 转 string
* @param {obj} o json
* @example
**/
function json2str(o){
var arr = [];
var fmt = function(s) {
if (typeof s == 'object' && s != null) return json2str(s);
return /^(string|number)$/.test(typeof s) ? '"' + s + '"' : s;
}
for (var i in o) arr.push('"' + i + '":' + fmt(o[i]));
return "{" + arr.join(',') + "}";
}
/**
* 获取cookies
* @param {string}
* @example
**/
function dealCookie(name, value, options){
if (typeof value != 'undefined') { // name and value given, set cookie
options = options || {};
if (value === null) {
value = '';
options.expires = -1;
}
var expires = '';
if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
var date;
if (typeof options.expires == 'number') {
date = new Date();
date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
} else {
date = options.expires;
}
expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
}
var path = options.path ? '; path=' + options.path : '';
var domain = options.domain ? '; domain=' + options.domain : '';
var secure = options.secure ? '; secure' : '';
document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
} else { // only name given, get cookie
var cookieValue = null;
if (document.cookie) {
var cookies = document.cookie.split(';');
for (var i = 0, len = cookies.length; i < len; i++) {
var cookie = $.trim(cookies[i]);
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) == (name + '=')) {
try {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
}
catch (e) {
this.dealCookie(name, null);
cookieValue = null;
}
break;
}
}
}
return cookieValue;
}
}
/**
* ajax jsonp请求方法
* @param {string} url 请求地址
* @param {object} datas 参数对象
* @param {function} callname 回调函数的名字
* @param {function} fn 回调函数
* @example
**/
function getAjax(url,datas,callname,fn){
jQuery.ajax({
type : 'GET',
dataType : "jsonp",
jsonp:callname,
data: datas || "",
url : url,
timeout: 3000,
success : function(data){
fn && fn(data);
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert(url+' 请求出错!' );
}
});
}
/**
* 参加并完成任务
* @param {obj} option
* @param {function} fn
* @example
**/
function joinAndFinish(option, fn){
var pcid = dealCookie("webdtmid"), //获取cookie中的webdtmid、webdtsg值
key = dealCookie("webdtsg");
if(pcid && key){
option['choosen'] = json2str({"serialNo":pcid +"|"+key}); //json格式转字符串
}
getAjax('http://task3.game.duowan.com/task/joinAndFinish.do?', option, 'callback', fn);
}
</script>
效果图
2.端机器码 方式
已逐渐过渡到 验证码 方式,不再详解了。