欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

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

程序员文章站 2022-05-03 12:33:26
...
获取sina邮箱联系人列表失败,求救!!!
PHP code

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('****@sina.com','***',$result);

print_r($res);
?>

 


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

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。

相关文章

相关视频