Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP]API Inpost Tracking pomoc we wdrożeniu, api inpost
casperii
post 8.01.2018, 19:29:05
Post #1





Grupa: Zarejestrowani
Postów: 680
Pomógł: 28
Dołączył: 14.08.2014

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


Panowie próbuje zrozumieć dokumentacje API Inpost. Z tego co rozumiem, nie jest wymagane żadne tokeny, hasła, klucze etc. aby sprawdzać tracking przesyłki.
https://docs.inpost24.com/display/PL/%5B1.2...aprzesy%C5%82ki

<?php
require_once 'vendor/restApi.php';
$restApi = new RestApi(array(

));

print_r($restApi->getResponse());
print_r(json_decode($restApi->getResponse()));

?>


Poniżej restApi.php

  1. <?php
  2. class RestApi
  3. {
  4. protected $response;
  5. protected $info;
  6. protected $errno;
  7. protected $error;
  8. public function __construct($params)
  9. {
  10. $this->response = $this->curlInit(array(
  11. 'token' => $params['token'],
  12. 'url' => $params['url'],
  13. 'methodType' => $params['methodType'],
  14. 'params' => $params['params']
  15. ));
  16. }
  17. private function curlInit($params = array())
  18. {
  19. $ch = curl_init();
  20. switch($params['methodType']){
  21. case 'GET':
  22. curl_setopt($ch, CURLOPT_HTTPHEADER, array('HTTP/1.1: GET') );
  23. $getParams = null;
  24. if(!empty($params['params'])){
  25. foreach($params['params'] as $field_name => $field_value){
  26. $getParams .= $field_name.'='.urlencode($field_value).'&';
  27. }
  28. curl_setopt($ch, CURLOPT_URL, $params['url'].'?'.$getParams);
  29. }else{
  30. curl_setopt($ch, CURLOPT_URL, $params['url'].'?'.$params['token']);
  31. }
  32. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
  33. break;
  34. case 'POST':
  35. $string = json_encode($params['params']);
  36. #$string = $params['params'];
  37. curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-HTTP-Method-Override: POST') );
  38. curl_setopt($ch, CURLOPT_URL, $params['url'].'?token='.$params['token']);
  39. curl_setopt($ch, CURLOPT_POST, true);
  40. curl_setopt($ch, CURLOPT_POSTFIELDS, $string);
  41. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
  42. curl_setopt($ch, CURLOPT_HTTPHEADER, array(
  43. 'Content-Type: application/json',
  44. 'Content-Length: ' . strlen($string))
  45. );
  46. break;
  47. case 'PUT':
  48. $string = json_encode($params['params']);
  49. #$string = $params['params'];
  50. curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-HTTP-Method-Override: PUT') );
  51. curl_setopt($ch, CURLOPT_URL, $params['url'].'?token='.$params['token']);
  52. curl_setopt($ch, CURLOPT_POST, true);
  53. curl_setopt($ch, CURLOPT_POSTFIELDS, $string);
  54. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
  55. curl_setopt($ch, CURLOPT_HTTPHEADER, array(
  56. 'Content-Type: application/json',
  57. 'Content-Length: ' . strlen($string))
  58. );
  59. break;
  60. }
  61. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  62. $result = curl_exec($ch);
  63. $this->info = curl_getinfo($ch);
  64. $this->errno = curl_errno($ch);
  65. $this->error = curl_error($ch);
  66. if ($this->info['http_code'] != 200) {
  67.  
  68.  
  69. $response = json_encode(array(
  70. 'message' => 'Request failed',
  71. 'type' => 'RequestErrors',
  72. 'code_errors' => $this->config['errorCodes'][$info['http_code']]
  73. ));
  74.  
  75.  
  76. }
  77. return $result;
  78. }
  79. public function getResponse()
  80. {
  81. return $this->response;
  82. }
  83. public function getInfo()
  84. {
  85. return $this->info;
  86. }
  87. public function getErrno()
  88. {
  89. return $this->errno;
  90. }
  91. public function getError()
  92. {
  93. return $this->error;
  94. }
  95. }
  96. ?>


Nikt nie wie ? sad.gif
Go to the top of the page
+Quote Post
Pyton_000
post 8.01.2018, 20:23:46
Post #2





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

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


Bo nie zadałeś pytania?
Go to the top of the page
+Quote Post
casperii
post 16.01.2018, 21:51:35
Post #3





Grupa: Zarejestrowani
Postów: 680
Pomógł: 28
Dołączył: 14.08.2014

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


A no tak tongue.gif

Chodzi mi o to by pobrać informacje o danej przesyłce smile.gif

@Pyton_000 podpowiesz jak się do tego dobrać ?smile.gif

Na prawdę nikt się nie bawił API Inpostu?
Po zagłębieniu się w dokumentacje API Inpost, doczytać się można , że API zostaje wyłączone z końcem lutego i od marca będzie tylko API shipx.

Próbuje pobrać informację o przesyłce poprzez spreparowany link:
https://api-shipx-pl.easypack24.net/v1/trac...787200032505244

ale za cholerę nie wiem jak według API to powinno być.


Ten post edytował casperii 9.01.2018, 20:02:36
Go to the top of the page
+Quote Post
Pyton_000
post 16.01.2018, 22:05:12
Post #4





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

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


No ale do cholery czego nie wiesz? Nie umiesz pobrać danych ? Nie umiesz sparsować JSON? Nie umies PHP?
Go to the top of the page
+Quote Post
casperii
post 16.01.2018, 22:08:33
Post #5





Grupa: Zarejestrowani
Postów: 680
Pomógł: 28
Dołączył: 14.08.2014

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


  1. $url = 'https://api-shipx-pl.easypack24.net/v1/tracking/681589165787200032505244';
  2. $ch = curl_init();
  3. curl_setopt($ch, CURLOPT_URL, $url);
  4. curl_setopt($ch, CURLOPT_HTTPHEADER, array('HTTP/1.1: GET') );
  5.  
  6. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
  7. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  8. $result = curl_exec($ch);
  9.  
  10. print_r($result);


nie wyświetla nic.

jak dodam:

  1. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);
  2. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);


wywala:
400 Bad request
Your browser sent an invalid request.
Go to the top of the page
+Quote Post
aras785
post 16.01.2018, 22:12:31
Post #6





Grupa: Zarejestrowani
Postów: 859
Pomógł: 177
Dołączył: 29.10.2009

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


  1. <?php
  2. $data = file_get_contents('https://api-shipx-pl.easypack24.net/v1/tracking/681589165787200032505244');
  3. echo '<pre>';
  4. print_r(json_decode($data));
  5. echo '</pre>';
  6. ?>


lub curl:

  1. <?php
  2. $url = 'https://api-shipx-pl.easypack24.net/v1/tracking/681589165787200032505244';
  3. $ch = curl_init();
  4. curl_setopt($ch, CURLOPT_URL, $url);
  5. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  6. $result = curl_exec($ch);
  7.  
  8. echo '<pre>';
  9. print_r(json_decode($result));
  10. echo '</pre>';
  11. ?>



wklej kod np. tutaj: http://phpfiddle.org/ i sprawdź jak działa smile.gif

Ten post edytował aras785 16.01.2018, 22:25:48
Go to the top of the page
+Quote Post
casperii
post 16.01.2018, 23:41:46
Post #7





Grupa: Zarejestrowani
Postów: 680
Pomógł: 28
Dołączył: 14.08.2014

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


DZIĘKI @aras785
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: 28.03.2024 - 18:47