本文整理汇总了PHP中Credentials::getServer方法的典型用法代码示例。如果您正苦于以下问题:PHP Credentials::getServer方法的具体用法?PHP Credentials::getServer怎么用?PHP Credentials::getServer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Credentials
的用法示例。
在下文中一共展示了Credentials::getServer方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: request
/**
* @param $method
* @param array $post
* @param null $successCallback
* @param null $errorCallback
*/
private function request($method, array $post, $successCallback, $errorCallback)
{
$url = "https://" . $this->credentials->getServer() . "/apiv1";
$postData = "JSON-RPC=" . urlencode(json_encode(["method" => $method, "params" => $post]));
$headers = ["Connection: keep-alive", "Content-Type: application/x-www-form-urlencoded", "Charset=UTF-8", "Cache-Control: no-cache", "Pragma: no-cache"];
$defaults = array(CURLOPT_URL => $url, CURLOPT_POST => true, CURLOPT_POSTFIELDS => $postData, CURLOPT_HTTPHEADER => $headers, CURLOPT_RETURNTRANSFER => true, CURLOPT_HEADER => true, CURLOPT_TIMEOUT => 30, CURLOPT_ENCODING => "gzip", CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => false, CURLOPT_SSLVERSION => 6);
$ch = curl_init();
curl_setopt_array($ch, $defaults);
$response = curl_exec($ch);
$error = curl_error($ch);
if ($error != "") {
trigger_error(curl_error($ch));
}
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
//$headerReturn = substr($response, 0, $header_size);
$body = substr($response, $header_size);
curl_close($ch);
$result = json_decode($body, true);
// If callbacks are specified - then call them. Otherwise, just return the results or throw an error
if ($this->array_check("result", $result)) {
if (is_callable($successCallback)) {
$successCallback($result["result"]);
} else {
return $result["result"];
}
} else {
if (count($result) == 0) {
if (is_callable($successCallback)) {
$successCallback($result);
} else {
return $result;
}
} else {
if (is_callable($errorCallback)) {
$errorCallback($result["error"]["errors"][0]);
} else {
throw new MyGeotabException($result["error"]["errors"][0]);
}
}
}
}