安静
PHP技术博客

100821 php之腾讯微博 Api 修改版

自从前2天添加了 wordpress 腾讯微博插件以后,整个网站内容看上去又多了很多,今天无意间看到了 其实很早就有人在网上共享了 查看腾讯微博的php  api代码,在这里 提供我修改后的api ,仅供参考学习.

类需要的 函数库 点击这里下载

我修改的代码如下 你直接复制代码进  tqq.php     即可

md5_3()函数 腾讯的 密码加密:

function md5_3($str) {

return strtoupper(md5(md5(md5($str,true),true)));
}

tqq.php 我的修改版本

<?php

/*******************************************************************************

Version: 1.11 ($Rev: 175 $)

Website: http://www.115.co

Author: S.C. Chen <admin@185.cm>

Acknowledge: Jose Solorzano (http://www.115.co/)

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.

*******************************************************************************/

//缓存时间,单位:秒

//  blog.80aj.com  可乐烟 做了下封装

getQQWeiBoApp ( “kuaisubeian”, “624D3274815F2237817A7C62F42DD26A”, 10 ); //帐号 密码  需要显示的数量

function getQQWeiBoApp($weiboName, $weibopwd, $needshow, $t = 1) {

if (! is_file ( ‘index.html’ ) || (time () – filemtime ( ‘index.html’ )) > $t) {

//微博帐号

$qq = $weiboName;

//经过腾讯那个md5_3()加密后的密码

$pwd = $weibopwd;

$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];

for($i = 0; $i < $needshow; $i ++) {

$userName = $lastTalk->children ( $i )

->children ( 1 )

->find ( ‘.userName’ );

$msgCnt = $lastTalk->children ( $i )

->children ( 1 )

->find ( ‘.msgCnt’ );

$pubInfo = $lastTalk->children ( $i )

->children ( 1 )

->find ( ‘.pubInfo’ );

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

$result = ”;

//大于二则是转播

echo “<br>”;

if (count ( $msgCnt ) < 10) {

$pi = $pubInfo [0]->find ( ‘.left’ );

$result = $userName . $msgCnt [0]->plaintext . ‘<p style=”text-align:center;”> <span style=”display:none”></span></p>

<title>blog.80aj.com</title><meta http-equiv=”content-type” content=”text/html; charset=UTF-8″ /><span style=”font-style: italic; color: rgb(238, 29, 36);”>’ . $pi [0]->children ( 0 )->plaintext . ‘ ‘ . $pi [0]->children ( 1 )->plaintext . ‘</span>’;

} else {

$pi = $pubInfo [1]->find ( ‘.left’ );

$result = $userName . $msgCnt [0]->plaintext . ‘[‘ . $msgCnt [1]->plaintext . ‘] <span style=”font-style: italic; color: rgb(149, 158, 135);”>’ . $pi [0]->plaintext . ‘</span>’;

}

echo $result . “<br>”;

}

}

?>

赞(0) 打赏
未经允许不得转载:AJ's Blog » 100821 php之腾讯微博 Api 修改版
分享到: 更多 (0)

评论 4

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
  1. #-49

    有空的话,也来整一个!

    zen cart11年前 (2010-08-21)
  2. :0可以的 研究下也不错的 tcp的3层通信 7次握手

    可 乐烟11年前 (2010-08-21)
  3. #-48

    这个有可用的价值,呵呵

    3G建站程序10年前 (2010-11-01)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏