Skip to content

Instantly share code, notes, and snippets.

@noone0
Created February 5, 2017 11:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save noone0/b539a0303fb3255c0c9e7dac6039e7c3 to your computer and use it in GitHub Desktop.
Save noone0/b539a0303fb3255c0c9e7dac6039e7c3 to your computer and use it in GitHub Desktop.
function callApi($method, $function, $data = false)
{
$curl = curl_init();
$url = $this->parentUrl.$function;
switch ($method)
{
case "POST":
curl_setopt($curl, CURLOPT_POST, 1);
if ($data)
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
break;
case "PUT":
curl_setopt($curl, CURLOPT_PUT, 1);
break;
default:
if ($data)
$url = sprintf("%s?%s", $url, http_build_query($data));
}
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$headers = [
'APIKey: '.$this->apiKey,
'MerchantId: '.$this->merchantId,
'StationId: '.$this->stationId,
'Content-Type: application/json'
];
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($curl);
curl_close($curl);
return $result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment