68 lines
2.2 KiB
PHP
68 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Libraries;
|
|
|
|
class NaverApiClient
|
|
{
|
|
protected $baseUrl = 'https://test-b2b.land.naver.com';
|
|
protected $charger = 'admin';
|
|
|
|
/**
|
|
* [GET] 매물 정보 조회
|
|
*/
|
|
public function getArticleInfo(string $articleNumber): ?array
|
|
{
|
|
$url = "{$this->baseUrl}/kiso/center/verification-article/{$articleNumber}?charger={$this->charger}";
|
|
|
|
return $this->request('GET', $url);
|
|
}
|
|
|
|
/**
|
|
* [PUT] 매물 정보 수정
|
|
* @param string $articleNumber 매물번호
|
|
* @param array $updateData 수정할 데이터 (tradeType, price, space 등)
|
|
*/
|
|
public function updateArticleInfo(string $articleNumber, array $updateData): ?array
|
|
{
|
|
$url = "{$this->baseUrl}/kiso/center/verification-article/{$articleNumber}?charger={$this->charger}";
|
|
|
|
return $this->request('PUT', $url, $updateData);
|
|
}
|
|
|
|
/**
|
|
* CURL 공통 실행 함수
|
|
*/
|
|
private function request(string $method, string $url, array $data = null): ?array
|
|
{
|
|
$ch = curl_init();
|
|
curl_setopt($ch, CURLOPT_URL, $url);
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
|
|
|
|
if ($method === 'PUT') {
|
|
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
|
|
if ($data) {
|
|
$payload = json_encode($data);
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
|
'Content-Type: application/json',
|
|
'Content-Length: ' . strlen($payload)
|
|
]);
|
|
}
|
|
}
|
|
|
|
$response = curl_exec($ch);
|
|
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
|
curl_close($ch);
|
|
|
|
// 결과 로그 기록 (성공/실패 모두 기록하여 추적 가능하게 함)
|
|
if ($httpCode === 200) {
|
|
log_message('info', "[Naver API $method SUCCESS] URL: $url | Response: $response");
|
|
} else {
|
|
log_message('error', "[Naver API $method FAIL] URL: $url | Code: $httpCode | Response: $response");
|
|
return null;
|
|
}
|
|
|
|
return json_decode($response, true);
|
|
}
|
|
} |