zoukankan      html  css  js  c++  java
  • php curl 获取 邮箱通讯录 sohu

    2012-3-24 经测试可正常使用

    <?php
    error_reporting(0);
    define("COOKIEJAR", tempnam(ini_get("upload_tmp_dir"), "cookie"));   //定义COOKIES存放的路径,要有操作的权限
    define("TIMEOUT", 10000); //超时设定
    /**
     * author : 郭钱
     */
    $contacts = new sohu();
    
    $lists = $contacts->getcontacts('email@sohu.com', 'password', $result);
    var_dump($lists);
    
    class sohu {
    
        function checklogin($user, $password) {
            $ch = curl_init( );
            $url = "http://passport.sohu.com/sso/login.jsp";
            $url = $url . "?userid=" . urlencode($user);
            $url = $url . "&password=" . md5($password);
            $url = $url . "&appid=1000&persistentcookie=0&s=" . time() . "&b=1&w=1024&pwdtype=1";
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_COOKIEJAR, COOKIEJAR);
            curl_setopt($ch, CURLOPT_TIMEOUT, TIMEOUT);
            ob_start( );
            curl_exec($ch);
            $contents = ob_get_contents( );
            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 '登陆失败';
            }
            $cookies = array();
            $bRet = $this->readcookies(COOKIEJAR, $cookies);
            if (!$bRet && !$cookies['JSESSIONID']) {
                return '读取cookie失败';
            }
            $ch = curl_init( );
            curl_setopt($ch, CURLOPT_COOKIEFILE, COOKIEJAR);
            curl_setopt($ch, CURLOPT_TIMEOUT, TIMEOUT);
            curl_setopt($ch, CURLOPT_URL, "http://mail.sohu.com/bapp/86/main#addressList");
            ob_start( );
            curl_exec($ch);
            $content = ob_get_contents( );
            ob_end_clean( );
            curl_close($ch);
            $bRet = $this->_parsedata($content);
            return $bRet;
        }
    
        function _parsedata($content) {
            preg_match_all("/var addresses = '(.*)';/Umsi", $content, $data);
            $numList = json_decode($data[1][0], true);
            $contactList = array();
            foreach ($numList['contact'] as $val) {
                $obj['name'] = $val['nickname'];
                $obj['nickname'] = $val['pinyin'];
                $obj['email'] = $val['email'];
                if ($obj['nickname'] == "") {
                    $obj['nickname'] = $$obj['name'];
                }
                $contactList[] = $obj;
            }
            if (!$contactList) {
                return CONTACT_ERROR;
            } else {
                return $contactList;
            }
        }
    
        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;
        }
    
    }
    ?> 
    
  • 相关阅读:
    如何在SAP中找表
    SQL SARG
    计算两个时间相差多少年月日的sql算法
    给WordPress添加微博功能
    sqlServer,oracle中case关键字的用法
    SSIS错误之"The Excel Connection Manager is not supported in the 64bit version of SSIS"
    Oracle编程艺术之设置环境
    Quest.Central.For.Databases.v6.1下载地址
    Oracle Database 11g SQL开发指南store模式脚本
    SQL中连接的种类和区别
  • 原文地址:https://www.cnblogs.com/ybbqg/p/2415715.html
Copyright © 2011-2022 走看看