黄聪:URL推广系统防作弊

要实现的功能:

1、注册用户登录以后可以获取到个人私人唯一的一个推广链接,通过主动传播带来的注册用户全部计入该ID名下;
2、其中与该ID相同cookies或者同IP的注册量全部作为作弊处理(也就是说不计入该ID名下,被带来的新ID本身是没有影响的)
3、累计推广用户1人以上5人以下送E币若干(每人累计见表如下)

推广人数 E币
1人 300
2人 300
3人 300
4人 300
5人 300

 

下面是实现方法:

1、已登录状态生成推广链接并记录主推广id作为的cookie:

setcookie("friend_invite_check",$uid,time()+86400,"/");//生成推广链接后的checkcookie 防止同cookie注册
        $invite = M("FriendInvite");
$re = $invite->where("uid = $uid")->find();
        if(!$re){//没有数据则写入,生成推广链接。
        $ip=get_client_ip();
            $data['uid']=$uid;
            $data['token']=md5($uid."http://hcsem.com");
            $data['create_time']=time();
            $data['cip']=$ip;
        $res = $invite->add($data);
            }
        $ref = $invite->where("uid = $uid")->find();
    //echo "<span style='display:none'>http://".$_SERVER["HTTP_HOST"].'/Jihuo/invite/uid/'.$uid.'/token/'.$ref['token']."</span>";

2、进入推广链接,进入后记录一个住推广id到friend_invite如果这一步没有成功后面的推广是无效滴,记录成功后,不管在哪一个入口注册都会记录到推广成功数据库:

public function invite(){
    $input = new Input();
    $token = $input->get('token');
    $uid = $input->get('uid');
 
    $uinfo =$this->uinfo();
    $suid = $uinfo['id'];
    //echo $uinfo['id'];
    //9b3d8191bc595c18b90674be92cbb08c
    //f331f65dd41b4cf79c3e4c95a76b3145
    $invite = M("FriendInvite");
    $re = $invite->where("uid = $uid")->find();
    //dump($re);
    if($re['token']!=$token) $this->error('来路不正确请检查!');
    setcookie("friend_invite",$uid,time()+86400,"/");
    //redirect("/Jihuo");
    //$this->display('jihuoye:index');
    $this->index();
 
    }

注册成功后增加接口,判断用户状态写入到数据库:

1: 成功

2:和主推广同ip不同电脑

3:和住推广不同ip同电脑 

4:和主推广同ip同电脑

5:已经通过推广注册过一次的人同电脑同ip

6:已经通过推广注册过一次的人同ip不同电脑

7:已经通过推广注册过一次的人不同ip同电脑。

public function friend_invite($sentid,$sendusername){
    //$uid = $this->getUserinfo('id');
    $uid = $_COOKIE['friend_invite'];//主推广id
    if(!$uid){
        return ;
    }
    import('ORG.Util.String');
    $invite = M("FriendInvite");
    $invitelist = M("FriendInviteList");
    $chickid = $_COOKIE['friend_invite_check'];//本机登录id
    $chickregid = $_COOKIE['friend_invite_check_reg'];
    $ip=get_client_ip();
    $re = $invite->where("uid = $uid")->find();
    $rrrrid = $re['id'];//OID
    $checktong = $invitelist->where("id = $chickregid and oid = $rrrrid")->find();//判断本机cookie是否已经通过推广注册过。
    $checktip = $invitelist->where("byqip = '$ip' and oid = $rrrrid")->find();//判断已通过推广链接注册的重复注册。
    if($re['cip']!=$ip){//不同ip的写入
        $data['oid']=$re['id'];
        $data['uid']=$sentid;//注册的id
        $data['username']=$sendusername;
        $data['byqip']=$ip;
        $data['byqregtime']=time();
        if($chickid!=$uid){//和住推广不同cookie
        if($checktong && $checktip){//和主推广不同ip,不同cookie,如果有注册过
        $data['status']=5;//已经通过推广注册过一次,同cookie 同ip
        }else if($checktip && !$checktong){
        $data['status']=6;//已经通过推广注册过一次,同ip 不同cookie
            }else if($checktong && !$checktip){
                $data['status']=7;//已经通过推广注册过一次,不同同ip 同cookie
                }else{
                $data['status']=1;
                    }
        }else{
        $data['status']=3;//和主推广,不同ip 同cookie
            }
 
        }else{
        $data['oid']=$re['id'];
        $data['uid']=$sentid;//注册的id
        $data['username']=$sendusername;
        $data['byqip']=$ip;
        $data['byqregtime']=time();
        if($chickid!=$uid){
        $data['status']=2;//和主推广同ip不同cookie
        }else{
        $data['status']=4;//和主推广同ip同cookie
            }
            }
        //dump($data);
    $ll = $invitelist->add($data);
    if($ll){//写入后更新主推广人信息
        //$checkregid = $invitelist->where("id = $ll")->find();
        setcookie("friend_invite_check_reg",$ll,time()+86400,"/");//生成推广链接后的checkcookie 防止同cookie注册重复注册
        $count = $invitelist->where("status=1 and oid=$rrrrid")->count();
        //echo $invitelist->getLastSql();
        //exit;
        //$count=7; test
        if($count==3 && !$re['key']){
        $randStr = String::randstring(16,5,'');
        $data1['key']= $randStr;
        $dkey['come_from']=1;
        $dkey['promotion_code']=$randStr;
        $dkey['code_create_time']=time();
        $dkey['remark']="2测推广好友赠送";
        M('ElectrumPromotion')->add($dkey);
        }
        $rel = $invite->where("id = $rrrrid")->find();
        if($count > $rel['invite']){
        if($count>0 && $count <=5){
        $data1['electurm']=$rel['electurm']+300;
            }else if($count>5 && $count <=10){
            $data1['electurm']=$rel['electurm']+200;
                }else if($count>10 && $count <=15){
            $data1['electurm']=$rel['electurm']+150;
                }else if($count>15 && $count <=20){
            $data1['electurm']=$rel['electurm']+100;
                }else if($count>20 && $count <=29){
            $data1['electurm']=$rel['electurm']+50;
                }else if($count==30){
                $data1['electurm']=$rel['electurm']+1800;
                    }
        $data1['invite']=$rel['invite']+1;
        }
        $data1['id']=$rrrrid;
        $data1['lastupdatetime']=time();
        $invite->save($data1);
 
        //dump($count);
        }
    //dump($re);
    //$data['']
 
    }

 

你可能感兴趣的:(黄聪:URL推广系统防作弊)