php下用curl做的一个更新人人网状态的代码
2010-07-10 11:20 by hackerzhou20100821最新更新:豆瓣/人人/BBS/开心/嘀咕/网易微博/新浪微博状态更新PHP代码终结版
参考了网上别人的实现,发现若干bug,自己重新写了下。发现人人网还真是猥琐,经常改变接口以及post的参数,广告么又一大堆,没有开心网清爽,要不是看在有那么多同学都用的份上我早就不用了。。。 代码还可以在诸如wp-to-twitter之类的博客->twitter的插件中使用,这样就能同时更新到renren以及twitter了。 curl还算是比较简单而且功能强大,熟悉了之后可以用来做很多东西。
<?php
function updateRenRen($item) {
$renren_username='人人网登录用户名';
$renren_password='人人网登录密码';
$cookie_jar = tempnam('./tmp','cookie');
$ch = curl_init();
curl_setopt($ch,CURLOPT_COOKIEJAR,$cookie_jar);
curl_setopt($ch,CURLOPT_URL,"http://passport.renren.com/PLogin.do");
curl_setopt($ch,CURLOPT_POST,TRUE);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,TRUE);
curl_setopt($ch,CURLOPT_POSTFIELDS,'email='.urlencode($renren_username).'&password='.urlencode($renren_password).'&autoLogin=true&origURL=http%3A%2F%2Fwww.renren.com%2FHome.do&domain=renren.com');
curl_setopt($ch,CURLOPT_RETURNTRANSFER,TRUE);
$str = curl_exec($ch);
$pattern = "/get_check:'([^']+)'/";
preg_match($pattern,$str,$matches);
$get_check = $matches[1];
curl_close($ch);
$ch1 = curl_init();
curl_setopt($ch1,CURLOPT_URL,"http://status.renren.com/doing/update.do");
curl_setopt($ch1,CURLOPT_COOKIEFILE,$cookie_jar);
curl_setopt($ch1,CURLOPT_POST,TRUE);
curl_setopt($ch1,CURLOPT_POSTFIELDS,'c='.urlencode($item).'&raw='.urlencode($item).'&isAtHome=1&publisher_form_ticket='.$get_check.'&requestToken='.$get_check);
curl_setopt($ch1,CURLOPT_FOLLOWLOCATION,TRUE);
curl_setopt($ch1,CURLOPT_REFERER,'http://status.renren.com/ajaxproxy.htm');
curl_setopt($ch1,CURLOPT_RETURNTRANSFER,TRUE);
$ret = curl_exec($ch1);
curl_close($ch1);
$ret = json_decode($ret,TRUE);
echo $ret['msg']."\n";
}
updateRenRen("test php update renren status.");
?>
2010-08-21 09:53
请看我今天发布的最终版:豆瓣/人人/BBS/开心/嘀咕/网易微博/新浪微博状态更新PHP代码终结版
2010-08-20 03:16
朋友,这个现在是不是已 经不行了,我刚试了下,不成功啊