Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP] Orange MultiBox - wysyłanie smsa, Wysyłanie smsa za pomocą bramki MultiBox Orange - dla pro
pablo86
post
Post #1





Grupa: Zarejestrowani
Postów: 13
Pomógł: 0
Dołączył: 18.07.2009

Ostrzeżenie: (0%)
-----


Witam,

Mam problem z skryptem którego zaprezentowałem poniżej. Skrypt się bez problemu uruchamia, ale nie robi tego co ma zrobić - czyli nie wysyła smsa na podany numer.

Co jest nie tak, czy może mi ktoś pomóc rozwiązać ten problem?

Paweł

  1. <?PHP
  2. header("Content-type: text/html; charset=UTF-8");
  3.  
  4. /**
  5.  * Licencja CC BY-NC-SA
  6.  * <a href="http://creativecommons.org/licenses/by-nc-sa/3.0/deed.pl" target="_blank">http://creativecommons.org/licenses/by-nc-sa/3.0/deed.pl</a>
  7.  * Klasa mbox umożliwiająca wysyłanie wiadomości SMS
  8.  * @author Kacper 'kacka' Szurek
  9.  * @mail kacperszurek (poczta w gmail.com)
  10.  * Jeżeli się przydało - napisz
  11.  * Chcesz podziękować, pomóc masz pytanie - napisz
  12.  * Skrypt przechowuje cookie w katalogu /dane/mbox.txt
  13.  *
  14.  */
  15. class mbox
  16. {
  17.    /**
  18.      * Przechowuje identyfikator połączenia curl
  19.      *
  20.      * @var $ch
  21.      */
  22.    protected $_curl;
  23.  
  24.    /**
  25.      * Ułatwienie dostępu do curl
  26.      *
  27.      * @param string $url - adres strony
  28.      * @param array $post - opcjonalnie tablica parametrów
  29.      * @return string - zwraca pobraną treść
  30.      */
  31.    public function curl($url, $post = null)
  32.    {
  33.        $this->_curl = curl_init();
  34.        
  35.        $var = array(
  36.            CURLOPT_URL => $url,
  37.            CURLOPT_COOKIEJAR => dirname(__FILE__).'/dane/mbox.txt',
  38.            CURLOPT_COOKIEFILE => dirname(__FILE__).'/dane/mbox.txt',
  39.            CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; pl; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6',
  40.            CURLOPT_RETURNTRANSFER => true,
  41.            CURLOPT_FOLLOWLOCATION => true);
  42.                    
  43.        if ( !is_null($post) ) {
  44.            foreach ($post as $option => $value) {
  45.                $tmp .= $option. '=' .urlencode($value). '&';
  46.            }
  47.            
  48.            $var[CURLOPT_POST] = true;
  49.            $var[CURLOPT_POSTFIELDS] = $tmp;
  50.        }
  51.            
  52.        curl_setopt_array($this->_curl, $var);
  53.        
  54.        $return = curl_exec($this->_curl);
  55.    
  56.        return $return;
  57.        
  58.        curl_close($this->_curl);
  59.    }
  60.  
  61.    /**
  62.      * Funkcja logująca do orange.pl
  63.      *
  64.      * @param string $user - użytkownik
  65.      * @param string $password - hasło
  66.      */
  67.    public function login($user, $password)
  68.    {
  69.        $data = array(
  70.        '_dyncharset' => 'UTF-8',
  71.        '/amg/ptk/map/core/formhandlers/AdvancedProfileFormHandler.loginErrorURL' => 'http://www.orange.pl/portal/map/map/signin',
  72.        '_D:/amg/ptk/map/core/formhandlers/AdvancedProfileFormHandler.loginErrorURL=' => '',
  73.        '/amg/ptk/map/core/formhandlers/AdvancedProfileFormHandler.loginSuccessURL' => 'http://www.orange.pl/portal/map/map/pim',
  74.        '_D:/amg/ptk/map/core/formhandlers/AdvancedProfileFormHandler.loginSuccessURL' => '',
  75.        '/amg/ptk/map/core/formhandlers/AdvancedProfileFormHandler.value.login' => $user,
  76.        '_D:/amg/ptk/map/core/formhandlers/AdvancedProfileFormHandler.value.login' => '',
  77.        '/amg/ptk/map/core/formhandlers/AdvancedProfileFormHandler.value.password' => $password,
  78.        '_D:/amg/ptk/map/core/formhandlers/AdvancedProfileFormHandler.value.password' => '',
  79.        '/amg/ptk/map/core/formhandlers/AdvancedProfileFormHandler.login.x' => 10,
  80.        '/amg/ptk/map/core/formhandlers/AdvancedProfileFormHandler.login.y' => 10,
  81.        '_D:/amg/ptk/map/core/formhandlers/AdvancedProfileFormHandler.login' => '',
  82.        '&_DARGS' => '/gear/static/signInLoginBox.jsp'
  83.        );
  84.        
  85.        $login = $this->curl('http://www.orange.pl/portal/map/map/signin', $data);
  86.        
  87.        if (preg_match('/Podałeś błędny login lub hasło. Sprawdź je i wpisz jeszcze raz/', $login))
  88.        {
  89.            file_put_contents('/dane/mbox.txt', '');
  90.            throw new Exception('Błędne dane logowania.');
  91.        }
  92.    }
  93.    
  94.    /**
  95.      * Funkcja wysyłająca sms, sprawdza jego długość i poprawność numeru
  96.      *
  97.      * @param int $to - adres odbiorcy
  98.      * @param string $message - treść wiadomości
  99.      */
  100.    public function send($to, $message)
  101.    {
  102.        if (strlen($message) == 0 || strlen($message) > 640)
  103.        {
  104.            throw new Exception('Wiadomość musi mieć mniej niż 640 znaków');
  105.        }
  106.        
  107.        $data = array(
  108.        '_dyncharset' => 'UTF-8',
  109.        '/amg/ptk/map/messagebox/formhandlers/MessageFormHandler.type' => 'sms',
  110.        '&_D:/amg/ptk/map/messagebox/formhandlers/MessageFormHandler.type' => '',
  111.        'enabled' => 'false',
  112.        '/amg/ptk/map/messagebox/formhandlers/MessageFormHandler.errorURL' => '/portal/map/map/message_box?mbox_view=newsms',
  113.        '_D:/amg/ptk/map/messagebox/formhandlers/MessageFormHandler.errorURL' => '',
  114.        '/amg/ptk/map/messagebox/formhandlers/MessageFormHandler.successURL' => '/portal/map/map/message_box?mbox_view=messageslist',
  115.        '_D:/amg/ptk/map/messagebox/formhandlers/MessageFormHandler.successURL' =>'',
  116.        'smscounter' => 1,
  117.        'counter' => strlen($message),
  118.        '/amg/ptk/map/messagebox/formhandlers/MessageFormHandler.to' => $to,
  119.        '_D:/amg/ptk/map/messagebox/formhandlers/MessageFormHandler.to' => '',
  120.        '_D:/amg/ptk/map/messagebox/formhandlers/MessageFormHandler.body' => '',
  121.        '/amg/ptk/map/messagebox/formhandlers/MessageFormHandler.body' => $message,
  122.        '_D:/amg/ptk/map/messagebox/formhandlers/MessageFormHandler.create' => '',
  123.        '/amg/ptk/map/messagebox/formhandlers/MessageFormHandler.create' => 'Wyślij',
  124.        '_DARGS' => '/gear/mapmessagebox/smsform.jsp',
  125.        '/amg/ptk/map/messagebox/formhandlers/MessageFormHandler.create.x' => 10,
  126.        '/amg/ptk/map/messagebox/formhandlers/MessageFormHandler.create.y' => 10
  127.        );
  128.                
  129.        $send = $this->curl('http://www.orange.pl/portal/map/map/message_box?_DARGS=/gear/mapmessagebox/smsform.jsp', $data);
  130.        
  131.        if (preg_match('/Niepoprawny numer telefonu/', $send))
  132.        {
  133.            throw new Exception('Podany numer telefonu jest błędny');
  134.        }
  135.        
  136.        if (preg_match('/Wyszukaj wiadomości, których/', $send))
  137.        {
  138.            echo 'Wiadomość została prawidłowo wysłana.';
  139.        }
  140.    }
  141. }
  142. try {
  143.    if (!isset($_POST['login']))
  144.    {
  145.        echo '<form method="post" action="mbox2.php5">Login:<input type="text" name="login">
  146. Hasło:<input type="password" name="haslo">
  147. Do kogo:<input type="text" name="do">
  148. Wiadomość:<textarea name="tresc" rows="10" cols="40"></textarea><input type="submit" name="wyslij" value="Wyślij"></form>';
  149.    }
  150.    else {
  151.    $a = new mbox();
  152.    $a->login($_POST['login'], $_POST['haslo']);
  153.    $a->send($_POST['do'], $_POST['tresc']);
  154.    }
  155. } catch (Exception $e)
  156. {
  157.    echo $e->getMessage();
  158. }
  159.  
  160. ?>


Bardzo proszę o pomoc, na prawdę zależy mi na tym skrypcie..

Czekam na jakąś podpowiedź

Proszę o pomoc

Ten post edytował pablo86 20.07.2009, 14:43:34
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
Mikz
post
Post #2





Grupa: Zarejestrowani
Postów: 48
Pomógł: 3
Dołączył: 7.12.2007

Ostrzeżenie: (0%)
-----


A więc do czego doszedłem po chwili główkowania:

Twój skrypt loguje się do serwisu poprawnie, kiedy jednak próbuje wysłać smsa, po wywaleniu efektu otrzymałem "Przepraszamy. Podana strona nie istnieje", czyli 404 orange.
Może to być niepoprawny adres, może być zabezpieczenie forwardujące do strony 404 kiedy coś mu się nie zgadza.
Pierwsza moja sugestia: Ustaw referera w cURLu.

Poza tym zawartość POST jaką wysyła cURL, oraz zawartość POST jaką wysyła prawdziwy MultiBox nieco się różni:

To jest POST Twojego skryptu:
Kod
  _dyncharset = UTF-8
   /amg/ptk/map/messagebox/formhandlers/MessageFormHandler_type = sms
   _D:/amg/ptk/map/messagebox/formhandlers/MessageFormHandler_type =
   enabled = false
   /amg/ptk/map/messagebox/formhandlers/MessageFormHandler_errorURL = /portal/map/map/message_box?mbox_view=newsms
   _D:/amg/ptk/map/messagebox/formhandlers/MessageFormHandler_errorURL =
   /amg/ptk/map/messagebox/formhandlers/MessageFormHandler_successURL = /portal/map/map/message_box?mbox_view=messageslist
   _D:/amg/ptk/map/messagebox/formhandlers/MessageFormHandler_successURL =
   smscounter = 1
   counter = 3
   /amg/ptk/map/messagebox/formhandlers/MessageFormHandler_to = 666
   _D:/amg/ptk/map/messagebox/formhandlers/MessageFormHandler_to =
   _D:/amg/ptk/map/messagebox/formhandlers/MessageFormHandler_body =
   /amg/ptk/map/messagebox/formhandlers/MessageFormHandler_body = asd
   _D:/amg/ptk/map/messagebox/formhandlers/MessageFormHandler_create =
   /amg/ptk/map/messagebox/formhandlers/MessageFormHandler_create = Wy�lij
   _DARGS = /gear/mapmessagebox/smsform.jsp
   /amg/ptk/map/messagebox/formhandlers/MessageFormHandler_create_x = 10
   /amg/ptk/map/messagebox/formhandlers/MessageFormHandler_create_y = 10


A to jest POST MultiBoxa:

Kod
  _dyncharset = UTF-8
   /amg/ptk/map/messagebox/formhandlers/MessageFormHandler_type = sms
   _D:/amg/ptk/map/messagebox/formhandlers/MessageFormHandler_type =  
   /amg/ptk/map/messagebox/formhandlers/MessageFormHandler_token = 2xV1WzOU7yoO4hU
   _D:/amg/ptk/map/messagebox/formhandlers/MessageFormHandler_token =  
   /amg/ptk/map/messagebox/formhandlers/MessageFormHandler_to = 666
   _D:/amg/ptk/map/messagebox/formhandlers/MessageFormHandler_to =  
   _D:/amg/ptk/map/messagebox/formhandlers/MessageFormHandler_body =  
   /amg/ptk/map/messagebox/formhandlers/MessageFormHandler_body = od mikz:
   /amg/ptk/map/messagebox/formhandlers/MessageFormHandler_create_x = 39
   /amg/ptk/map/messagebox/formhandlers/MessageFormHandler_create_y = 10
   _D:/amg/ptk/map/messagebox/formhandlers/MessageFormHandler_create =  
   /amg/ptk/map/messagebox/formhandlers/MessageFormHandler_create = true
   _DARGS = /gear/guiextensions/multibox_sms.jsp.multibox-SMSForm


Przede wszystkim zwróć uwagę na pole /amg/ptk/map/messagebox/formhandlers/MessageFormHandler_token w którym znajduje się być może jakiś cholerny ciąg weryfikujący czy cokolwiek w tym stylu.

Tyle na dzisiaj, nie mam już siły nad tym siedzieć bo całą noc gryzłem się nad różnymi phpowymi rzeczami. Jutro spróbuję podłubać w tym Twoim skrypcie bo chciałbym go wykorzystać a i mam nadzieję że Tobie w czymś pomogłem.


Aaaa, byłbym zapomniał. Sprawę analizy formularzy zdecydowanie ułatwia wyłączenie javascripta. Multibox nieźle sobie radzi na pure html a formy nie są wtedy submitowane przez ajax.

Przepraszam za posta pod postem, ale za długie było żeby to w jednym upchnąć.
Oto działająca wersja Twojego skryptu:
Kod
<?php
header("Content-type: text/html; charset=UTF-8");

/**
* Licencja CC BY-NC-SA
* <a href="http://creativecommons.org/licenses/by-nc-sa/3.0/deed.pl" target="_blank">http://creativecommons.org/licenses/by-nc-sa/3.0/deed.pl</a>
* Klasa mbox umożliwiająca wysyłanie wiadomości SMS
* @author Kacper 'kacka' Szurek
* @mail kacperszurek (poczta w gmail.com)
* Jeżeli się przydało - napisz
* Chcesz podziękować, pomóc masz pytanie - napisz
* Skrypt przechowuje cookie w katalogu /dane/mbox.txt
*
*/
class mbox
{
   /**
    * Przechowuje identyfikator połączenia curl
    *
    * @var $ch
    */
   protected $_curl;

   /**
    * Ułatwienie dostępu do curl
    *
    * @param string $url - adres strony
    * @param array $post - opcjonalnie tablica parametrów
    * @return string - zwraca pobraną treść
    */
   public function curl($url, $post = null)
   {
       $this->_curl = curl_init();
      
       $var = array(
           CURLOPT_URL => $url,
           CURLOPT_COOKIEJAR => dirname(__FILE__).'/dane/mbox.txt',
           CURLOPT_COOKIEFILE => dirname(__FILE__).'/dane/mbox.txt',
           CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; pl; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6',
           CURLOPT_RETURNTRANSFER => true,
           CURLOPT_FOLLOWLOCATION => true);
                  
       if ( !is_null($post) ) {
           foreach ($post as $option => $value) {
               $tmp .= $option. '=' .urlencode($value). '&';
           }
          
           $var[CURLOPT_POST] = true;
           $var[CURLOPT_POSTFIELDS] = $tmp;
       }
          
       curl_setopt_array($this->_curl, $var);
      
       $return = curl_exec($this->_curl);
  
       return $return;
      
       curl_close($this->_curl);
   }

   /**
    * Funkcja logująca do orange.pl
    *
    * @param string $user - użytkownik
    * @param string $password - hasło
    */
   public function login($user, $password)
   {
       $data = array(
       '_dyncharset' => 'UTF-8',
       '/amg/ptk/map/core/formhandlers/AdvancedProfileFormHandler.loginErrorURL' => 'http://www.orange.pl/portal/map/map/signin',
       '_D:/amg/ptk/map/core/formhandlers/AdvancedProfileFormHandler.loginErrorURL=' => '',
       '/amg/ptk/map/core/formhandlers/AdvancedProfileFormHandler.loginSuccessURL' => 'http://www.orange.pl/portal/map/map/pim',
       '_D:/amg/ptk/map/core/formhandlers/AdvancedProfileFormHandler.loginSuccessURL' => '',
       '/amg/ptk/map/core/formhandlers/AdvancedProfileFormHandler.value.login' => $user,
       '_D:/amg/ptk/map/core/formhandlers/AdvancedProfileFormHandler.value.login' => '',
       '/amg/ptk/map/core/formhandlers/AdvancedProfileFormHandler.value.password' => $password,
       '_D:/amg/ptk/map/core/formhandlers/AdvancedProfileFormHandler.value.password' => '',
       '/amg/ptk/map/core/formhandlers/AdvancedProfileFormHandler.login.x' => 10,
       '/amg/ptk/map/core/formhandlers/AdvancedProfileFormHandler.login.y' => 10,
       '_D:/amg/ptk/map/core/formhandlers/AdvancedProfileFormHandler.login' => '',
       '&_DARGS' => '/gear/static/signInLoginBox.jsp'
       );
      
       $login = $this->curl('http://www.orange.pl/portal/map/map/signin', $data);
      
       if (preg_match('/Podałeś błędny login lub hasło. Sprawdź je i wpisz jeszcze raz/', $login))
       {
           file_put_contents('/dane/mbox.txt', '');
           throw new Exception('Błędne dane logowania.');
       }
   }
  
   /**
    * Funkcja wysyłająca sms, sprawdza jego długość i poprawność numeru
    *
    * @param int $to - adres odbiorcy
    * @param string $message - treść wiadomości
    */
   public function send($to, $message)
   {
       if (strlen($message) == 0 || strlen($message) > 640)
       {
           throw new Exception('Wiadomość musi mieć mniej niż 640 znaków');
       }
      
       //Dodał Mikz
       $tokenStack = $this->curl('http://www.orange.pl/portal/map/map/message_box?mbox_view=newsms');
      
       $position0 = strpos($tokenStack, '/amg/ptk/map/messagebox/formhandlers/MessageFormHandler.token');
       $position = $position0-37;
      
       $token =  substr($tokenStack, $position, 15);
       /////////////
      
       $data = array(
       '_dyncharset' => 'UTF-8',
       '/amg/ptk/map/messagebox/formhandlers/MessageFormHandler.type' => 'sms',
       '_D:/amg/ptk/map/messagebox/formhandlers/MessageFormHandler.type' => '',
       'enabled' => 'true',
       '/amg/ptk/map/messagebox/formhandlers/MessageFormHandler.token' => $token,
       '_D:/amg/ptk/map/messagebox/formhandlers/MessageFormHandler.token' => '',
       '/amg/ptk/map/messagebox/formhandlers/MessageFormHandler.errorURL' => '/portal/map/map/message_box?mbox_view=newsms',
       '_D:/amg/ptk/map/messagebox/formhandlers/MessageFormHandler.errorURL' => '',
       '/amg/ptk/map/messagebox/formhandlers/MessageFormHandler.successURL' => '/portal/map/map/message_box?mbox_view=messageslist',
       '_D:/amg/ptk/map/messagebox/formhandlers/MessageFormHandler.successURL' =>'',
       '/amg/ptk/map/messagebox/formhandlers/MessageFormHandler.to' => $to,
       '_D:/amg/ptk/map/messagebox/formhandlers/MessageFormHandler.to' => '',
       '_D:/amg/ptk/map/messagebox/formhandlers/MessageFormHandler.body' => '',
       '/amg/ptk/map/messagebox/formhandlers/MessageFormHandler.body' => $message,
       '_D:/amg/ptk/map/messagebox/formhandlers/MessageFormHandler.create' => '',
       '/amg/ptk/map/messagebox/formhandlers/MessageFormHandler.create' => 'Wyślij',
       '_DARGS' => '/gear/mapmessagebox/smsform.jsp',
       '/amg/ptk/map/messagebox/formhandlers/MessageFormHandler.create.x' => 10,
       '/amg/ptk/map/messagebox/formhandlers/MessageFormHandler.create.y' => 10
       );
      
       curl_setopt ($this->_curl, CURLOPT_REFERER, 'http://www.orange.pl/portal/map/map/message_box?mbox_view=newsms');
      
       $send = $this->curl('http://www.orange.pl/portal/map/map/message_box?_DARGS=/gear/mapmessagebox/smsform.jsp', $data);
      
       if (preg_match('/Niepoprawny numer telefonu/', $send))
       {
           throw new Exception('Podany numer telefonu jest błędny');
       }
      
       if (preg_match('/Wyszukaj wiadomości, których/', $send))
       {
           echo 'Wiadomość została prawidłowo wysłana.';
       }
   }
}


try {
   if (!isset($_POST['login']))
   {
       echo '<form method="post" action="test.php">Login:<input type="text" name="login">
Hasło:<input type="password" name="haslo">
Do kogo:<input type="text" name="do">
Wiadomość:<textarea name="tresc" rows="10" cols="40"></textarea><input type="submit" name="wyslij" value="Wyślij"></form>';
   }
   else {
   $a = new mbox();
   $a->login($_POST['login'], $_POST['haslo']);
   $a->send($_POST['do'], $_POST['tresc']);
   }
} catch (Exception $e)
{
   echo $e->getMessage();
}

?>


Jeszcze Ci jakieś notice'y wywala po submicie, ale generalnie smsy wysyła.

Pozdrawiam :-).

Będę wdzięczny jeśli wyślesz mi całość skryptu przez PW jak go skończysz :-).

Pozdrawiam

Ten post edytował Mikz 1.08.2009, 04:54:16
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 14.10.2025 - 17:33