当前位置: 移动技术网 > IT编程>开发语言>PHP > php采用curl模仿登录人人网发布动态的方法

php采用curl模仿登录人人网发布动态的方法

2018年07月13日  | 移动技术网IT编程  | 我要评论

本文实例讲述了php采用curl模仿登录人人网发布动态的方法。分享给大家供大家参考。具体实现方法如下:

说到php中模仿登录很多人第一时间会想到curl函数系列了,这个没错本例子也是使用curl模仿登录之后再进行动态发布,原理也简单我们只要抓取人人网的登录信息,然后再由curl post登录数据上去就可以了。

具体代码如下:

复制代码 代码如下:
$rconfig = pdo_fetch("select * from ".tablename("edutwo_renren")." where weid = :weid",array(':weid'=>$_w['weid']));

$cookie_file = dirname(__file__)."/renren.cookie";
$login_url = 'http://passport.renren.com/plogin.do';
$post_fields['email'] = $rconfig['rusername'];
$post_fields['password'] = $rconfig['rpassword'];
$post_fields['origurl'] = 'http%3a%2f%2fhome.renren.com%2fhome.do';
$post_fields['domain'] = 'renren.com';

$ch = curl_init($login_url);
curl_setopt($ch, curlopt_useragent, 'mozilla/5.0 (windows; u; windows nt 5.1; zh-cn; rv:1.9.1.5) gecko/20091102 firefox/3.5.5');
curl_setopt($ch, curlopt_header, 0);
curl_setopt($ch, curlopt_returntransfer, 1);
curl_setopt($ch, curlopt_maxredirs, 1);
curl_setopt($ch, curlopt_followlocation, 1);
curl_setopt($ch, curlopt_autoreferer, 1);
curl_setopt($ch, curlopt_post, 1);
curl_setopt($ch, curlopt_postfields, $post_fields);
curl_setopt($ch, curlopt_cookiejar, $cookie_file);
$content = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
//var_dump($info);exit;
//匹配用户的id
$send_url='http://www.renren.com/home';
$ch = curl_init($send_url);
curl_setopt($ch, curlopt_header, 0);
curl_setopt($ch, curlopt_returntransfer, 1);
curl_setopt($ch, curlopt_cookiefile, $cookie_file);
curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);

//$uid = "305115027";
//获取token和rtk
$send_url=$info['redirect_url'];
$ch = curl_init($send_url);
curl_setopt($ch, curlopt_header, 0);
curl_setopt($ch, curlopt_returntransfer, 1);
curl_setopt($ch, curlopt_cookiefile, $cookie_file);
$tmp = curl_exec($ch);
curl_close($ch);
preg_match_all("/get_check:'(.*?)',get_check_x:'(.*?)',/is",$tmp,$arr);
preg_match_all("/'ruid':'(.*?)',/is",$tmp,$utmp);
//var_dump($utmp);exit;
$token = $arr[1][0];//1121558104
$rtk = $arr[2][0];//e9a9cb2
$uid = $utmp[1][0];
//echo $token;exit;
//发布信息
$poststr['content'] = $_gpc['content'].$rconfig['tail'];
$poststr['withinfo'] = '{"wpath":[]}';
$poststr['hostid:'] = $uid;
$poststr['privacyparams'] = '{"sourcecontrol": 99}';
$poststr['requesttoken'] = $token;
$poststr['_rtk'] = $rtk;
$poststr['channel'] = "renren";
$head = array(
 'referer:http://shell.renren.com/ajaxproxy.htm',
 'x-requested-with:xmlhttprequest',
);
$ch = curl_init("http://shell.renren.com/{$uid}/status");
curl_setopt($ch, curlopt_useragent, 'mozilla/5.0 (windows; u; windows nt 5.1; zh-cn; rv:1.9.1.5) gecko/20091102 firefox/3.5.5');
curl_setopt($ch,curlopt_httpheader,$head);
curl_setopt($ch, curlopt_returntransfer, 1);
curl_setopt($ch, curlopt_maxredirs, 1);
curl_setopt($ch, curlopt_followlocation, 1);
curl_setopt($ch, curlopt_autoreferer, 1);
curl_setopt($ch, curlopt_post, 1);
curl_setopt($ch, curlopt_postfields, $poststr);
curl_setopt($ch, curlopt_cookiefile, $cookie_file);
$content = curl_exec($ch);
curl_close($ch);
//echo $content;exit;
$data = json_decode($content,true);
if($data["code"] == "0"){
 echo "发布成功!";
}else{
 echo "shit !!!";
}

最后就发布成功了,当然前面的数据库需要自己写一个吧,非常的简单的一个记录库也是你要发布的信息。录数据上去就可以了。

希望本文所述对大家的php程序设计有所帮助。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网