Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP]Własna bramka sms
nawasaqi
post 16.11.2015, 15:46:13
Post #1





Grupa: Zarejestrowani
Postów: 63
Pomógł: 0
Dołączył: 28.12.2010

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


Witam wszystkich...
Mam pytanie postanowiłem sobie zrobić bramkę sms wykorzystując do tego nieżytkowany modem, wszystko sprawdziłem na swoim podręcznym raspberry i działa idealnie.
Ale chciałem pójść krok dalej i mam problem mianowicie aby wysłać sms wystarczy pobrac token a potem wysłać sms"
  1. curl "http://192.168.8.1/api/webserver/token"
  2. <?xml version="1.0" encoding="UTF-8"?>
  3. <response>
  4. <token>695328588</token>
  5. </response>


i wysyłka sms:
  1. curl "http://192.168.8.1/api/sms/send-sms" -H "__RequestVerificationToken: 695328588" --data "<?xml version='1.0' encoding='UTF-8'?><request><Index>-1</Index><Phones><Phone>xxxxxxxxx</Phone></Phones><Sca></Sca><Content>ala ma kota</Content><Length>-1</Length><Reserved>1</Reserved><Date>-1</Date></request>"


Jak wklejam taką wersję do konsoli sms dochodzą nie ma problemu.
Ale jak tylko chcę to wysłać za pomocą PHP jest lipa token pobiera poprawnie ale nie wysyła. Czy możliwe że nie obsługuje curl w php takiej składni długiej questionmark.gif Czy coś źle zrobiłem??

  1. <?php
  2. $url = ('http://192.168.8.1/api/webserver/token');
  3. $ch = curl_init();
  4. curl_setopt($ch, CURLOPT_URL,$url);
  5. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  6. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  7. curl_setopt($ch, CURLOPT_HEADER,0);
  8. $curl_scraped_page = curl_exec($ch);
  9. curl_close($ch);
  10.  
  11.  
  12. preg_match('#<token>(.+?)</token>#si', $curl_scraped_page, $matches);
  13. $token = ($matches[1]);
  14.  
  15. $url = ("http://192.168.8.1/api/sms/send-sms -H __RequestVerificationToken: ".$token." --data <?xml version='1.0' encoding='UTF-8'?><request><Index>-1</Index><Phones><Phone>xxxxxxxxx</Phone></Phones><Sca></Sca><Content>ala ma kota</Content><Length>-1</Length><Reserved>1</Reserved><Date>-1</Date></request>");
  16.  
  17. $ch = curl_init();
  18. curl_setopt($ch, CURLOPT_URL,$url);
  19. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  20. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  21. curl_setopt($ch, CURLOPT_HEADER,0);
  22. $curl_scraped_page = curl_exec($ch);
  23. curl_close($ch);
  24.  
  25. echo ($curl_scraped_page);
  26.  
  27. ?>



Pomożecie Panowie co jest nie tak questionmark.gif?

Ten post edytował nawasaqi 16.11.2015, 15:50:52
Go to the top of the page
+Quote Post
Pyton_000
post 16.11.2015, 15:58:51
Post #2





Grupa: Zarejestrowani
Postów: 8 068
Pomógł: 1414
Dołączył: 26.10.2005

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


Bo robisz to źle.

Wszystkie parametry z CURL musisz podać pod opowiednie opcje dla CURL w PHP
Go to the top of the page
+Quote Post
nawasaqi
post 16.11.2015, 16:27:53
Post #3





Grupa: Zarejestrowani
Postów: 63
Pomógł: 0
Dołączył: 28.12.2010

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


Mój angielski niestety nie jest za dobry ale z tego co znalazłem to mam to umieścić w POSTFIELDS ale dalej lipa:

  1. <?php
  2. $url = ("http://192.168.8.1/api/sms/send-sms");
  3.  
  4. $ch = curl_init();
  5. curl_setopt($ch, CURLOPT_URL,$url);
  6. curl_setopt($ch, CURLOPT_POST, 1);
  7. curl_setopt($ch, CURLOPT_POSTFIELDS, (" -H __RequestVerificationToken: ".$token." --data <?xml version='1.0' encoding='UTF-8'?><request><Index>-1</Index><Phones><Phone>xxxxxxxxx</Phone></Phones><Sca></Sca><Content>Ala ma kota</Content><Length>-1</Length><Reserved>1</Reserved><Date>-1</Date></request>");
  8. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1));
  9. curl_setopt($ch, CURLOPT_HEADER,0);
  10. $curl_scraped_page = curl_exec($ch);
  11. curl_close($ch);
  12.  
  13. ?>


Ten post edytował nawasaqi 16.11.2015, 16:29:16
Go to the top of the page
+Quote Post
Pyton_000
post 16.11.2015, 17:21:21
Post #4





Grupa: Zarejestrowani
Postów: 8 068
Pomógł: 1414
Dołączył: 26.10.2005

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


Kod
<?php
$url = ("http://192.168.8.1/api/sms/send-sms");

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    "__RequestVerificationToken: ".$token
));
curl_setopt($ch, CURLOPT_POSTFIELDS, ("<?xml version='1.0' encoding='UTF-8'?><request><Index>-1</Index><Phones><Phone>xxxxxxxxx</Phone></Phones><Sca></Sca><Content>Ala ma kota</Content><Length>-1</Length><Reserved>1</Reserved><Date>-1</Date></request>");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1));
curl_setopt($ch, CURLOPT_HEADER,0);
$curl_scraped_page = curl_exec($ch);
curl_close($ch);
Go to the top of the page
+Quote Post
nawasaqi
post 16.11.2015, 18:29:26
Post #5





Grupa: Zarejestrowani
Postów: 63
Pomógł: 0
Dołączył: 28.12.2010

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


@Pyton_000 dalej nic ;(
Go to the top of the page
+Quote Post
Pyton_000
post 16.11.2015, 18:30:21
Post #6





Grupa: Zarejestrowani
Postów: 8 068
Pomógł: 1414
Dołączył: 26.10.2005

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


no to zobacz sobie co w API dostajesz...
Go to the top of the page
+Quote Post
nawasaqi
post 17.11.2015, 08:50:06
Post #7





Grupa: Zarejestrowani
Postów: 63
Pomógł: 0
Dołączył: 28.12.2010

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


Oki odpaliłem to pod wamp'em i znalazłem co jest nie tak... nawiasy ;/ po prostu tępa strzała ze mnie... w CURLOPT_POSTFIELDS brakuje jednego zamykającego a w CURLOPT_RETURNTRANSFER jeden za dużo wink.gif

Ten post edytował nawasaqi 17.11.2015, 09:30:21
Go to the top of the page
+Quote Post

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

 



RSS Wersja Lo-Fi Aktualny czas: 25.04.2025 - 05:36