139 lines
7.1 KiB
PHP
139 lines
7.1 KiB
PHP
<?php
|
|
/**
|
|
* 바로빌 API 설정 진단 페이지
|
|
* 현재 API 키 설정 상태를 확인합니다.
|
|
*/
|
|
header('Content-Type: application/json; charset=utf-8');
|
|
|
|
require_once('barobill_account_config.php');
|
|
|
|
// 전역 변수 접근
|
|
global $barobillCertKey, $barobillCorpNum, $barobillUserId, $isTestMode, $barobillAccountSoapUrl;
|
|
$documentRoot = getenv('DOCUMENT_ROOT');
|
|
|
|
$diagnostics = [
|
|
'cert_key' => [
|
|
'file_exists' => file_exists($documentRoot . '/apikey/barobill_cert_key.txt'),
|
|
'file_path' => $documentRoot . '/apikey/barobill_cert_key.txt',
|
|
'is_set' => !empty($barobillCertKey),
|
|
'length' => strlen($barobillCertKey),
|
|
'preview' => !empty($barobillCertKey) ? substr($barobillCertKey, 0, 8) . '...' . substr($barobillCertKey, -4) : 'NOT SET',
|
|
'raw_content' => file_exists($documentRoot . '/apikey/barobill_cert_key.txt')
|
|
? file_get_contents($documentRoot . '/apikey/barobill_cert_key.txt')
|
|
: 'FILE NOT FOUND',
|
|
'is_placeholder' => !empty($barobillCertKey) ? false : (
|
|
file_exists($documentRoot . '/apikey/barobill_cert_key.txt')
|
|
? (strpos(file_get_contents($documentRoot . '/apikey/barobill_cert_key.txt'), '[여기에') !== false
|
|
|| strpos(file_get_contents($documentRoot . '/apikey/barobill_cert_key.txt'), '바로빌 CERTKEY') !== false
|
|
|| strpos(file_get_contents($documentRoot . '/apikey/barobill_cert_key.txt'), '================================') !== false)
|
|
: false
|
|
)
|
|
],
|
|
'corp_num' => [
|
|
'file_exists' => file_exists($documentRoot . '/apikey/barobill_corp_num.txt'),
|
|
'file_path' => $documentRoot . '/apikey/barobill_corp_num.txt',
|
|
'is_set' => !empty($barobillCorpNum),
|
|
'value' => $barobillCorpNum,
|
|
'raw_content' => file_exists($documentRoot . '/apikey/barobill_corp_num.txt')
|
|
? file_get_contents($documentRoot . '/apikey/barobill_corp_num.txt')
|
|
: 'FILE NOT FOUND'
|
|
],
|
|
'user_id' => [
|
|
'file_exists' => file_exists($documentRoot . '/apikey/barobill_user_id.txt'),
|
|
'file_path' => $documentRoot . '/apikey/barobill_user_id.txt',
|
|
'is_set' => !empty($barobillUserId),
|
|
'value' => $barobillUserId,
|
|
'raw_content' => file_exists($documentRoot . '/apikey/barobill_user_id.txt')
|
|
? file_get_contents($documentRoot . '/apikey/barobill_user_id.txt')
|
|
: 'FILE NOT FOUND'
|
|
],
|
|
'test_mode' => [
|
|
'file_exists' => file_exists($documentRoot . '/apikey/barobill_test_mode.txt'),
|
|
'is_active' => $isTestMode,
|
|
'raw_content' => file_exists($documentRoot . '/apikey/barobill_test_mode.txt')
|
|
? file_get_contents($documentRoot . '/apikey/barobill_test_mode.txt')
|
|
: 'FILE NOT FOUND'
|
|
],
|
|
'soap_client' => [
|
|
'url' => $barobillAccountSoapUrl,
|
|
'initialized' => isset($barobillAccountSoapClient) && $barobillAccountSoapClient !== null
|
|
],
|
|
'hardcoded_values' => [
|
|
'note' => '⚠️ barobill_account_config.php에 하드코딩된 값이 있을 수 있습니다.',
|
|
'check_file' => 'eaccount/api/barobill_account_config.php (62-68줄)'
|
|
]
|
|
];
|
|
|
|
// 실제 API 호출 테스트
|
|
// 테스트 모드일 때는 CERTKEY가 없어도 테스트 가능
|
|
$testResult = null;
|
|
$canTest = false;
|
|
if ($isTestMode) {
|
|
// 테스트 모드: CERTKEY 불필요, 사업자번호만 확인
|
|
$canTest = !empty($barobillCorpNum);
|
|
} else {
|
|
// 운영 모드: CERTKEY와 사업자번호 모두 필요
|
|
$canTest = !empty($barobillCertKey) && !empty($barobillCorpNum);
|
|
}
|
|
|
|
if ($canTest) {
|
|
try {
|
|
$testResult = callBarobillAccountSOAP('GetBankAccountEx', [
|
|
'AvailOnly' => 0
|
|
]);
|
|
|
|
$diagnostics['api_test'] = [
|
|
'success' => $testResult['success'],
|
|
'error' => $testResult['error'] ?? null,
|
|
'error_code' => $testResult['error_code'] ?? null,
|
|
'has_data' => isset($testResult['data']),
|
|
'debug_available' => isset($testResult['debug'])
|
|
];
|
|
|
|
if (isset($testResult['debug'])) {
|
|
$diagnostics['api_test']['request_preview'] = $testResult['debug']['request'] ?? null;
|
|
}
|
|
} catch (Exception $e) {
|
|
$diagnostics['api_test'] = [
|
|
'success' => false,
|
|
'error' => 'Exception: ' . $e->getMessage()
|
|
];
|
|
}
|
|
} else {
|
|
if ($isTestMode) {
|
|
$diagnostics['api_test'] = [
|
|
'skipped' => true,
|
|
'reason' => '테스트 모드: 사업자번호가 설정되지 않았습니다. (CERTKEY는 불필요)'
|
|
];
|
|
} else {
|
|
$diagnostics['api_test'] = [
|
|
'skipped' => true,
|
|
'reason' => '운영 모드: CERTKEY 또는 사업자번호가 설정되지 않았습니다.'
|
|
];
|
|
}
|
|
}
|
|
|
|
echo json_encode([
|
|
'success' => true,
|
|
'diagnostics' => $diagnostics,
|
|
'recommendations' => array_filter([
|
|
!$isTestMode && !$diagnostics['cert_key']['is_set'] ? 'CERTKEY를 설정하세요: apikey/barobill_cert_key.txt 파일에 바로빌 CERTKEY를 입력하세요.' : null,
|
|
!$isTestMode && isset($diagnostics['cert_key']['is_placeholder']) && $diagnostics['cert_key']['is_placeholder'] ? '⚠️ CERTKEY 파일에 설명 텍스트만 있습니다. 파일의 모든 설명을 삭제하고 실제 CERTKEY 값만 입력하세요. (예: "2DD6C76C-1234-5678-ABCD-EF1234561826")' : null,
|
|
!$diagnostics['corp_num']['is_set'] ? '사업자번호를 설정하세요: apikey/barobill_corp_num.txt 파일에 사업자번호를 입력하세요.' : null,
|
|
!$isTestMode && $diagnostics['cert_key']['file_exists'] && empty(trim($diagnostics['cert_key']['raw_content'])) ? 'CERTKEY 파일이 비어있습니다. 바로빌 사이트에서 CERTKEY를 확인하고 입력하세요.' : null,
|
|
!$isTestMode && strpos($diagnostics['cert_key']['raw_content'], '[여기에') !== false ? 'CERTKEY 파일에 설명 텍스트가 남아있습니다. 실제 CERTKEY 값만 입력하세요.' : null,
|
|
isset($diagnostics['api_test']['error_code']) && $diagnostics['api_test']['error_code'] == -24005 ? '사업자번호가 잘못되었습니다. 바로빌 사이트에 로그인하여 등록된 사업자번호를 확인하세요.' : null,
|
|
isset($diagnostics['api_test']['error_code']) && $diagnostics['api_test']['error_code'] == -25001 ? '등록된 계좌가 없습니다. 바로빌 사이트에서 계좌를 먼저 등록하세요.' : null,
|
|
$isTestMode ? '현재 테스트 모드입니다. CERTKEY는 필요하지 않습니다.' : null,
|
|
]),
|
|
'next_steps' => [
|
|
'1. 바로빌 사이트(https://www.barobill.co.kr)에 로그인',
|
|
'2. 마이페이지 > API 설정에서 CERTKEY 확인',
|
|
'3. apikey/barobill_cert_key.txt 파일에 CERTKEY 입력 (설명 텍스트 제외)',
|
|
'4. apikey/barobill_corp_num.txt 파일에 사업자번호 입력 (하이픈 제외 가능)',
|
|
'5. (주)코드브릿지 산하 기업인 경우, barobill_account_config.php의 하드코딩된 값 확인 필요'
|
|
]
|
|
], JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
|
|
?>
|
|
|