PageRenderTime 44ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 1ms

/getmail/sohu.php

https://github.com/jerywang/phplib
PHP | 60 lines | 52 code | 4 blank | 4 comment | 5 complexity | d3c5b4793105f08092174a65a9604445 MD5 | raw file
  1. <?php
  2. define( "COOKIEJAR", tempnam( ini_get( "upload_tmp_dir" ), "cookie" ) );
  3. class sohu
  4. {
  5. public function getAddressList($username, $password)
  6. {
  7. $name=explode('@', $username);
  8. $username=$name[0];
  9. $ch = curl_init();
  10. $encodeurl = "http://passport.sohu.com/sso/login.jsp?userid=".urlencode($username . "@sohu.com") . "&password=".md5($password)."&appid=1000&persistentcookie=0&s=".time()."343&b=2&w=1024&pwdtype=1";
  11. curl_setopt($ch, CURLOPT_URL, $encodeurl);
  12. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  13. curl_setopt($ch, CURLOPT_COOKIESESSION, true);
  14. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  15. curl_setopt($ch, CURLOPT_COOKIEJAR, COOKIEJAR );
  16. curl_setopt($ch, CURLOPT_TIMEOUT, 60);
  17. $contents = curl_exec( $ch );
  18. if ( strpos( $contents, "success" ) === false )
  19. {
  20. return 0;
  21. }
  22. curl_setopt($ch, CURLOPT_URL, "http://mail.sohu.com/bapp/128/main#addressList");
  23. $contents = curl_exec($ch);
  24. if(false == $contents){
  25. curl_close( $ch );
  26. return false;
  27. }else{
  28. curl_close( $ch );
  29. return $this->parserContent($contents);
  30. }
  31. }
  32. function parserContent($content){
  33. preg_match_all("/var addresses = '(.*)';/Umsi",$content,$data);
  34. $numList= json_decode( $data[1][0]);
  35. $contactList = array();
  36. foreach ($numList->contact as $val){
  37. $obj = array();
  38. $obj['name'] = $val->nickname;
  39. //$obj['nickname'] = $val->pinyin;
  40. $obj['emailAddress'] = $val->email;
  41. //if($obj['nickname']==""){
  42. // $obj['nickname'] = $obj['name'];
  43. //}
  44. $contactList[] = $obj;
  45. }
  46. if( count($contactList) == 0 ){
  47. return false;
  48. }else{
  49. return $contactList;
  50. }
  51. }
  52. }
  53. $test = new sohu();
  54. $contects = $test->getAddressList('jerrywang4444@sohu.com', '123456');
  55. print_r($contects);
  56. ?>