Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [CURL] Logowanie Allegro
hostcom
post 20.12.2014, 08:33:25
Post #1





Grupa: Zarejestrowani
Postów: 46
Pomógł: 0
Dołączył: 1.03.2008

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


Witam
Piszę klasę do logowania allegro i mam następujący problem.
Otóż po przesłaniu wszystkich parametrów wymaganych do logowania występuję po stronie allegro następujący komunikat:
"Ten formularz stracił ważność, wyślij go ponownie."

  1. ?php
  2.  
  3. $login='';
  4. $password='';
  5.  
  6. class Allegro{
  7. public static function curl ($url, $post = NULL, $ref = NULL, $follow = 1, $header = 1, $post_type = NULL)
  8. {
  9. $ch = curl_init ($url);
  10. $headers = array('Accept-Language: pl,en-us;q=0.7,en;q=0.3','Accept-Charset: ISO-8859-2,utf-8;q=0.7,*;q=0.7', 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8');
  11. curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  12. curl_setopt($ch, CURLOPT_ENCODING, 'deflate');
  13. curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; pl; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7');
  14. curl_setopt($ch,CURLOPT_RETURNTRANSFER, 1);
  15. // Zapisywanie ciastek do pliku
  16. curl_setopt($ch,CURLOPT_COOKIEJAR, dirname(__FILE__).'/cookie.txt');
  17. curl_setopt($ch,CURLOPT_COOKIEFILE, dirname(__FILE__).'/cookie.txt');
  18. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
  19. if ( ! empty($post))
  20. {
  21. $postVars='';
  22. foreach ($post as $option => $value)
  23. $postVars .= $option.'='.urlencode($value).'&';
  24. curl_setopt($ch, CURLOPT_POST, 1);
  25. curl_setopt($ch, CURLOPT_POSTFIELDS, $postVars);
  26. }
  27. if($ref)
  28. curl_setopt($ch, CURLOPT_REFERER, $ref);
  29. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  30. curl_setopt($ch, CURLOPT_HEADER, 1);
  31. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, $follow);
  32. $r = curl_exec($ch);
  33. curl_close($ch);
  34. return $r;
  35. }
  36.  
  37.  
  38. public function Login($login,$password){
  39. global $URL;
  40.  
  41. $login = $this->curl('http://allegro.pl');
  42. $login = $this->curl('https://ssl.allegro.pl/fnd/authentication/',null,'http://allegro.pl',1);
  43.  
  44. preg_match_all('/\shref="(.+?)"\s/', $login, $rand1);
  45. preg_match_all('/\svalue="(.+?)"\s/', $login, $rand);
  46. echo'<pre>';
  47. print_r($rand);
  48.  
  49.  
  50. $POST=array(
  51. 'userForm[redirectUri]'=>$rand[1][0],
  52. 'userForm[clientId] '=>$rand[1][1],
  53. 'userForm[responseType]'=>$rand[1][2],
  54. 'userForm[scope]'=>$rand[1][3],
  55. 'userForm[state]'=>$rand[1][4],
  56. 'userForm[login]'=>$login,
  57. 'userForm[password]'=>$password,
  58. 'userForm[_token]'=>$rand[1][5]
  59.  
  60. );
  61.  
  62. echo$login = $this->curl('https://ssl.allegro.pl/fnd/authentication/', $POST,'https://ssl.allegro.pl/fnd/authentication/?response_type='.$rand[1][2].'&client_id='.$rand[1][1].'&redirect_uri='.$rand[1][0].'&scope='.$rand[1][3].'&state='.$rand[1][3]);
  63. $login = $this->curl('http://allegro.pl/myaccount/');
  64. if (preg_match('/Wyloguj/',$login))
  65. return true;
  66. }
  67.  
  68.  
  69.  
  70.  
  71. }
  72.  
  73.  
  74.  
  75. ?>


Mógłby ktoś sprawdzić co jest nie tak? ewentulanie przetestować?
Dzieki za pomoc
Go to the top of the page
+Quote Post
viking
post 20.12.2014, 08:43:00
Post #2





Grupa: Zarejestrowani
Postów: 6 378
Pomógł: 1116
Dołączył: 30.08.2006

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


Dane z allegro pobiera się przez oficjalne webapi a nie curla.


--------------------
Go to the top of the page
+Quote Post
hostcom
post 20.12.2014, 08:53:03
Post #3





Grupa: Zarejestrowani
Postów: 46
Pomógł: 0
Dołączył: 1.03.2008

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


Wiem...
ale w tym przypadku webapi mnie nie interesuje
Go to the top of the page
+Quote Post
Daimos
post 20.12.2014, 12:54:18
Post #4





Grupa: Zarejestrowani
Postów: 1 319
Pomógł: 118
Dołączył: 26.11.2003
Skąd: Lublin

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


Cytat(hostcom @ 20.12.2014, 08:53:03 ) *
Wiem...
ale w tym przypadku webapi mnie nie interesuje

Wolisz jechać do Warszawy przez Rzym?! Twoja sprawa, więc masz co robić, bo z tego co widzę, to allegro chyba wrzuca ciastka za pomocą js.

Musisz zrobić tak, aby Twój curl wykonywał javascript przed wypluciem strony smile.gif)


--------------------
scriptun.com. Startup z poradnikami do gier ttp.zone i ttpzone.pl
Go to the top of the page
+Quote Post
jackraymund
post 21.12.2014, 03:40:52
Post #5





Grupa: Zarejestrowani
Postów: 217
Pomógł: 21
Dołączył: 10.06.2011
Skąd: Głogów

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


No to musisz spróbować po kolei wykonać zapytania. Aby się dowiedzieć co jest nie halo. Sam zgaduje że chodzi o client_id i tokeny, które samemu generujesz...
Na start CURLOPT_FOLLOWLOCATION FALSE, aby nie robiło redirectów.
1. Wchodzimy GET na https://ssl.allegro.pl/fnd/authentication/
Odbieramy 302
Location: https://ssl.allegro.pl/fnd/authentication/?...xxxxx219f%22%7D
2. Pobieramy dane i wchodzimy GET'em ten link.
3. Zbieramy dane do postu(tokeny tokeny tokeny!)
http://screenshooter.net/100008827/shnnojn
4. Wysyłamy na https://ssl.allegro.pl/fnd/authentication/
5. Wchodzimy w redirect 4 razy, i w ostatnim redirect'ie jak pewnie zauważyłeś zmieniła się jedynie domena z https na http, a reszta query jest taka sama, także wystarczy podmienić domene do ostatniego get'a.

@up
wyłącz js w przeglądarce, normalnie można się zalogować


--------------------
Wykonuje zlecenia na pobieranie danych ze stron i różne boty.
Go to the top of the page
+Quote Post
hostcom
post 22.12.2014, 21:11:58
Post #6





Grupa: Zarejestrowani
Postów: 46
Pomógł: 0
Dołączył: 1.03.2008

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


To niw to. próbowałem dalej to samo


Problem rozwiązany....

Poniżej zamieszczam skrypt jak by ktoś potzrebował...

  1. <?php
  2. /* PHP logowanie Allegro 2014-12-22
  3. ** admin(at)smsarena.pl
  4. */
  5.  
  6. $login='';
  7. $password=''
  8. $new = new Allegro();
  9. $ret=$new->Login($login,$password);
  10.  
  11. print_r($ret);
  12. ;
  13. class Allegro{
  14. public static function curl ($url, $post = NULL, $ref = NULL, $follow = 1, $header = 1, $post_type = NULL)
  15. {global $cookies;
  16. $ch = curl_init ($url);
  17. $headers = array('Accept-Language: pl,en-us;q=0.7,en;q=0.3','Accept-Charset: ISO-8859-2,utf-8;q=0.7,*;q=0.7', 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8');
  18. curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  19. curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; pl; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7');
  20. curl_setopt($ch,CURLOPT_RETURNTRANSFER, 1);
  21. curl_setopt($ch, CURLOPT_COOKIE, base64_decode($cookies));
  22. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
  23. if ( ! empty($post))
  24. {
  25. $postVars='';
  26. foreach ($post as $option => $value)
  27. $postVars .= $option.'='.urlencode($value).'&';
  28. curl_setopt($ch, CURLOPT_POST, 1);
  29. curl_setopt($ch, CURLOPT_POSTFIELDS, $postVars);
  30. }
  31. if($ref)
  32. curl_setopt($ch, CURLOPT_REFERER, $ref);
  33. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  34. curl_setopt($ch, CURLOPT_HEADER, 1);
  35. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, $follow);
  36. curl_setopt($ch, CURLINFO_HEADER_OUT,1);
  37. $r = curl_exec($ch);
  38. $set=$new = new Allegro();
  39. $set->set_cookies($r);
  40. curl_close($ch);
  41. return $r;
  42. }
  43. public function Login($log,$pass){
  44. global $cookies;
  45. $login = $this->curl('http://allegro.pl');
  46. $login = $this->curl('https://ssl.allegro.pl/fnd/authentication/',null,'http://allegro.pl',0);
  47. preg_match_all('/href="(.+?)"/', $login, $rand1);
  48. preg_match_all('/\svalue="(.+?)"\s/', $login, $rand);
  49. $login = $this->curl(urldecode($rand1[1][0]),null,'http://allegro.pl',1);
  50. preg_match_all('/href="(.+?)"/', $login, $rand1);
  51. preg_match_all('/\svalue="(.+?)"\s/', $login, $rand);
  52. $POST=array(
  53. 'userForm[redirectUri]'=>$rand[1][0],
  54. 'userForm[clientId] '=>$rand[1][1],
  55. 'userForm[responseType]'=>$rand[1][2],
  56. 'userForm[scope]'=>$rand[1][3],
  57. 'userForm[state]'=>$rand[1][4],
  58. 'userForm[login]'=>$log,
  59. 'userForm[password]'=>$pass,
  60. 'userForm[_token]'=>$rand[1][5]);
  61. $login = $this->curl('https://ssl.allegro.pl/fnd/authentication/', $POST,urldecode($rand1[1][0]),1);
  62. preg_match_all('/href="(.+?)"/', $login, $rand1);
  63. preg_match_all('/\svalue="(.+?)"\s/', $login, $rand);
  64. $POST=array(
  65. 'userForm[redirectUri]'=>$rand[1][0],
  66. 'userForm[clientId] '=>$rand[1][1],
  67. 'userForm[responseType]'=>$rand[1][2],
  68. 'userForm[scope]'=>$rand[1][3],
  69. 'userForm[state]'=>str_replace(array('&quot;'),array('"'),$rand[1][4]),
  70. 'userForm[login]'=>$log,
  71. 'userForm[password]'=>$pass,
  72. 'userForm[_token]'=>$rand[1][5]
  73. );
  74. $login = $this->curl('https://ssl.allegro.pl/fnd/authentication/', $POST,urldecode($rand1[1][0]),1);
  75. $login = $this->curl('http://allegro.pl/myaccount/');
  76. if (preg_match('/Licytacje i Kup Teraz/',$login))
  77. return array('status'=>true,'cookies'=>$cookies);
  78. else{
  79. return array('status'=>false,'cookies'=>false);
  80. }
  81. }
  82. public static function set_cookies($r){
  83. global $cookies;
  84. $cookies=@explode('; ',base64_decode($cookies));
  85. preg_match_all('#Set-Cookie: (.+?)\n#is', $r, $ccc);
  86. $cookies=$cookies;
  87. $count = count($ccc[1]);
  88. for($i=0;$i<$count;$i++) {
  89. $ex = explode('=',$ccc[1][$i]);
  90. $cookies[$ex[0]]=implode('=',$ex);
  91. }
  92. $cookies=trim(base64_encode(str_replace(array("\n","\r"),'',@implode('; ',$cookies)) ));
  93. }
  94. }
  95. ?>


cookies są przechowywane w zmiennej. bedą potrzeby przy rozbudowie
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: 26.06.2025 - 23:05