<?php
define( "COOKIEJAR", tempnam( ini_get( "upload_tmp_dir" ), "cookie" ) ); //定义COOKIES存放的路径,要有操作的权限
define( "TIMEOUT", 1000 ); //超时设定
/**
* sohu -- contactssina.class.php
*/class sohu
{ function checklogin( $user, $password )
{
// $url = "http://passport.sohu.com/sso/login.jsp"; $headers_login = array(
'Host' => 'mail.sohu.com',
'User-Agent' => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2.2) Gecko/20100316 Firefox/3.6.2',
'Accept' => 'text/javascript, text/html, application/xml',
'Accept_Language' => 'zh-cn,zh;q=0.5',
'Accept_Encoding' => 'gzip,deflate',
'Accept_Charset' => 'GB2312,utf-8;q=0.7,*;q=0.7\r\n',
'Keep-Alive' => '115',
'Connection' => 'keep-alive',
'X-Requested-With'=> 'XMLHttpRequest',
'Content_Type' => 'application/x-www-form-urlencoded; charset=UTF-8',
'Referer' => 'http://mail.sohu.com/'
); $url = "http://passport.sohu.com/sso/login.jsp";
$url = $url."?userid=".urlencode( $user );
$url = $url."&password=".md5( $password );
$url = $url."&appid=1000&persistentcookie=0&isSLogin=1&s=".time( )."&b=1&w=1366&pwdtype=1&v=26";
$ch = curl_init($url);
curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers_login);
curl_setopt( $ch, CURLOPT_COOKIEJAR, COOKIEJAR );
curl_setopt( $ch, CURLOPT_TIMEOUT, TIMEOUT );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch,CURLOPT_HEADER,1);
// ob_start( );
$contents = curl_exec( $ch );
// $contents = ob_get_contents( );
// echo $contents;exit;
curl_close($ch); //获取二次跳转地址
// preg_match("/<a\shref=\"(.+)\">here<\/a>/", $contents, $mtitle);
// print_r($mtitle);exit;
// $_url1 = $mtitle[1];
// echo $_url1;
// exit;
// $_url1 = 'http://mail.sohu.com/bapp/81/main';
//
// //第二步:再次跳转到到上面$_url1
// $ch = curl_init($_url1);
// curl_setopt($ch, CURLOPT_TIMEOUT, TIMEOUT);
// curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// curl_setopt($ch,CURLOPT_COOKIEFILE,COOKIEJAR);
// curl_setopt($ch, CURLOPT_COOKIEJAR, COOKIEJAR);
// curl_setopt($ch,CURLOPT_HEADER,1);
// $str2 = curl_exec($ch);
// curl_close($ch);
// echo $str2;exit;
//// ob_end_clean( );
// curl_close( $ch );
if ( strpos( $contents, "success" ) === false )
{
return 0;
}
return 1;
} function getcontacts( $user, $password, &$result )
{
if ( !$this->checklogin( $user, $password ) )
{
return 'checklogin失败';
}
$cookies = array( );
$bRet = $this->readcookies( COOKIEJAR, $cookies );
// print_r($cookies);exit;
// print_r($bRet);exit;
if ( !$bRet && !$cookies['JSESSIONID'] )
{
return 'readcookies失败';
}
$ch = curl_init( );
curl_setopt( $ch, CURLOPT_COOKIEFILE, COOKIEJAR );
curl_setopt( $ch, CURLOPT_TIMEOUT, TIMEOUT );
// curl_setopt( $ch, CURLOPT_URL, "http://www51.mail.sohu.com/webapp/contact" ); $headers = array(
'Host' => $server,
'User-Agent' => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2.2) Gecko/20100316 Firefox/3.6.2',
'Content-Type' => 'application/x-www-form-urlencoded; charset=UTF-8'
); for($i=0;$i<6;$i++)
{
$num.=mt_rand(1,9);
}
// echo $num;exit;
curl_setopt( $ch, CURLOPT_URL, "http://mail.sohu.com/jsoplog/log?uc=|mailaddress&r=".$num );
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_HEADER, 0);
ob_start( );
curl_exec( $ch );
$content = ob_get_contents( );
echo $content;exit;
ob_end_clean( );
curl_close( $ch );
$bRet = $this->_parsedata( $content, $result );
return $bRet;
} function _parsedata( $content, &$ar )
{
$ar = array( );
if ( !$content )
{
return '获取内容为空';;
}
$data = json_decode( $content );
// print_r($data);
unset( $content );
foreach ( $data->listString as $value )
{
if ( preg_match_all( "/[a-z0-9_\\.\\-]+@[a-z0-9\\-]+\\.[a-z]{2,6}/i", $value->email, $matches ) )
{
$emails = array_unique( $matches[0] );
unset( $matches );
foreach ( $emails as $email )
{
$ar[$email] = $value->name;
}
}
}
return $ar;
} function readcookies( $file, &$result )
{
$fp = fopen( $file, "r" );
while ( !feof( $fp ) )
{
$buffer = fgets( $fp, 4096 );
$tmp = split( "\t", $buffer );
$result[trim( $tmp[5] )] = trim( $tmp[6] );
}
return 1;
}}$contacts = new sohu;$res = $contacts->getcontacts('****','****',$result);print_r($res);
?>
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货