PHP Code:
<?php
/**
* 新浪博客自动发博客程序,请不要用于非法用途
* author: hetal
* email : huoqi29@163.com
* qq : 231073376
* msn : hetao29@hotmail.com
* web : http://www.haqoo.com
* weburl: <a href="http://www.haqoo.com">http://www.haqoo.com</a>
*
*/
$blog = new Sina_Blog;
$blog->init();
$user="showmygod";
$pass="你的新浪密码";
if($blog->login($user,$pass)){
echo "登录成功\n";
}else{
die("用户名或者密码错误");
}
$title="博客标题";
$text ="博客文本,支持 html哦";
if($blog->post($title,$text)==0){
echo "发贴成功";
}else{
echo "发贴失败";
}
class Sina_Blog{
var $proxyPort;
var $proxyHost;
var $cookie;
var $_error=0;
function setProxy($proxyHost,$proxyPort){
$this->proxyPort=$proxyPort;
$this->proxyHost=$proxyHost;
}
function init(){
set_time_limit(0);
$this->cookie="SINAGLOBAL=";
$data = $this->_getUrl("http://beacon.sina.com.cn/a.gif?".urlencode("UNIPROINFO=sz:1440x900||dp:32||ac:Mozilla||an:Microsoft Internet Explorer||av:4.0 (compatible, MSIE 6.0, Windows NT 5.1, SV1)||cpu:x86||pf:Win32||jv:1.3||ct:lan||lg:zh-cn||tz:-8||un:||uid:;UNIPROPATH=|*||pid:30-9999-0-0-1|http://www.sr/|st:0|et:".time()."||hp:N|lb:1|PGLS:PGLS000022|keys:|*|;"));
preg_match_all ("/Set-Cookie: (.+?)=(.+?);/", $data, $_matches,PREG_SET_ORDER);
$tmp=array();
for($i=0;$i<count($_matches);$i++){
$tmp[]=$_matches[$i][1]."=".$_matches[$i][2];
}
$tmp[]="SINAGLOBAL=";
$this->cookie=implode(';',$tmp);
}
//登录
function login($user,$pass){
$cookie=$this->cookie;
$post_data ="site=com&chatlogin=in&l=&user=&nick=&pass=&product=mail&grp=2&userid=$user&passcode=$pass&mynum=4";
$post_data_le = strlen($post_data);
if(!empty($this->proxyPort) and !empty($this->proxyHost)){
$post_url="http://unipro.sina.com.cn/cgi-bin/unilogin2.cgi";
$post_port=$this->proxyPort;
$post_host=$this->proxyHost;
$connect="Proxy-Connection";
}else{
$post_url="/cgi-bin/unilogin2.cgi";
$post_port=80;
$connect="Connection";
$post_host="unipro.sina.com.cn";
}
$data="POST $post_url HTTP/1.1\nAccept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*\nReferer: http://www.sina.com.cn\nAccept-Language: zh-cn\nContent-Type: application/x-www-form-urlencoded\nAccept-Encoding: gzip, deflate\nUser-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Alexa Toolbar)\nHost: unipro.sina.com.cn\nContent-Length: $post_data_le\n$connect: Close\nCache-Control: no-cache\nCookie: $cookie\n\n$post_data\n";
$sock = fsockopen($post_host,$post_port,$errno,$error,3);
if(!$sock){return false;}
fputs($sock,$data);
stream_set_timeout($sock, 3);
$rt=stream_get_contents($sock);
$rt=str_replace("\n","",$rt);
$rt=str_replace("\t","",$rt);
fclose($sock);
preg_match_all ("/Set-Cookie: (.+?)=(.+?);/", $rt, $_matches,PREG_SET_ORDER);
$tmp=array();
for($i=0;$i<count($_matches);$i++){
$tmp[]=$_matches[$i][1]."=".$_matches[$i][2];
}
$this->cookie=$cookie.";".implode(';',$tmp);
if(stripos($this->cookie,"UNIPROU")!==false){
return true;
}else{
return false;
}
}
//回贴
function post($title,$text,$tags="音乐 歌手"){
$tmp = array();
$tmp[]="album=";
$tmp[]="act=";
$tmp[]="mode=0";
$tmp[]="ntime=";
$tmp[]="video=0";
$tmp[]="ttype=2";
$tmp[]="failpost=";
$tmp[]="pubtime=".urlencode(date("Y-m-d H:i:s",time()-300));
$tmp[]="blog_info_quote=".urlencode("http://");
$tmp[]="blog_title=".urlencode($title);
$tmp[]="post_pptype=e8bcc1c8d4ef57d3769402541dbcd649";
$tmp[]="blog_class=0";
$tmp[]="sort=text";
$tmp[]="blog_body=".urlencode($text);
$tmp[]="char_count=-1";
$tmp[]="tags=";
$tmp[]="x_cms_flag=1";
$tmp[]="join_circle=1";
$cookie=$this->cookie;
$post_data =implode("&",$tmp);
$post_data_le = strlen($post_data);
if(!empty($this->proxyPort) and !empty($this->proxyHost)){
$post_url="http://blog.sina.com.cn/control/writing/scriber/article_post.php";
$post_port=$this->proxyPort;
$connect="Proxy-Connection";
$post_host=$this->proxyHost;
}else{
$post_url="/control/writing/scriber/article_post.php";
$post_port=80;
$connect="Connection";
$post_host="blog.sina.com.cn";
}
$data="POST $post_url HTTP/1.1\nAccept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*\nAccept-Language: zh-cn\nContent-Type: application/x-www-form-urlencoded\nUser-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Alexa Toolbar)\nHost: tiebacommit.baidu.com\nContent-Length: $post_data_le\nConnection: Close\nCache-Control: no-cache\nCookie: $cookie\n\n$post_data\n";
$sock = fsockopen($post_host,$post_port,$errno,$error,3);
if(empty($sock)){
return -2;
}
fputs($sock,$data);
stream_set_timeout($sock, 3);
$rt=stream_get_contents($sock);
$rt=str_replace("\n","",$rt);
$rt=str_replace("\t","",$rt);
fclose($sock);
if(stripos($rt,"文章发表成功")){
return 0;
}else{
return -1;
}
}
function _getUrl($url,$referer=""){
$purl= parse_url($url);
$host=$purl['host'];
if(!empty($this->proxyHost) and !empty($this->proxyPort)){
$port=$this->proxyPort;
$post_host=$this->proxyHost;
}else{
$post_host=$purl['host'];
if(empty($purl['port'])){
$port=80;
}else{
$port=$purl['port'];
}
}
$cookie = $this->cookie;
$path=$purl['path'];
$query=empty($purl['query'])?"":$purl['query'];
if(!empty($proxyhost) and !empty($proxyport)){
$content="";
$content.="GET $url HTTP/1.0\r\n";
$content.="Accept: */*\r\n";
if(!empty($referer))
$content.="Referer: $referer\r\n";
$content.="Accept-Language: zh-cn\r\n";
$content.="Proxy-Connection: Close\r\n";
$content.="User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)\r\n";
$content.="Host: $host\r\n";
$content.="Pragma: no-cache\r\n";
$content.="Cookie: $cookie\r\n";
$content.="\r\n\r\n";
}else{
$content="";
if(!empty($query))
$content.="GET $path?$query HTTP/1.0\r\n";
else
$content.="GET $path HTTP/1.0\r\n";
$content.="Accept: */*\r\n";
if(!empty($referer))
$content.="Referer: $referer\r\n";
$content.="Accept-Language: zh-cn\r\n";
$content.="Connection: Close\r\n";
$content.="User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)\r\n";
$content.="Host: $host\r\n";
$content.="Pragma: no-cache\r\n";
$content.="Cookie: $cookie\r\n";
$content.="\r\n\r\n";
}
$sock=fsockopen ($post_host,$port,$errno, $errstr, 5);
if($sock){
$this->_error=0;
fwrite($sock,$content);
}else{
$this->_error++;
if($this->error>5){
return null;
}else{
return $this->_getUrl($url,$referer);
}
}
$rt=stream_get_contents($sock);
fclose($sock);
return $rt;
}
}
?>