腾讯QQ微博API接口获取微博内容(14)

// reset the length of content
        $this->size = strlen($this->doc);
        if ($this->size>0) $this->char = $this->doc[0];
    }

// restore noise to html content
    function restore_noise($text) {
        while(($pos=strpos($text, '___noise___'))!==false) {
            $key = '___noise___'.$text[$pos+11].$text[$pos+12].$text[$pos+13];
            if (isset($this->noise[$key]))
                $text = substr($text, 0, $pos).$this->noise[$key].substr($text, $pos+14);
        }
        return $text;
    }

function __toString() {
        return $this->root->innertext();
    }

function __get($name) {
        switch($name) {
            case 'outertext': return $this->root->innertext();
            case 'innertext': return $this->root->innertext();
            case 'plaintext': return $this->root->text();
        }
    }

// camel naming conventions
    function childNodes($idx=-1) {return $this->root->childNodes($idx);}
    function firstChild() {return $this->root->first_child();}
    function lastChild() {return $this->root->last_child();}
    function getElementById($id) {return $this->find("#$id", 0);}
    function getElementsById($id, $idx=null) {return $this->find("#$id", $idx);}
    function getElementByTagName($name) {return $this->find($name, 0);}
    function getElementsByTagName($name, $idx=-1) {return $this->find($name, $idx);}
    function loadFile() {$args = func_get_args();$this->load(call_user_func_array('file_get_contents', $args), true);}
}
?>

tqq.php

<?php
/*******************************************************************************
Version: 1.11 ($Rev: 175 $)
Website:
Author: S.C. Chen <admin@185.cm>
Acknowledge: Jose Solorzano ()
Contributions by:QQ交流群:89097023
    Yousuke Kumakura (Attribute filters)
    Vadim Voituk (Negative indexes supports of "find" method)
    Antcs (Constructor with automatically load contents either text or file/url)
Licensed under The MIT License
Redistributions of files must retain the above copyright notice.
*******************************************************************************/
//缓存时间,单位:秒
$t = 360;
if(!is_file('index.html')||(time()-filemtime('index.html'))>$t){
 //微博帐号
 $qq = 'kuaisubeian';
 //经过腾讯那个md5_3()加密后的密码
 $pwd = '624D3274815F2237817A7C62F42DD26A';
 $verifyURL = 'http://ptlogin2.qq.com/check?uin=@'.$qq.'&appid=46000101';
 $loginURL = 'http://ptlogin2.qq.com/login?';

 //获取验证码及第一次cookie
 $curl = curl_init($verifyURL);
 $cookie_jar = tempnam('.', 'cookie');
 curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
 curl_setopt($curl, CURLOPT_COOKIEJAR, $cookie_jar);
 $verifyCode = curl_exec($curl);
 curl_close($curl);
 $verifyCode = strtoupper(substr($verifyCode, 18, 4));
 //echo '验证码:'.$verifyCode;
 //echo '<hr />';
 // echo 'Cookies:'.$cookie_jar;
 // echo '<hr />';

 //发送登录请求并获取第二次cookie
 $loginURL .= 'u=@'.$qq.'&p='.md5($pwd.$verifyCode).'&verifycode='.$verifyCode.'&aid=46000101&u1=http%3A%2F%2Ft.qq.com&h=1&from_ui=1&fp=loginerroralert';
 //echo '登录地址:'.$loginURL;
 //echo '<hr />';
 $curl = curl_init($loginURL);
 curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
 curl_setopt($curl, CURLOPT_COOKIEJAR, $cookie_jar);
 curl_setopt($curl, CURLOPT_COOKIEFILE, $cookie_jar);
 curl_setopt($curl, CURLOPT_COOKIEJAR, $cookie_jar);
 $loginResult = curl_exec($curl);
 curl_close($curl);
 //echo '登录验证结果:'.$loginResult;
 //echo '<hr />';
       
 //获取第三次cookie
 $curl = curl_init('http://t.qq.com');
 curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
 curl_setopt($curl, CURLOPT_COOKIEJAR, $cookie_jar);
 curl_setopt($curl, CURLOPT_COOKIEFILE, $cookie_jar);
 curl_setopt($curl, CURLOPT_COOKIEJAR, $cookie_jar);
 $loginResult = curl_exec($curl);
 curl_close($curl);

 //第四次
 $curl = curl_init('http://t.qq.com/'.$qq.'/mine');
 curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
 curl_setopt($curl, CURLOPT_COOKIEJAR, $cookie_jar);
 curl_setopt($curl, CURLOPT_COOKIEFILE, $cookie_jar);
 curl_setopt($curl, CURLOPT_COOKIEJAR, $cookie_jar);
 $loginResult = curl_exec($curl);
 curl_close($curl);

 unlink($cookie_jar);
 file_put_contents('index.html',$loginResult);
}
include('cnz.php');
$html = file_get_html('index.html');
$talkList = $html->find('#talkList');
$lastTalk = $talkList[0];

$userName = $lastTalk->children(0)->children(1)->find('.userName');
$msgCnt = $lastTalk->children(0)->children(1)->find('.msgCnt');
$pubInfo =  $lastTalk->children(0)->children(1)->find('.pubInfo');

$userName = $userName[0]->plaintext;

$result = '';


//大于二则是转播

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/48a71be181fbc92c655ea1d0074b56d8.html