Advertisement
Guest User

Untitled

a guest
Dec 17th, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. <?php
  2.  
  3. // Token generation
  4. $timestamp = time();
  5. $uri = "https://api.website.com/post.json";
  6. $password = "somePassword";
  7.  
  8. $security_token = sha1($timestamp.$uri.$password);
  9.  
  10. // Webservice call
  11. $ch = curl_init();
  12. curl_setopt($ch, CURLOPT_URL, $uri);
  13. curl_setopt($ch, CURLOPT_HEADER, false);
  14. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  15. $post = array();
  16. $post["timestamp"] = $timestamp;
  17. $post["security_token"] = $security_token;
  18. curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post));
  19. curl_setopt($ch, CURLOPT_POST, true);
  20.  
  21. // USE THIS CODE TO CHECK THAT SSL CERTIFICATE IS VALID:
  22. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
  23. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
  24. curl_setopt($ch, CURLOPT_CAINFO, "path/to/certifcate/file/certificate.crt");
  25.  
  26. $ret = curl_exec($ch);
  27.  
  28. // Check response
  29. if(curl_errno($ch)) {
  30. curl_close($ch);
  31. die("CURL error: ".curl_error($ch));
  32. }
  33.  
  34. $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  35. if($http_code != 200) {
  36. die("Server error, HTTP code: $http_code");
  37. }
  38.  
  39. curl_close($ch);
  40.  
  41. // Parse response
  42. try {
  43. $json = json_decode($ret);
  44. var_dump($json);
  45. }
  46. catch(Exception $e) {
  47. die("Failed to decode server response");
  48. }
  49.  
  50. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement