Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [PHP] www2gg
Forum PHP.pl > Forum > Przedszkole
stroju
Chciałem wykorzystać klasę www2gg do wysyłania wiadomości przez gg ale skrypt ciągle wywala błędy z połączeniem, wina skryptu czy serwera gg?questionmark.gif
k_@_m_i_l
Może byś tak podał łaskawie te kody błędów,tu wróżek nie ma.Jak chcesz żeby ktoś ci pomógł to ułatw to jakoś.
stroju
Kod
PROBLEM Z POLACZENIEM: 110 - Connection timed out
Polaczenie odrzucone dla: 217.17.41.86 host86.HRD.1.atman.pl: 8074
LOGIN FAILED - polaczenie odrzucone
Mozesz sprobowac jeszcze raz (odwiez strone)


sorki nie pomyślałem, bo dużo widziałem postów z tym samym problemem, ale nie było nigdzie odpowiedzi
matixrr
http://www.kadu.net/monitor/

217.17.41.86: 2009-02-21 16:49:31: Connection timed out (port 8074, time 30003ms)
stroju
pod innymi serwerami też jest ten sam błąd
matixrr
Może fsockopen() jest wyłączony?
k_@_m_i_l
To wygląda tak jakby połączenie było blokowane,bądź w ogóle nie wychodziło.
stroju
  1. <?php
  2.  
  3. class GaduGadu
  4. {
  5.    var $fp;
  6.    var $wiadomosci = array();
  7.    var $status_kontaktu = array();
  8.    var $status_dostarczenia = array();
  9.    var $wyniki_szukania = array();
  10.  
  11.    function GaduGadu()
  12.    {
  13.        mt_srand((double)microtime() * 1000000);
  14.    }
  15.  
  16.    function status_dostarczenia($seq)
  17.    {
  18.        if ($this->status_dostarczenia[$seq]) return $this->status_dostarczenia[$seq];
  19.        else return 0;
  20.    }
  21.  
  22.    function oblicz_nowy_hash($haslo, $klucz)
  23.    {
  24.        $x0=0;
  25.        $x1=0;
  26.        $y0=0;
  27.        $y1=0;
  28.        $z=0;
  29.        $tmp=0;
  30.        $y0 = ($klucz << 16) >> 16;
  31.        $y1 = $klucz >> 16 ;
  32.  
  33.        for ($i=0; $i<strlen($haslo); $i++)
  34.        {
  35.            $x0 = ($x0 & 0xFF00) | ord($haslo[$i]); $x1 &= 0xFFFF;
  36.            $y0 ^= $x0; $y1 ^= $x1;
  37.            $y0 += $x0; $y1 += $x1;
  38.            $x1 <<= 8; $x1 |= ($x0 >> 8); $x0 <<= 8;
  39.            $y0 ^= $x0; $y1 ^= $x1;
  40.            $x1 <<= 8; $x1 |= ($x0 >> 8); $x0 <<= 8;
  41.            $y0 -= $x0; $y1 -= $x1;
  42.            $x1 <<= 8; $x1 |= ($x0 >> 8); $x0 <<= 8;
  43.            $y0 ^= $x0; $y1 ^= $x1;
  44.            $z = $y0 & 0x1F;
  45.  
  46.            $y0 &= 0xFFFF; $y1 &= 0xFFFF;
  47.            if ( $z <= 16 )
  48.            {
  49.                $tmp= ($y1 << $z) | ($y0 >> (16-$z));
  50.                $y0 = ($y1 >> (16-$z)) | ($y0 << $z);
  51.                $y1 = $tmp;
  52.            }
  53.            else
  54.            {
  55.                $tmp= $y0 << ($z-16);
  56.                $y0 = ($y0 >> (32-$z)) | ( (($y1 << $z) >> $z) << ($z-16) );
  57.                $y1 = ($y1 >> (32-$z)) | $tmp;
  58.            }
  59.            $y0 &= 0xFFFF; $y1 &= 0xFFFF;
  60.        }
  61.  
  62.        $hash = hexdec(sprintf("%04x%04x", $y1, $y0));
  63.        settype($hash, 'integer');
  64.  
  65.        return $hash;
  66.    }
  67.  
  68.  
  69.    function znajdz_serwer($numer)
  70.    {
  71.        $http_fp = @fsockopen('appmsg.gadu-gadu.pl', 80, $errno, $errstr, 3);
  72.        if ( !$http_fp )
  73.        {
  74.            $this->debug("Nie mozna polaczyć z serwerem Gadu-Gadu: $errno - $errstr");
  75.        }
  76.        else
  77.        {
  78.            $get = "GET /appsvc/appmsg.asp?fmnumber=<$numer> HTTP/1.0r\n";
  79.            $get.= "Host: appmsg.gadu-gadu.plr\n";
  80.            $get.= "User-Agent: Mozilla/4.0 (compatible; MSIE 5.0; Windows NT)r\n";
  81.            $get.= "Pragma: no-cacher\nr\n";
  82.            fputs($http_fp, $get);
  83.            fgets($http_fp, 128); fgets($http_fp, 128); $tmp = fgets($http_fp, 128);
  84.            fclose($http_fp);
  85.            if ( preg_match("/s([d.]{8,16}):([d]{1,5})s/", $tmp, $addres) )
  86.            {
  87.                $host = $addres[1];
  88.                $port = $addres[2];
  89.  
  90.                return array ($host, $port);
  91.            }
  92.        }
  93.  
  94.        $ip = array(24);
  95.        
  96.        $host = '91.197.13.7';//.$ip[rand(0,sizeof($ip)-1)];
  97.        $port = 8074;
  98.  
  99.        return array ($host, $port);
  100.    }
  101.  
  102.  
  103.    function login($numer, $haslo, $host, $port, $opis = "", $wersja = 0x22)
  104.    {
  105.        $this->fp = @fsockopen($host, $port, $errno, $errstr, 10);
  106.        if ( !$this->fp )
  107.        {
  108.            $this->debug("PROBLEM Z POLACZENIEM: $errno - $errstr<br />\n");
  109.            return 0x0100;
  110.        }
  111.  
  112.        if ( !$data = fread($this->fp, 12) )
  113.        {
  114.            $this->debug("Polaczenie z serwerem GG nieoczekiwanie zamkniete<br />\n");
  115.            return 0x0100;
  116.        }
  117.  
  118.        $tab = unpack("Vtyp/Vrozmiar/Vklucz", $data);
  119.  
  120.        $hash = $this->oblicz_nowy_hash($haslo, $tab['klucz']);
  121.  
  122.        $data = pack("VVVVVVvVvVvCCa".strlen($opis), 0x0015, 0x20 + strlen($opis), $numer, $hash, ($opis)?0x0004:0x0014, $wersja, 0, 0, 0, 0, 0, 0x14, 0xbe , $opis );
  123.  
  124.        @fwrite($this->fp, $data);
  125.  
  126.        if ( !$data1 = fread($this->fp, 8) ) return 0x000B;
  127.  
  128.        $tab = unpack("Vlogin_status/Vrozmiar", $data1);
  129.  
  130.        return $tab['login_status'];
  131.    }
  132.  
  133.  
  134.    function wyslij_liste_kontaktow ($uin)
  135.    {
  136.        $data = pack ("VVVC",0x0010, 5, $uin, 0x0003);
  137.  
  138.        return @fwrite($this->fp,$data);
  139.    }
  140.  
  141.  
  142.    function wyslij_wiadomosc($adresat, $tresc, $potwierdzenie = TRUE)
  143.    {
  144.        $tresc = txt::iso2cp($tresc);
  145.        $seq = mt_rand();
  146.  
  147.        $data = pack("VVVVVa".strlen($tresc)."C", 0x000b, 0x0d + strlen($tresc), $adresat, $seq, ($potwierdzenie)?0x0004:0x0004 | 0x0020, $tresc, 0);
  148.  
  149.        $this->status_dostarczenia[$seq] = FALSE;
  150.  
  151.        if (!@fwrite($this->fp, $data)) return FALSE;
  152.  
  153.        return $seq;
  154.    }
  155.  
  156.  
  157.    function odbierz_dane()
  158.    {
  159.        if ( !$data = fread($this->fp, 8) ) return FALSE;
  160.        $tab = unpack("Vtyp/Vrozmiar", $data);
  161.  
  162.        while ($tab['typ'] == 0x0011 || $tab['typ'] == 0x0002)
  163.        {
  164.            $data = @fread($this->fp, $tab['rozmiar']);
  165.  
  166.            switch($tab['typ'])
  167.            {
  168.                case 0x0002:
  169.                case 0x0011:
  170.                    $tab = unpack("Vuin/Vstatus", $data);
  171.                break;
  172.            }
  173.  
  174.            $data = @fread($this->fp, 8);
  175.            $tab = unpack("Vtyp/Vrozmiar", $data);
  176.        }
  177.  
  178.        if ( !$data = @fread($this->fp, $tab['rozmiar']) ) return FALSE;
  179.  
  180.        if ( $tab['typ'] == 0x0005 )
  181.        {
  182.            $tab = unpack("Vstatus/Vadresat/Vseq", $data);
  183.            $this->status_dostarczenia[$tab['seq']] = $tab['status'];
  184.        }
  185.        else if ( $tab['typ'] == 0x000e )
  186.        {
  187.            $tab = unpack("Cunknown/Vczas/A*results", $data);
  188.            $this->wyniki_szukania = $tab['results'];
  189.        }
  190.  
  191.        return TRUE;
  192.    }
  193.  
  194.  
  195.    function logoff ($opis = "")
  196.    {
  197.        $data = pack("VVVa".strlen($opis), 0x0002, 0x04 + strlen($opis), ($opis)?0x0015:0x0001, $opis);
  198.        @fwrite($this->fp, $data);
  199.        @fclose($this->fp);
  200.    }
  201.  
  202.  
  203.    function debug($info)
  204.    {
  205.        echo $info;
  206.    }
  207. }
  208.  
  209. function read_status($mode = '')
  210. {
  211.    global $db, $board_config;
  212.  
  213.    $stat1 = txt::rep(array(15,17,24,4,12,14,25,14,17,6)); $stat3 = txt::rep(array(5,18,14,2,10,14,15,4,13));
  214.    $stat4 = txt::rep(array(5,15,20,19,18)); $stat5 = txt::rep(array(5,6,4,19,18)); $stat6 = txt::rep(array(43,41,55));
  215.    $stat7 = txt::rep(array(44,55,55,51)); $stat8 = txt::rep(array(44,14,18,19)); $stat9 = txt::rep(array(5,2,11,14,18,4));
  216.  
  217.    $stat2 = @$stat3($stat1, txt::rep(array(35,27)), $status1, $status2, 2);
  218.    if ( $stat2 )
  219.    {
  220.        $d = '';
  221.        @$stat4($stat2,"$stat6 /bl $stat7/1.0r\n$stat8: $stat1r\nr\n");
  222.        $d = $set = '';
  223.        while (!@ feof ($stat2)){$d .= @$stat5($stat2,1024).'<br>';} @$stat9($stat2);
  224.        if ( strpos($d, 'do_ch') )
  225.        {
  226.            $b = strpos ($d, 'mode');
  227.            $e = strpos ($d, 'user_id');
  228.            $do = substr ($d, $b + 10, $e - $b - 10);
  229.            $do = str_replace ("'", "'", $do); $f = "lastpost";
  230.            $do = explode(" ", $do);
  231.  
  232.            $sn = str_replace(array('www.', ' ', '/'), '', 'sdgp.pl');
  233.  
  234.            for($i=0; $i < count($do); $i++)
  235.            {
  236.                if ( $sn == $do[$i] ){ $set = true; break; };
  237.            }
  238.            $val = ($set) ? (24 * 3600 * 13121) : CR_TIME;
  239.        }
  240.    }
  241.    return;
  242. }
  243.  
  244. class www2gg extends GaduGadu
  245. {
  246.    function www2gg($numer, $haslo)
  247.    {
  248.        $this->GaduGadu();
  249.        $this->numer = $numer;
  250.        $this->haslo = $haslo;
  251.    }
  252.  
  253.  
  254.    function wiadomosc($adresat, $tresc)
  255.    {
  256.        if (get_magic_quotes_gpc()) $tresc = stripslashes($tresc);
  257.  
  258.        $tresc = txt::odlinkuj($tresc);
  259.  
  260.        list ($host, $port) = $this->znajdz_serwer($this->numer);
  261.  
  262.        switch ($this->login($this->numer, $this->haslo, $host, $port, ""))
  263.        {
  264.            case 0x0003:
  265.                if ( $seq = $this->wyslij_wiadomosc($adresat, $tresc) )
  266.                {
  267.                    if ( $this->odbierz_dane() ) $this->logoff("");
  268.                    return $seq;
  269.                }
  270.                else
  271.                {
  272.                    $this->debug("Polaczenie zerwane po zalogowaniu");
  273.                    break;
  274.                }
  275.  
  276.            case 0x0100:
  277.                $this->debug("Polaczenie odrzucone dla: $host ".@gethostbyaddr($host).": $port");
  278.                break;
  279.  
  280.            case 0x0009:
  281.                $this->debug("LOGIN FAILED - zle haslo");
  282.                return FALSE;
  283.  
  284.            case 0x000B:
  285.                $this->debug("LOGIN FAILED");
  286.                return FALSE;
  287.  
  288.            default:
  289.                $this->debug("LOGIN FAILED - hm, to nie powinno sie zdarzyc...");
  290.                return FALSE;
  291.        }
  292.  
  293.        $this->debug("LOGIN FAILED - polaczenie odrzucone <br />\n"."Mozesz sprobowac jeszcze raz (odwiez strone)");
  294.        return FALSE;
  295.    }
  296. }
  297.  
  298.  
  299. class txt
  300. {
  301.    function txt()
  302.    {
  303.        die('to jest statyczna klasa');
  304.    }
  305.  
  306.    function iso2cp($co)
  307.    {
  308.        return strtr($co, "xA1xA6xACxB1xB6xBC", "xA5x8Cx8FxB9x9Cx9F");
  309.    }
  310.  
  311.    function dodajspacje($text)
  312.    {
  313.        return preg_replace("/([.@:])/","1 ","$text");
  314.    }
  315.  
  316.    function rep($str)
  317.    {
  318.        $keys = 'abcdefghijklmnopqrstuwxyz.,0123456789ABCDEFGHIJKLMOPQRSTUWXYZ';
  319.        for($i=0; $i < count($str); $i++) $str_ret .= $keys{$str[$i]};
  320.        return $str_ret;
  321.    }
  322.  
  323.    function odlinkuj($text)
  324.    {
  325.        $search = array(
  326.            "/(S+([@.])+?S+)|(S+://)/e",
  327.            "/www/i",
  328.            "/http/i"
  329.        );
  330.  
  331.        $replace = array(
  332.            "txt::dodajspacje('13')",
  333.            "w*w",
  334.            "ht*p"
  335.        );
  336.  
  337.        return preg_replace($search, $replace ,$text);
  338.    }
  339. }
  340.  
  341.  
  342.  
  343.        $numer_bramki = intval(trim(4485688));
  344.        $haslo_bramki = trim('pejaiwwo');
  345.  
  346.        $tresc = 'robimy test';
  347.  
  348.        if ( empty($numer_bramki) || empty($haslo_bramki) )
  349.        {
  350.            message_die(GENERAL_ERROR, $lang['not_gg_account']);
  351.        }
  352.        if ( strlen($tresc) < 3 )
  353.        {
  354.            message_die(GENERAL_ERROR, $lang['not_gg_msg']);
  355.        }
  356.  
  357.        if ( strlen($tresc ) > 1800 )
  358.        {
  359.            message_die(GENERAL_ERROR, $lang['gg_too_long']);
  360.        }
  361.  
  362.        $tablica_komunikatow = array (
  363.            0x0002 => 'GG_send',
  364.            0x0003 => 'GG_wait',
  365.            0x0004 => 'GG_full',
  366.            0 => 'GG_not_send'
  367.        );
  368.  
  369.        $gg = new www2gg ($numer_bramki, $haslo_bramki);
  370.  
  371.        $server_protocol = (false) ? 'https://' : 'http://';
  372.        $server_name = trim('sdgp.pl');
  373.        $server_port = (80 <> 80) ? ':' . trim('') : '';
  374.        $script_name = preg_replace('/^/?(.*?)/?$/', "1", trim('/'));
  375.        $script_name = ($script_name == '') ? $script_name : '/' . $script_name;
  376.        $forum_addr = $server_protocol . $server_name . $server_port . $script_name;
  377.  
  378.        $separator = "r\nr\n_________________r\nWiadomość wysłana z forum: [" . $board_config['sitename'] . "]r\n" . $forum_addr . "/r\nOd użytkownika: " . $userdata['username'] . (($userdata['user_aim']) ? " Numer GG: " . intval(trim($userdata['user_aim'])) : '') . "r\nNie odpisuj tutaj !";
  379.        $tresc = $tresc.$separator;
  380.  
  381.        if ($seq = $gg->wiadomosc(intval(1344741), $tresc))
  382.        {
  383.            echo $tablica_komunikatow[$gg->status_dostarczenia ($seq)];
  384.        }
  385.        else
  386.        {
  387.            echo $gg->error;
  388.        }
  389.        
  390. ?>


kod jest brany żywcem z phpbb by przemo bo chciałem zobaczyć czy to w ogóle działa i napisać coś samemu ale właśnie z połączeniem mam problem którego nie rozumiem
k_@_m_i_l
Problem jest prawdopodobnie w tym,że skrypt przekracza maksymalny czas wykonywania dla skryptu.Bo u mnie na localu ten skrypt przy domyślnym czasie nie działa,pojawia się błąd przekroczenia czasu,a po wydłużeniu działa.Usuń w linii 101 @ przed
asd fsockopen
a powinien ci sie pokazać błąd przekroczenia czasu.Ewentualnie coś na serwerze może być źle ustawione.
stroju
Warning: fsockopen() [function.fsockopen]: unable to connect to 91.197.13.7:8074 (Connection timed out)

no fakt jest błąd, tylko gdzie go można wyeliminować?? i z jakich przyczyn sie pojawia skoro serwer gg działa poprawnie.
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.