2009-05-02 25 views
4

Ich versuche, eine Verbindung zu einem Yahoo Messenger-Konto und senden PM mit PHP oder CURL. Ich habe die folgende Klasse von phpclasses.org heruntergeladen, die mit eBuddy Web Messenger (http://www.ebuddy.com/) verbindet, um Nachrichten an die gewünschte IM zu senden Der ursprüngliche Code funktionierte nicht, also habe ich einige Änderungen vorgenommen (die ursprünglichen Anweisungen sind auskommentiert), immer noch nein Glück.Senden von Nachrichten an Yahoo IM mit PHP

Ich würde es wirklich schätzen, wenn jemand mir half herauszufinden, wo ich hier falsch liege.

Danke.

<?php 

class My_Yahoo_Messenger { 

    /** 
    * Server host 
    * @access private 
    */ 
    var $serverHost = 'denver.ebuddy.com'; 

    /** 
    * Login user name 
    * @access private 
    */ 
    var $username = null; 

    /** 
    * Login session 
    * @access private 
    */ 
    var $_cookie = null; 

    /** 
    *Connection handle 
    * @access private 
    */ 
    var $fp_handle = null; 

    /** 
    * Construct 
    *@params: 
    * username: String Yahoo account user name 
    * password: String Yahoo account password 
    * login status: Boolean true from visible 
    * @access public 
    */ 
    function __construct($username, $password, $inv = false) 
    { 
     $this->login($username, $password, $inv); 
    } 

    /** 
    * Construct PHP 4 
    *@params: 
    * username: String Yahoo account user name 
    * password: String Yahoo account password 
    * login status: Boolean true from visible 
    * @access public 
    */ 
    function My_Yahoo_Messenger($username, $password, $inv = false) 
    { 
     $this->__construct($username, $password, $inv); 
    } 

    /** 
    * Function provide login to yahoo account 
    *@params: 
    * username: String Yahoo account user name 
    * password: String Yahoo account password 
    * login status: Boolean true from visible 
    *@return: String cookie data 
    * @access public 
    */ 
    function login($username, $password, $inv = false) 
    { 
     $inv = $inv === false ? 'FALSE' : 'TRUE'; 
     $username = urlencode($username); 
     $password = urlencode($password); 

     $content = "password=$password&network=yahoo&initial=FALSE&login_network=yahoo&username=$username&pwd=&init_status=$inv"; 

     //$this->_createConnection('POST', '/vo074922/login.jsp', 'http://www.ebuddy.com/?web_messenger', "yahoo_uname=$username; Emessenger=yahoo; network=YAHOO;", $content, false); 

     $this->_createConnection('POST', '/vo7.3.11/start.html', 'http://www.ebuddy.com/?web_messenger', "yahoo_uname=$username; Emessenger=yahoo; network=YAHOO;", $content, false); 

     $headers = array(); 
     $content = ''; 

     $atStart = true; 
     $atHeader= true; 
     while (!feof($this->fp_handle)) { 
      $line = fgets($this->fp_handle, 4096); 

      if($atStart) { 
       $atStart = false; 
       if (!preg_match('/HTTP\/(\\d\\.\\d)\\s*(\\d+)\\s*(.*)/', $line, $m)) { 
        break; 
       } 
      } 
      if ($atHeader) { 
       if (trim($line) == '') { 
        $atHeader = false; 
        continue; 
       } 
       if (!preg_match('/([^:]+):\\s*(.*)/', $line, $m)) { 
        continue; 
       } 
       $key = strtolower(trim($m[1])); 
       $val = trim($m[2]); 
       if (isset($headers[$key])) { 
        if (is_array($headers[$key])) { 
         $headers[$key][] = $val; 
        } else { 
         $headers[$key] = array($headers[$key], $val); 
        } 
       } else { 
        $headers[$key] = $val; 
       } 
       continue; 
      } 
      $content .= $line; 
     } 

     foreach ($headers as $name=>$header) 
     { 
      switch (true) { 
       case strpos($name, 'location') !== false : 
        if(preg_match('@time\s*=\s*([0-9]+)@i', $header, $m)) { 
         $this->time = $m[1]; 
        } 
        if(preg_match('@hash\s*=\s*([a-z0-9]+)@i', $header, $m)) { 
         $this->hash = $m[1]; 
        } 
        break; 
       case strpos($name, 'set-cookie') !== false : 
        if(is_array($header)) $header = implode(';', $header); 
        $this->_cookie = $header; 
        break; 
      } 
     } 
     @fclose ($this->fp_handle); 

     $this->username = $username; 

     return $this->_cookie; 
    } 

    /** 
    * Function for send message to fav. yahoo account 
    *@params: 
    * to: String Yahoo account 
    * message: String Your message 
    * @access public 
    */ 
    function sendMessage($to, $message) 
    { 
     $message = urlencode($message); 

     $message = preg_replace('!<br.*>!iU', "\n", $message); 

     $hash = isset($this->hash) ? $this->hash : ''; 
     $time = isset($this->time) ? $this->time : time(); 

     $content = "e_hash=$hash&e_action=send_message&e_user=$to&e_message=$message&e_format=FN%3DVerdana%3B%20EF%3D%3B%20CO%3D000000%3B%20CS%3D0%3B%20PF%3D00%3B%20RL%3D0&e_network=YAHOO&_="; 

     //$this->_createConnection('POST', '/dispatch', "http://".$this->serverHost."/vo074922/main.jsp?hash=$hash&u=$this->username&network=YAHOO&time=$time", $this->_cookie, $content, false); 

     $this->_createConnection('POST', '/dispatch', "http://".$this->serverHost."/vo7.3.11/main.html?hash=$hash&u=$this->username&network=YAHOO&time=$time", $this->_cookie, $content, false); 
    } 

    /** 
    * Function for get unread message from yahoo account 
    *@return : Array From:Message 
    * @access public 
    */ 
    function getMessage() 
    { 
     $content = "e_format=short&e_action=poll&e_time=0&e_timeout=10000&e_max=100&_="; 

     $hash = isset($this->hash) ? $this->hash : ''; 
     $time = isset($this->time) ? $this->time : time(); 

     //$this->_createConnection('POST', '/dispatch', "http://".$this->serverHost."/vo074922/main.jsp?hash=$hash&u=$this->username&network=YAHOO&time=$time", null, $content, false); 

     $this->_createConnection('POST', '/dispatch', "http://".$this->serverHost."/vo7.3.11/main.html?hash=$hash&u=$this->username&network=YAHOO&time=$time", null, $content, false); 

     $reciveMessage = array(); 

     $atStart = true; 
     $atHeader= true; 
     while (!feof($this->fp_handle)) { 
      $line = fgets($this->fp_handle, 4096); 

      if($atStart) { 
       $atStart = false; 
       if (!preg_match('/HTTP\/(\\d\\.\\d)\\s*(\\d+)\\s*(.*)/', $line, $m)) { 
        break; 
       } 
      } 
      if ($atHeader) { 
       if (trim($line) == '') { 
        $atHeader = false; 
        continue; 
       } 
       if (!preg_match('/([^:]+):\\s*(.*)/', $line, $m)) { 
        continue; 
       } 
       continue; 
      } 
      if(strpos($line, 'from') !== false) { 
       $from = null; $message = null; 
       if(preg_match('@from\s*=\s*([^;]*);[email protected]', $line, $m)) { 
        $from = $m[1]; 
       } 
       if(preg_match('@msg\s*=\s*([^;]*);[email protected]', $line, $m)) { 
        $message = $m[1]; 
       } 
       if(!empty($message)) { 
        $reciveMessage[ ] = array($from, $message); 
       } 
      } 
     } 
     return $reciveMessage; 
    } 

    /** 
    * Function for create connection 
    *@params: 
    * method: String Request method 
    * file: String Request file 
    * referer: String Referer 
    * cookie: String cookie for send by request 
    * content: String data content to post to server 
    * close: Boolean False for keep connection handle and not close it 
    * @access public 
    */ 
    function _createConnection($method = 'GET', $file = '/', $referer = null, 
           $cookie = null, $content = null, $close = true) 
    { 
     $this->fp_handle = @fsockopen ($this->serverHost, 80, $errno, $errstr, 100); 
     if(!$this->fp_handle) { 
      exit("can not connect to $this->serverHost"); 
     } 

     $method = strtoupper($method); 
     if(!in_array($method, array('GET', 'POST')) || is_null($content)) { 
      $method = 'GET'; 
     } 

     if(is_null($referer)) { 
      $referer = $this->serverHost; 
     } 

     if(is_null($cookie)) { 
      $cookie = $this->_cookie; 
     } 

     $data = "$method $file HTTP/1.1\n"; 
     $data.= "Accept: */*\n"; 
     $data.= "Accept-Language: fa\n"; 
     $data.= "Referer: $referer/\n"; 
     $data.= "Content-Type: application/x-www-form-urlencoded; charset=UTF-8\n"; 
     $data.= "Accept-Encoding: gzip, deflate\n"; 
     $data.= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; Avant Browser [avantbrowser.com]; .NET CLR 1.1.4322)\n"; 
     $data.= "Host: $this->serverHost\n"; 
     $data.= "Connection: Keep-Alive\n"; 
     $data.= "Cache-Control: no-cache\n"; 
     $data.= "Cookie: $cookie\n"; 

     if($method == 'POST') { 
      $length = strlen($content); 
      $data.= "Content-Length: $length\n\n"; 
      $data.= $content; 
     } else { 
      $data.= "\n"; 
     } 

     @fputs ($this->fp_handle, $data); 
     if($close) @fclose($this->fp_handle); 
    } 
} 


?> 
+0

Sie gehen zu müssen, um etwas zu debuggen. Diese Klasse gibt vor, dass es ein Browser ist und missbraucht Ebuddy, also ist es gut möglich, dass sie ihre Seite ein bisschen verändert haben, was dazu führen würde, dass dies scheitert. Gehen Sie Schritt für Schritt durch den Code, stellen Sie sicher, dass alle Fehler aktiv sind, und schreiben Sie vielleicht sogar einige Unittests. – Evert

Antwort

-1

können Sie var $ Passwort vergessen = '', $ var zu = '', Ich bin nicht sicher ‚cos i nicht Experte in PHP ...

Verwandte Themen