首頁 > 後端開發 > php教程 > 获取sina邮箱联系人列表失败,

获取sina邮箱联系人列表失败,

WBOY
發布: 2016-06-13 10:13:29
原創
1312 人瀏覽過

获取sina邮箱联系人列表失败,求救!!!

PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--><?phpdefine ( "COOKIEJAR", tempnam( ini_get( "upload_tmp_dir" ), "cookie" ) );   //定义COOKIES存放的路径,要有操作的权限define( "TIMEOUT", 1000 ); //超时设定/** * 获得sina邮箱通讯录列表 -- contactssina.class.php */class contactssina{    var $host = "";    function checklogin( $user, $password )    {        if ( empty( $user ) || empty( $password ) )        {            return 0;        }        $ch = curl_init( );        curl_setopt( $ch, CURLOPT_REFERER, "http://mail.sina.com.cn/index.html" );        curl_setopt( $ch, CURLOPT_HEADER, true );        curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );        curl_setopt( $ch, CURLOPT_USERAGENT, USERAGENT );        curl_setopt( $ch, CURLOPT_TIMEOUT, TIMEOUT );        curl_setopt( $ch, CURLOPT_URL, "http://mail.sina.com.cn/cgi-bin/login.cgi" );        curl_setopt( $ch, CURLOPT_POST, true );        curl_setopt( $ch, CURLOPT_POSTFIELDS, "&logintype=uid&u=".urlencode( $user )."&psw=".$password );        $contents = curl_exec( $ch );        curl_close( $ch );        if ( !preg_match( "/Location: (.*)\\/cgi\\/index\\.php\\?check_time=(.*)\n/", $contents, $matches ) )        {            return 0;        }        $this->host = $matches[1];        return 1;    }    function getcontacts( $user, $password, &$result )    {        if ( !$this->checklogin( $user, $password ) )        {            return '登陆失败';        }        $ch = curl_init( );        curl_setopt( $ch, CURLOPT_HEADER, true );        curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );        curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true );        curl_setopt( $ch, CURLOPT_USERAGENT, USERAGENT );        curl_setopt( $ch, CURLOPT_COOKIEJAR, COOKIEJAR );        curl_setopt( $ch, CURLOPT_TIMEOUT, TIMEOUT );        curl_setopt( $ch, CURLOPT_URL, "http://mail.sina.com.cn/cgi-bin/login.cgi" );        curl_setopt( $ch, CURLOPT_POST, true );        curl_setopt( $ch, CURLOPT_POSTFIELDS, "&logintype=uid&u=".urlencode( $user )."&psw=".$password );        curl_exec( $ch );        curl_close( $ch );        $cookies = array( );        $bRet = $this->readcookies( COOKIEJAR, $cookies );        if ( !$bRet && !$cookies['SWEBAPPSESSID'] )        {            return '读取cookie失败';        }        $ch = curl_init( );        curl_setopt( $ch, CURLOPT_COOKIEFILE, COOKIEJAR );        curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );        curl_setopt( $ch, CURLOPT_TIMEOUT, TIMEOUT );        curl_setopt( $ch, CURLOPT_URL, $this->host."/classic/addr_member.php" );        curl_setopt( $ch, CURLOPT_POST, true );        curl_setopt( $ch, CURLOPT_POSTFIELDS, "&act=list&sort_item=letter&sort_type=desc" );        $content = curl_exec( $ch );        curl_close( $ch );        $bRet = $this->_parsedata( $content, $result );        return "结果:".$bRet;    }    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;    }        function _parsedata( $content, &$ar )    {        $ar = array( );        if ( !$content )        {            return '获取内容为空';        }        $data = json_decode( $content );        unset( $content );        foreach ( $data->data->contact 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;    }}$contactssina = new contactssina;$res = $contactssina->getcontacts([email protected]','***',$result);print_r($res);?><div class="clear">
                 
              
              
        
            </div>
登入後複製
相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板