Advertisement
Guest User

Untitled

a guest
Feb 11th, 2016
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.40 KB | None | 0 0
  1. <?php
  2. $username = 'xxx';
  3. $password = 'xxx';
  4. $userpass = $username . ":" . $password;
  5. $headers=array(
  6.         'Authorization: Basic '. base64_encode($userpass),
  7.         'Accept: */*',
  8.         'Accept-Encoding: gzip, deflate'
  9. );
  10.  
  11. const ECSET_AUTH = 'xxx';
  12.  
  13. if(isset($_REQUEST['ecset'])){
  14.     SendEcset($_REQUEST['ecset']);
  15. }
  16.  
  17. function SendEcset($ecset){
  18.     global $headers, $username, $password;
  19.     $params = array(
  20.         "client_id" => "xxx",
  21.         "client_secret" => "xxx",
  22.         "grant_type" => "client_credentials",
  23.     );
  24.    
  25.     $curl = curl_init(ECSET_AUTH);
  26.     curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
  27.     curl_setopt($curl, CURLOPT_HEADER, true);
  28.     curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  29.     curl_setopt($curl, CURLOPT_POST, true);
  30.     curl_setopt($curl, CURLOPT_HEADER,'Content-Type: application/x-www-form-urlencoded');
  31.  
  32.     $postData = "";
  33.  
  34.     foreach($params as $k => $v)
  35.     {
  36.        $postData .= $k . '='.urlencode($v).'&';
  37.     }
  38.  
  39.     $postData = rtrim($postData, '&');
  40.     curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);
  41.     echo "Performing Request...";
  42.  
  43.     $json_response = curl_exec($curl);
  44.  
  45.     $status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
  46.  
  47.     if ($status != 200) {
  48.       throw new Exception("Error: call to URL $endpoint failed with status $status, response $json_response, curl_error " . curl_error($curl) . ", curl_errno " . curl_errno($curl) . "\n");
  49.     }
  50.     curl_close($curl);
  51.  
  52.     return $json_response;
  53. }
  54. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement