PHP 8 · cURL 확장이 필요합니다. 키는 서버 환경변수로 읽습니다.
<?php
$headers = ["Authorization: Bearer " . getenv("APICK_API_KEY")];
$form = [
'account_num' => getenv('APICK_ACCOUNT_NUM'),
];
$curl = curl_init('https://apick.app/rest/transfer_1won');
curl_setopt_array($curl, [
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_HTTPHEADER => $headers,
CURLOPT_POSTFIELDS => $form,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CONNECTTIMEOUT => 10, CURLOPT_TIMEOUT => 120,
]);
$body = curl_exec($curl);
if ($body === false) { throw new RuntimeException(curl_error($curl)); }
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);
if ($status >= 400) { throw new RuntimeException($body); }
$result = json_decode($body, true, 512, JSON_THROW_ON_ERROR);
print_r($result);