Advertisement
thimo

Spreadshirt get Design Data from image URL

Mar 21st, 2018
622
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. $user_agent = 'test/1.0 (http://tshirtfamily.fr/; test@mail.de)';
  4. ini_set('user_agent', $user_agent);
  5.  
  6. // Default values
  7. $designId = 0;
  8. $url = '';
  9.  
  10. if (!empty($_REQUEST['url'])) {
  11.     $url = strip_tags(htmlentities($_REQUEST['url']));
  12.     preg_match('/designs\/(\w*)/i', $url, $matches);
  13.     $designId = $matches[1];
  14. }
  15.  
  16. $site_url = 'https://api.spreadshirt.net/api/v1/shops/205909/designs/'.$designId.'?locale=fr_FR&fullData=true';
  17.  
  18. $header = array();
  19. $header[] = createSprdAuthHeader("GET", $site_url);
  20. $header[] = "Content-Type: application/xml";
  21.  
  22.  
  23. $ch = curl_init();
  24. curl_setopt($ch, CURLOPT_URL, $site_url);
  25. curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  26. curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
  27. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  28. curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
  29. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  30. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  31.  
  32. $resultat = curl_exec($ch);
  33.  
  34. print_r($resultat);
  35.  
  36.  
  37. function createSprdAuthHeader($method, $url)
  38. {
  39.     $apiKey = "my-api-key";
  40.     $secret = "my-api-secret";
  41.     $time = time()*1000;
  42.  
  43.     $data = "$method $url $time";
  44.     $sig = sha1("$data $secret");
  45.  
  46.     return "Authorization: SprdAuth apiKey=\"$apiKey\", data=\"$data\", sig=\"$sig\"";
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement