API Keys and Access Tokens - PHP, problem z połączeniem |
API Keys and Access Tokens - PHP, problem z połączeniem |
10.01.2023, 10:31:00
Post
#1
|
|
Grupa: Zarejestrowani Postów: 1 Pomógł: 0 Dołączył: 10.01.2023 Ostrzeżenie: (0%) |
Dzień dobry,
Mam problem z połączeniem się z zewnętrznym API za pomocą skryptu PHP. Niestety zestawienie połączenia za pomocą tego skryptu nie działa. Problem jest podstawienie zmiennej typu string w miejsce klucza token i daty by za pomocą ich pobrać dane. Poniżej kod jaki napisałem brakuje mi tylko funkcji lub poprawnej deklaracji zmiennych by wstawić klucz i czas, są one zadeklarowane jako $curl1 i $curl2. <?php $secret = '52'; $key = 'jcr'; function createHmacAuth($method, $path, $timestamp) { global $key, $secret; $str = $method . ' ' . $path . $timestamp; $hash = hash_hmac('sha256', $str, $secret); return $key . ':' . $hash; } function getRequest($path) { $t = microtime(true); $micro = sprintf("%03d", ($t - floor($t)) * 1000); $time = gmdate('Y-m-d\TH:i:s.', $t) . $micro . 'Z'; $auth = createHmacAuth('POST', $path, $time); echo $auth . "</pre>"; echo $time . "</pre>"; return $auth; return $time; } $response = getRequest(''); $curl = curl_init(); $curl1 = curl_init($auth); $curl2 = curl_init($time); curl_setopt_array($curl, array( CURLOPT_URL => 'https://...', CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_POSTFIELDS => '{ "machineSns": [ "IL3" ], "dateFrom": "2022-03-30T08:47:32.591", "dateTo": "2022-09-24T05:47:32.591", "startRow": 0, "endRow": 10, "selectedKpiTab": "", "searchString": "DG15460" }', CURLOPT_HTTPHEADER => array( 'Content-Type: application/json', 'x-hp-hmac-authentication:' . $curl1 , 'x-hp-hmac-date:' . $curl2 , 'x-hp-hmac-algorithm: SHA256 ' ), )); $response = curl_exec($curl); curl_close($curl); echo $response; Dziękuję za pomoc. |
|
|
Wersja Lo-Fi | Aktualny czas: 26.09.2024 - 18:05 |