'error', 'http_code' => 0, 'body' => '', 'json' => null, 'curl_error' => '', ); if (!function_exists('curl_init')) { $arrResult['curl_error'] = 'cURL indisponible'; return $arrResult; } $ch = curl_init(); $arrHeaders = isset($arrOptions['headers']) && is_array($arrOptions['headers']) ? $arrOptions['headers'] : array(); curl_setopt($ch, CURLOPT_URL, $strUrl); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 15); curl_setopt($ch, CURLOPT_TIMEOUT, 60); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, $arrHeaders); $strMethod = strtoupper(trim($strMethod)); if ($strMethod === 'GET') { curl_setopt($ch, CURLOPT_HTTPGET, true); } else { curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $strMethod); if (isset($arrOptions['body'])) { curl_setopt($ch, CURLOPT_POSTFIELDS, $arrOptions['body']); } } if (!empty($arrOptions['basic_user']) || !empty($arrOptions['basic_pass'])) { curl_setopt($ch, CURLOPT_USERPWD, $arrOptions['basic_user'] . ':' . $arrOptions['basic_pass']); } $strBody = curl_exec($ch); $arrResult['http_code'] = (int)curl_getinfo($ch, CURLINFO_HTTP_CODE); if ($strBody === false) { $arrResult['curl_error'] = curl_error($ch); } else { $arrResult['body'] = $strBody; $tabJson = json_decode($strBody, true); if (is_array($tabJson)) { $arrResult['json'] = $tabJson; } } curl_close($ch); if ($arrResult['curl_error'] !== '') { return $arrResult; } if ($arrResult['http_code'] >= 200 && $arrResult['http_code'] < 300) { $arrResult['state'] = 'ok'; } return $arrResult; } function fxChronotrackApiHttpGetJsonErrorMessage($arrHttp) { if (!empty($arrHttp['curl_error'])) { return $arrHttp['curl_error']; } if (is_array($arrHttp['json'])) { if (!empty($arrHttp['json']['errorMessage'])) { return (string)$arrHttp['json']['errorMessage']; } if (!empty($arrHttp['json']['errorCode'])) { return (string)$arrHttp['json']['errorCode']; } if (!empty($arrHttp['json']['error'][0]['errorMessage'])) { return (string)$arrHttp['json']['error'][0]['errorMessage']; } } return 'HTTP ' . intval($arrHttp['http_code']); }