PHP通过curl登录人人并发布状态…


$username=$_POST["username"];

$password=$_POST["password"];

$message=$_POST["message"];

if($message!=""){

	updateRenren($message,$username,$password,0);

	echo $message;

}

function updateRenren($status,$renren_username,$renren_password,$tried_times){
	if($tried_times>=3){
		return false;
	}

	$cookie_jar=tempnam('./tmp','renren');
	$ch=&getCurl($cookie_jar,"POST","http://passport.renren.com/PLogin.do");
	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');
	$str=&sendAndResult($ch);
	$pattern="/get_check:'([^']+)'/";
	preg_match($pattern,$str,$matches);
	$get_check=$matches[1];
	$ch=&getCurl($cookie_jar,"POST","http://status.renren.com/doing/update.do");	curl_setopt($ch,CURLOPT_POSTFIELDS,'c='.urlencode($status).'&raw='.urlencode($status).'&isAtHome=1&publisher_form_ticket='.$get_check.'&requestToken='.$get_check);
	curl_setopt($ch,CURLOPT_REFERER,'http://status.renren.com/ajaxproxy.htm');
	$ret=&sendAndResult($ch);
	if(strpos($ret,"{"allMsg":")===0){
		echo "[Renren] succeedn";
	}else{
		echo "[Renren] failedn";
		updateRenren($status,$renren_username,$renren_password,$tried_times+1);
	}
}


function &getCurl($jar,$method,$url){
	$ch=curl_init();
	curl_setopt($ch,CURLOPT_COOKIEJAR,$jar);
	curl_setopt($ch,CURLOPT_COOKIEFILE,$jar);
	curl_setopt($ch,CURLOPT_URL,$url);
	curl_setopt($ch,CURLOPT_FOLLOWLOCATION,TRUE);
	curl_setopt($ch,CURLOPT_RETURNTRANSFER,TRUE);
	curl_setopt($ch, CURLOPT_USERAGENT,"Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2.8) Gecko/20100722 Firefox/3.6.8");
	//curl_setopt($ch,CURLOPT_VERBOSE,true);
	if($method=="POST"){
	curl_setopt($ch,CURLOPT_POST,TRUE);
	}else{
	curl_setopt($ch,CURLOPT_POST,FALSE);
	}
	return $ch;
}


function &sendAndResult(&$ch){
	$str=curl_exec($ch);
	curl_close($ch);
	unset($ch);
	return $str;
}

发表评论

电子邮件地址不会被公开。 必填项已用*标注