前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >贴吧关注类-php

贴吧关注类-php

作者头像
用户2590762
发布2021-08-11 10:14:51
9100
发布2021-08-11 10:14:51
举报
文章被收录于专栏:Q青之家
代码语言:javascript
复制
<?php                                                                                           
/**
*author : 一千零一夜-龙辉QQ1790716272
*date:2020/03/28
*description:贴吧关注类
*parma: kw=需要关注的吧  bduss=登录贴吧之后的bduss
*
*
*/

class tbkw{
        protected $kw = '';
        protected $bduss = '';
        protected $head = array(
            'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
'Accept-Encoding: gzip, deflate, br',
'Accept-Language: zh-CN,zh;q=0.9',
'Cache-Control: max-age=0',
'Connection: keep-alive',
    'Host: tieba.baidu.com',
'Sec-Fetch-Dest: document',
'Sec-Fetch-Mode: navigate',
'Sec-Fetch-Site: none',
'Sec-Fetch-User: ?1',
'Upgrade-Insecure-Requests: 1',
'User-Agent: Mozilla/5.0 (Linux; Android 4.4.2; Nexus 4 Build/KOT49H) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.114 Mobile Safari/537.36',
            );
    public function __construct($kw=null,$bduss=null){
        
        $this->kw = urlencode($kw);
        $this->bduss =$bduss;
        
    }
    public function like(){
$kwurl = 'https://tieba.baidu.com/mo/q/favolike?fid='.$this->fid().'&kw='.$this->kw.'&itb_tbs='.$this->tbs().'&uid='.$this->tbs();
//$kwurl = 'https://tieba.baidu.com/mo/q/favolike?fid=16386&kw=%E6%81%8B%E7%88%B1&itb_tbs='.$this->tbs().'&uid='.$this->tbs();
  $result = $this->geturl($kwurl,$this->bduss,$this->head);
  $results = json_decode($result,true);
  
  if($results['no']==0){
      
      $data = '关注'.urldecode($this->kw).'吧成功';
      
  }elseif($results['no']==20001){
       $data = '参数不全';
       
  }else{
      
      $data = '出现了未知的错误';
  }
  return $data;

    }
    
    protected function fid(){
    
        $tbinfo = json_decode($this->geturl('http://tieba.baidu.com/f/commit/share/fnameShareApi?ie=utf-8&fname='.$this->kw),true);
        $fid = $tbinfo['data']['fid'];
        return $fid ;
    }
    protected function tbs(){
        $tbs = json_decode($this->geturl('http://tieba.baidu.com/dc/common/tbs',$this->bduss),true);
        
        return $tbs['tbs'];
    }
    
    protected function geturl($url,$bduss=null,$head=null){
            $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_HEADER, 0);            
        if(!is_null($bduss))curl_setopt($ch, CURLOPT_COOKIE , 'BDUSS='.$bduss);        
        if(!is_null($head))curl_setopt($ch, CURLOPT_HTTPHEADER, $head);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);        // 对认证证书来源的检查
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);        // 使用自动跳转
        curl_setopt($ch, CURLOPT_AUTOREFERER, 1);           // 自动设置Referer
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3);        // 设置等待时间
        curl_setopt($ch, CURLOPT_TIMEOUT, 1);              // 设置cURL允许执行的最长秒数
        $res = curl_exec($ch);
        curl_close($ch);
        return $res;
        }
}    
if($_GET['kw'] && $_GET['bduss']){
$tbkw = new tbkw($_GET['kw'],$_GET['bduss']);

print_r($tbkw->like());
}elseif($_GET[‘bduss’]){
    $tbkw = new tbkw('云签到',$_GET['bduss']);

print_r($tbkw->like());
}
/*代码编写完毕!就是如此简单——.——*/                                                                   
?>

版权属于:青城

本文链接:https://cloud.tencent.com/developer/article/1859273

转载时须注明出处及本声明

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2021-07-27,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档