최초 커밋
This commit is contained in:
@@ -0,0 +1,298 @@
|
||||
<?php
|
||||
// resign_and_update.php
|
||||
// header('Content-Type: application/json');
|
||||
|
||||
// // 1. Authorization 헤더 검사
|
||||
// $authHeader = '';
|
||||
// if (function_exists('getallheaders')) {
|
||||
// $hdrs = getallheaders();
|
||||
// if (!empty($hdrs['authorization'])) {
|
||||
// $authHeader = $hdrs['authorization'];
|
||||
// } elseif (!empty($hdrs['Authorization'])) {
|
||||
// $authHeader = $hdrs['Authorization'];
|
||||
// }
|
||||
// } elseif (!empty($_SERVER['HTTP_AUTHORIZATION'])) {
|
||||
// $authHeader = $_SERVER['HTTP_AUTHORIZATION'];
|
||||
// }
|
||||
|
||||
// $expectedKey = 'abcd1234efgh5678';
|
||||
// if ($authHeader !== $expectedKey) {
|
||||
// echo json_encode([
|
||||
// 'status' => 'error',
|
||||
// 'step' => 'auth',
|
||||
// 'message' => '인증에 실패했습니다. 올바른 인증키를 사용했는지 확인해 주세요.'
|
||||
// ], JSON_UNESCAPED_UNICODE);
|
||||
// exit;
|
||||
// }
|
||||
|
||||
// // 2. POST된 JSON 데이터 수신
|
||||
// $input = file_get_contents('php://input');
|
||||
// $data = json_decode($input, true);
|
||||
// if (!is_array($data)) {
|
||||
// echo json_encode([
|
||||
// 'status' => 'error',
|
||||
// 'step' => 'parse',
|
||||
// 'message' => '전달된 JSON이 올바르지 않습니다.'
|
||||
// ], JSON_UNESCAPED_UNICODE);
|
||||
// exit;
|
||||
// }
|
||||
|
||||
// // 3. 필수 파라미터 확인
|
||||
// $required = ['emp_no','name','email','type','date'];
|
||||
// foreach ($required as $key) {
|
||||
// if (empty($data[$key])) {
|
||||
// $friendly = [
|
||||
// 'emp_no' => '사번',
|
||||
// 'name' => '이름',
|
||||
// 'email' => '이메일',
|
||||
// 'type' => '퇴사 유형',
|
||||
// 'date' => '퇴사 일자'
|
||||
// ][$key] ?? $key;
|
||||
// echo json_encode([
|
||||
// 'status' => 'error',
|
||||
// 'step' => 'validation',
|
||||
// 'message' => "필수 항목이 누락되었습니다: {$friendly} 누락."
|
||||
// ], JSON_UNESCAPED_UNICODE);
|
||||
// exit;
|
||||
// }
|
||||
// }
|
||||
|
||||
// // 4. DB 연결 및 INSERT
|
||||
// $db = new mysqli('localhost','egbim','baron3840!!','egbim');
|
||||
// if ($db->connect_error) {
|
||||
// echo json_encode([
|
||||
// 'status' => 'error',
|
||||
// 'step' => 'db_connect',
|
||||
// 'message' => '데이터베이스 연결에 실패했습니다.'
|
||||
// ], JSON_UNESCAPED_UNICODE);
|
||||
// exit;
|
||||
// }
|
||||
// $stmt = $db->prepare("
|
||||
// INSERT INTO resign_info (emp_no,name,email,type,date)
|
||||
// VALUES (?,?,?,?,?)
|
||||
// ");
|
||||
// $stmt->bind_param('sssss',
|
||||
// $data['emp_no'],
|
||||
// $data['name'],
|
||||
// $data['email'],
|
||||
// $data['type'],
|
||||
// $data['date']
|
||||
// );
|
||||
|
||||
// if (! $stmt->execute()) {
|
||||
// // 중복 키(Primary Key/email) 에러
|
||||
// if ($stmt->errno === 1062) {
|
||||
// echo json_encode([
|
||||
// 'status' => 'error',
|
||||
// 'step' => 'db_insert',
|
||||
// 'message' => '이미 동일한 이메일의 퇴사자 정보가 등록되어 있습니다.'
|
||||
// ], JSON_UNESCAPED_UNICODE);
|
||||
// } else {
|
||||
// echo json_encode([
|
||||
// 'status' => 'error',
|
||||
// 'step' => 'db_insert',
|
||||
// 'message' => '퇴사자 정보를 저장하는 데 실패했습니다: ' . $stmt->error
|
||||
// ], JSON_UNESCAPED_UNICODE);
|
||||
// }
|
||||
// $stmt->close();
|
||||
// $db->close();
|
||||
// exit;
|
||||
// }
|
||||
|
||||
// $stmt->close();
|
||||
// $db->close();
|
||||
|
||||
// // 초기 응답 객체
|
||||
// $result = [
|
||||
// 'status' => 'success',
|
||||
// 'db' => 'ok',
|
||||
// 'descope' => null,
|
||||
// 'emp_status' => null,
|
||||
// 'message' => '퇴사자 정보가 DB에 정상적으로 등록되었습니다.'
|
||||
// ];
|
||||
|
||||
// // DB 실패 시 바로 리턴
|
||||
// if (! $dbResult) {
|
||||
// $result['status'] = 'error';
|
||||
// echo json_encode($result, JSON_UNESCAPED_UNICODE);
|
||||
// exit;
|
||||
// }
|
||||
|
||||
// // 이메일이 비어 있으면 나머지 호출 생략
|
||||
// if (empty($data['email'])) {
|
||||
// $result['status'] = 'partial_success';
|
||||
// $result['message'] = '(이메일 정보가 없어 Descope 삭제 및 사내 상태 업데이트는 생략되었습니다.)';
|
||||
// echo json_encode($result, JSON_UNESCAPED_UNICODE);
|
||||
// exit;
|
||||
// }
|
||||
|
||||
// // 5. Descope 사용자 삭제
|
||||
// $projectId = 'P2wON5fy1K6kyia269VpeIzYP8oP';
|
||||
// $managementKey = 'K2ycqpjeh1voPBdxXxzB3ScZOQ6v9aiLmU2cIj70X1H8Kcoz0KWfCWmofUwAsAkJroXA8QC';
|
||||
|
||||
// $ch1 = curl_init('https://api.descope.com/v1/mgmt/user/delete');
|
||||
// curl_setopt_array($ch1, [
|
||||
// CURLOPT_RETURNTRANSFER => true,
|
||||
// CURLOPT_POST => true,
|
||||
// CURLOPT_POSTFIELDS => json_encode(['loginId'=>$data['email']]),
|
||||
// CURLOPT_HTTPHEADER => [
|
||||
// 'Content-Type: application/json',
|
||||
// "Authorization: Bearer {$projectId}:{$managementKey}"
|
||||
// ],
|
||||
// ]);
|
||||
// $res1 = curl_exec($ch1);
|
||||
// $code1 = curl_getinfo($ch1, CURLINFO_HTTP_CODE);
|
||||
// $err1 = curl_error($ch1);
|
||||
// curl_close($ch1);
|
||||
|
||||
|
||||
// if ($err1) {
|
||||
// $result['descope'] = [
|
||||
// 'status' => 'error',
|
||||
// 'message' => 'Descope 사용자 삭제 중 오류가 발생했습니다: ' . $err1
|
||||
// ];
|
||||
// } elseif ($code1 >= 200 && $code1 < 300) {
|
||||
// $result['descope'] = ['status'=>'ok','message'=>'Descope 사용자 삭제에 성공했습니다.'];
|
||||
// } else {
|
||||
// $result['descope'] = [
|
||||
// 'status' => 'error',
|
||||
// 'message' => "Descope API 에러 (HTTP {$code1})",
|
||||
// 'response' => json_decode($res1, true)
|
||||
// ];
|
||||
// }
|
||||
|
||||
// 6. 사내 emp_status 업데이트
|
||||
// $ch2 = curl_init('http://172.16.10.191:20000/user/emp_status');
|
||||
// curl_setopt_array($ch2, [
|
||||
// CURLOPT_RETURNTRANSFER => true,
|
||||
// CURLOPT_POST => true,
|
||||
// CURLOPT_POSTFIELDS => json_encode([
|
||||
// 'email' => $data['email'],
|
||||
// 'status' => 'inactive'
|
||||
// ]),
|
||||
// CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
|
||||
// ]);
|
||||
// $res2 = curl_exec($ch2);
|
||||
// $code2 = curl_getinfo($ch2, CURLINFO_HTTP_CODE);
|
||||
// $err2 = curl_error($ch2);
|
||||
// curl_close($ch2);
|
||||
|
||||
// if ($err2) {
|
||||
// $result['emp_status'] = [
|
||||
// 'status' => 'error',
|
||||
// 'message' => 'BEPs에 전송 오류가 발생했습니다: ' . $err2
|
||||
// ];
|
||||
// } elseif ($code2 >= 200 && $code2 < 300) {
|
||||
// $result['emp_status'] = ['status'=>'ok','message'=>'BEPs에 전송 성공했습니다.'];
|
||||
// } else {
|
||||
// $result['emp_status'] = [
|
||||
// 'status' => 'error',
|
||||
// 'message' => "BEPS API 에러 (HTTP {$code2})",
|
||||
// 'response' => json_decode($res2, true)
|
||||
// ];
|
||||
// }
|
||||
// echo json_encode($result, JSON_UNESCAPED_UNICODE);
|
||||
// exit;
|
||||
// 6. 사내 emp_status 업데이트 (테스트용)
|
||||
?>
|
||||
<?php
|
||||
// 사내 emp_status 업데이트 (테스트용)
|
||||
$ch2 = curl_init('http://1.234.37.173:13000/user/emp_status');
|
||||
curl_setopt_array($ch2, [
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_POST => true,
|
||||
CURLOPT_HTTPHEADER => [
|
||||
'Content-Type: application/json'
|
||||
],
|
||||
CURLOPT_POSTFIELDS => json_encode([
|
||||
'email' => 'b24014@hanmaceng.co.kr', // 테스트용 하드코딩
|
||||
'status' => 'inactive' // 'active' 또는 'inactive'
|
||||
], JSON_UNESCAPED_UNICODE)
|
||||
]);
|
||||
|
||||
$res2 = curl_exec($ch2);
|
||||
$code2 = curl_getinfo($ch2, CURLINFO_HTTP_CODE);
|
||||
$err2 = curl_error($ch2);
|
||||
curl_close($ch2);
|
||||
|
||||
// 결과 처리
|
||||
if ($err2) {
|
||||
$result = [
|
||||
'status' => 'error',
|
||||
'message' => 'BEPs에 전송 오류: ' . $err2
|
||||
];
|
||||
} elseif ($code2 >= 200 && $code2 < 300) {
|
||||
$result = [
|
||||
'status' => 'ok',
|
||||
'message' => 'BEPs에 전송 성공',
|
||||
'response'=> json_decode($res2, true)
|
||||
];
|
||||
} else {
|
||||
$result = [
|
||||
'status' => 'error',
|
||||
'message' => "BEPs API 에러 (HTTP {$code2})",
|
||||
'response' => json_decode($res2, true)
|
||||
];
|
||||
}
|
||||
|
||||
echo json_encode($result, JSON_UNESCAPED_UNICODE);
|
||||
?>
|
||||
|
||||
<?php
|
||||
// 사내 emp_status 업데이트 (테스트 & 디버그용)
|
||||
// $url = 'http://1.234.37.173:13000/user/emp_status';
|
||||
// $email = 'b24014@hanmaceng.co.kr';
|
||||
// $status = 'inactive';
|
||||
|
||||
// // 요청 데이터
|
||||
// $payload = json_encode([
|
||||
// 'email' => $email,
|
||||
// 'status' => $status
|
||||
// ], JSON_UNESCAPED_UNICODE);
|
||||
|
||||
// // cURL 초기화
|
||||
// $ch = curl_init($url);
|
||||
// curl_setopt_array($ch, [
|
||||
// CURLOPT_RETURNTRANSFER => true,
|
||||
// CURLOPT_POST => true,
|
||||
// CURLOPT_HTTPHEADER => [
|
||||
// 'Content-Type: application/json'
|
||||
// ],
|
||||
// CURLOPT_POSTFIELDS => $payload,
|
||||
// CURLOPT_HEADER => true, // 헤더+바디 함께 받기
|
||||
// CURLINFO_HEADER_OUT => true, // 요청 헤더 디버그용
|
||||
// ]);
|
||||
|
||||
// $response = curl_exec($ch);
|
||||
// $err = curl_error($ch);
|
||||
// $info = curl_getinfo($ch);
|
||||
// curl_close($ch);
|
||||
|
||||
// if ($err) {
|
||||
// echo "=== cURL ERROR ===\n$err\n";
|
||||
// exit;
|
||||
// }
|
||||
|
||||
// // 응답 분리 (헤더 / 바디)
|
||||
// $headerSize = $info['header_size'];
|
||||
// $respHeader = substr($response, 0, $headerSize);
|
||||
// $respBody = substr($response, $headerSize);
|
||||
|
||||
// // 디버그 출력
|
||||
// echo "=== 요청 URL ===\n{$url}\n\n";
|
||||
// echo "=== 요청 메서드 ===\nPOST\n\n";
|
||||
// echo "=== 요청 헤더 ===\n" . implode("\n", $info['request_header'] ?? []) . "\n\n";
|
||||
// echo "=== 요청 바디 ===\n$payload\n\n";
|
||||
// echo "=== 응답 코드 ===\n{$info['http_code']}\n\n";
|
||||
// echo "=== 응답 헤더 ===\n$respHeader\n\n";
|
||||
// echo "=== 응답 바디 ===\n$respBody\n\n";
|
||||
|
||||
// // JSON 파싱 가능하면 보기 좋게 출력
|
||||
// $json = json_decode($respBody, true);
|
||||
// if ($json !== null) {
|
||||
// echo "=== 응답 JSON 파싱 ===\n";
|
||||
// print_r($json);
|
||||
// }
|
||||
|
||||
?>
|
||||
|
||||
@@ -0,0 +1,195 @@
|
||||
<?php
|
||||
// resign_and_update.php
|
||||
header('Content-Type: application/json');
|
||||
|
||||
// 1. Authorization 헤더 검사
|
||||
$authHeader = '';
|
||||
if (function_exists('getallheaders')) {
|
||||
$hdrs = getallheaders();
|
||||
if (!empty($hdrs['authorization'])) {
|
||||
$authHeader = $hdrs['authorization'];
|
||||
} elseif (!empty($hdrs['Authorization'])) {
|
||||
$authHeader = $hdrs['Authorization'];
|
||||
}
|
||||
} elseif (!empty($_SERVER['HTTP_AUTHORIZATION'])) {
|
||||
$authHeader = $_SERVER['HTTP_AUTHORIZATION'];
|
||||
}
|
||||
|
||||
$expectedKey = 'abcd1234efgh5678';
|
||||
if ($authHeader !== $expectedKey) {
|
||||
echo json_encode([
|
||||
'status' => 'error',
|
||||
'step' => 'auth',
|
||||
'message' => '인증에 실패했습니다. 올바른 인증키를 사용했는지 확인해 주세요.'
|
||||
], JSON_UNESCAPED_UNICODE);
|
||||
exit;
|
||||
}
|
||||
|
||||
// 2. POST된 JSON 데이터 수신
|
||||
$input = file_get_contents('php://input');
|
||||
$data = json_decode($input, true);
|
||||
if (!is_array($data)) {
|
||||
echo json_encode([
|
||||
'status' => 'error',
|
||||
'step' => 'parse',
|
||||
'message' => '전달된 JSON이 올바르지 않습니다.'
|
||||
], JSON_UNESCAPED_UNICODE);
|
||||
exit;
|
||||
}
|
||||
|
||||
// 3. 필수 파라미터 확인
|
||||
$required = ['emp_no','name','email','type','date'];
|
||||
foreach ($required as $key) {
|
||||
if (empty($data[$key])) {
|
||||
$friendly = [
|
||||
'emp_no' => '사번',
|
||||
'name' => '이름',
|
||||
'email' => '이메일',
|
||||
'type' => '퇴사 유형',
|
||||
'date' => '퇴사 일자'
|
||||
][$key] ?? $key;
|
||||
echo json_encode([
|
||||
'status' => 'error',
|
||||
'step' => 'validation',
|
||||
'message' => "필수 항목이 누락되었습니다: {$friendly} 누락."
|
||||
], JSON_UNESCAPED_UNICODE);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
// 4. DB 연결 및 INSERT
|
||||
$db = new mysqli('localhost','egbim','baron3840!!','egbim');
|
||||
if ($db->connect_error) {
|
||||
echo json_encode([
|
||||
'status' => 'error',
|
||||
'step' => 'db_connect',
|
||||
'message' => '데이터베이스 연결에 실패했습니다.'
|
||||
], JSON_UNESCAPED_UNICODE);
|
||||
exit;
|
||||
}
|
||||
$stmt = $db->prepare("
|
||||
INSERT INTO resign_info (emp_no,name,email,type,date)
|
||||
VALUES (?,?,?,?,?)
|
||||
");
|
||||
$stmt->bind_param('sssss',
|
||||
$data['emp_no'],
|
||||
$data['name'],
|
||||
$data['email'],
|
||||
$data['type'],
|
||||
$data['date']
|
||||
);
|
||||
|
||||
if (! $stmt->execute()) {
|
||||
// 중복 키(Primary Key/email) 에러
|
||||
if ($stmt->errno === 1062) {
|
||||
echo json_encode([
|
||||
'status' => 'error',
|
||||
'step' => 'db_insert',
|
||||
'message' => '이미 동일한 이메일의 퇴사자 정보가 등록되어 있습니다.'
|
||||
], JSON_UNESCAPED_UNICODE);
|
||||
} else {
|
||||
echo json_encode([
|
||||
'status' => 'error',
|
||||
'step' => 'db_insert',
|
||||
'message' => '퇴사자 정보를 저장하는 데 실패했습니다: ' . $stmt->error
|
||||
], JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
$stmt->close();
|
||||
$db->close();
|
||||
exit;
|
||||
}
|
||||
|
||||
$stmt->close();
|
||||
$db->close();
|
||||
|
||||
// 초기 응답 객체
|
||||
$result = [
|
||||
'status' => 'success',
|
||||
'db' => 'ok',
|
||||
'descope' => null,
|
||||
'emp_status' => null,
|
||||
'message' => '퇴사자 정보가 DB에 정상적으로 등록되었습니다.'
|
||||
];
|
||||
|
||||
// DB 실패 시 바로 리턴
|
||||
if (! $dbResult) {
|
||||
$result['status'] = 'error';
|
||||
echo json_encode($result, JSON_UNESCAPED_UNICODE);
|
||||
exit;
|
||||
}
|
||||
|
||||
// 이메일이 비어 있으면 나머지 호출 생략
|
||||
if (empty($data['email'])) {
|
||||
$result['status'] = 'partial_success';
|
||||
$result['message'] = '(이메일 정보가 없어 Descope 삭제 및 사내 상태 업데이트는 생략되었습니다.)';
|
||||
echo json_encode($result, JSON_UNESCAPED_UNICODE);
|
||||
exit;
|
||||
}
|
||||
|
||||
// 5. Descope 사용자 삭제
|
||||
$projectId = 'P2wON5fy1K6kyia269VpeIzYP8oP';
|
||||
$managementKey = 'K2ycqpjeh1voPBdxXxzB3ScZOQ6v9aiLmU2cIj70X1H8Kcoz0KWfCWmofUwAsAkJroXA8QC';
|
||||
|
||||
$ch1 = curl_init('https://api.descope.com/v1/mgmt/user/delete');
|
||||
curl_setopt_array($ch1, [
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_POST => true,
|
||||
CURLOPT_POSTFIELDS => json_encode(['loginId'=>$data['email']]),
|
||||
CURLOPT_HTTPHEADER => [
|
||||
'Content-Type: application/json',
|
||||
"Authorization: Bearer {$projectId}:{$managementKey}"
|
||||
],
|
||||
]);
|
||||
$res1 = curl_exec($ch1);
|
||||
$code1 = curl_getinfo($ch1, CURLINFO_HTTP_CODE);
|
||||
$err1 = curl_error($ch1);
|
||||
curl_close($ch1);
|
||||
|
||||
|
||||
if ($err1) {
|
||||
$result['descope'] = [
|
||||
'status' => 'error',
|
||||
'message' => 'Descope 사용자 삭제 중 오류가 발생했습니다: ' . $err1
|
||||
];
|
||||
} elseif ($code1 >= 200 && $code1 < 300) {
|
||||
$result['descope'] = ['status'=>'ok','message'=>'Descope 사용자 삭제에 성공했습니다.'];
|
||||
} else {
|
||||
$result['descope'] = [
|
||||
'status' => 'error',
|
||||
'message' => "Descope API 에러 (HTTP {$code1})",
|
||||
'response' => json_decode($res1, true)
|
||||
];
|
||||
}
|
||||
|
||||
// 6. 사내 emp_status 업데이트
|
||||
$ch2 = curl_init('http://172.16.10.191:20000/user/emp_status');
|
||||
curl_setopt_array($ch2, [
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_POST => true,
|
||||
CURLOPT_POSTFIELDS => json_encode([
|
||||
'email' => $data['email'],
|
||||
'status' => 'inactive'
|
||||
]),
|
||||
CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
|
||||
]);
|
||||
$res2 = curl_exec($ch2);
|
||||
$code2 = curl_getinfo($ch2, CURLINFO_HTTP_CODE);
|
||||
$err2 = curl_error($ch2);
|
||||
curl_close($ch2);
|
||||
|
||||
if ($err2) {
|
||||
$result['emp_status'] = [
|
||||
'status' => 'error',
|
||||
'message' => 'BEPs에 전송 오류가 발생했습니다: ' . $err2
|
||||
];
|
||||
} elseif ($code2 >= 200 && $code2 < 300) {
|
||||
$result['emp_status'] = ['status'=>'ok','message'=>'BEPs에 전송 성공했습니다.'];
|
||||
} else {
|
||||
$result['emp_status'] = [
|
||||
'status' => 'error',
|
||||
'message' => "BEPS API 에러 (HTTP {$code2})",
|
||||
'response' => json_decode($res2, true)
|
||||
];
|
||||
}
|
||||
echo json_encode($result, JSON_UNESCAPED_UNICODE);
|
||||
exit;
|
||||
@@ -0,0 +1,284 @@
|
||||
<?php
|
||||
/**
|
||||
* resign_and_update.php (운영용 정리본)
|
||||
* - Authorization 헤더 + JSON 입력 필수
|
||||
* - DB INSERT (1062 중복 캐치)
|
||||
* - Descope 사용자 삭제 → (성공시에만) BEPS 상태 업데이트
|
||||
* - 모든 응답은 JSON 1회 출력
|
||||
*/
|
||||
|
||||
header('Content-Type: application/json');
|
||||
|
||||
// ===== 에러 표시 & mysqli 예외 모드 =====
|
||||
ini_set('display_errors', '1');
|
||||
ini_set('display_startup_errors', '1');
|
||||
error_reporting(E_ALL);
|
||||
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
|
||||
|
||||
// ===== 설정 (운영에선 환경변수 사용 권장) =====
|
||||
$EXPECTED_AUTH = 'abcd1234efgh5678'; //인증 key
|
||||
|
||||
$MYSQL_HOST = 'localhost';
|
||||
$MYSQL_USER = 'egbim';
|
||||
$MYSQL_PASS = 'baron3840!!';
|
||||
$MYSQL_DB = 'egbim';
|
||||
|
||||
$DESCOPE_PROJECT_ID = 'P2wON5fy1K6kyia269VpeIzYP8oP'; //ptoject ID
|
||||
$DESCOPE_MGMT_KEY = 'K32l5ORmzy32OvaaPvpdZsMY3JmKQb7a3vvrl10PgjlJUGk3K7EssMH3uW5VGQSbrgtEdPj'; //management key
|
||||
// $DESCOPE_DELETE_URL = 'https://api.descope.com/v1/mgmt/user/delete'; //descope delete endpoint
|
||||
$DESCOPE_STATUS_URL = 'https://api.descope.com/v1/mgmt/user/update/status';
|
||||
|
||||
$BEPS_URL = 'http://1.234.37.173:13000/user/emp_status'; //BEPs end point
|
||||
|
||||
// ===== 공통 응답 헬퍼 =====
|
||||
function respond(array $payload, int $statusCode = 200) {
|
||||
http_response_code($statusCode);
|
||||
echo json_encode($payload, JSON_UNESCAPED_UNICODE);
|
||||
exit;
|
||||
}
|
||||
|
||||
// ===== 1) 인증 검사 =====
|
||||
$authHeader = '';
|
||||
if (function_exists('getallheaders')) {
|
||||
$hdrs = getallheaders();
|
||||
if (!empty($hdrs['Authorization'])) $authHeader = $hdrs['Authorization'];
|
||||
if (!empty($hdrs['authorization'])) $authHeader = $hdrs['authorization'];
|
||||
}
|
||||
if (!$authHeader && !empty($_SERVER['HTTP_AUTHORIZATION'])) {
|
||||
$authHeader = $_SERVER['HTTP_AUTHORIZATION'];
|
||||
}
|
||||
if ($authHeader !== $EXPECTED_AUTH) {
|
||||
respond([
|
||||
'status' => 'error',
|
||||
'step' => 'auth',
|
||||
'message' => '인증에 실패했습니다. 올바른 인증키를 사용해 주세요.'
|
||||
], 401);
|
||||
}
|
||||
|
||||
// ===== 2) JSON 입력 파싱 =====
|
||||
$input = file_get_contents('php://input');
|
||||
$data = json_decode($input, true);
|
||||
if (!is_array($data)) {
|
||||
respond([
|
||||
'status' => 'error',
|
||||
'step' => 'parse',
|
||||
'message' => '전달된 JSON이 올바르지 않습니다.'
|
||||
], 400);
|
||||
}
|
||||
|
||||
// ===== 3) 필수 항목 검증 =====
|
||||
$required = ['emp_no','name','email','type','date'];
|
||||
$labels = [
|
||||
'emp_no' => '사번',
|
||||
'name' => '이름',
|
||||
'email' => '이메일',
|
||||
'type' => '퇴사 유형',
|
||||
'date' => '퇴사 일자'
|
||||
];
|
||||
foreach ($required as $k) {
|
||||
if (!isset($data[$k]) || $data[$k] === '') {
|
||||
respond([
|
||||
'status' => 'error',
|
||||
'step' => 'validation',
|
||||
'message' => "필수 항목이 누락되었습니다: {$labels[$k]} 누락."
|
||||
], 400);
|
||||
}
|
||||
}
|
||||
|
||||
// ===== 4) DB 연결 =====
|
||||
try {
|
||||
$db = new mysqli($MYSQL_HOST, $MYSQL_USER, $MYSQL_PASS, $MYSQL_DB);
|
||||
$db->set_charset('utf8mb4');
|
||||
} catch (mysqli_sql_exception $e) {
|
||||
respond([
|
||||
'status' => 'error',
|
||||
'step' => 'db_connect',
|
||||
'message' => '데이터베이스 연결에 실패했습니다.',
|
||||
'detail' => $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
|
||||
// ===== 5) INSERT (1062 중복 예외 캐치) =====
|
||||
try {
|
||||
$stmt = $db->prepare("
|
||||
INSERT INTO resign_info (emp_no, name, email, type, date)
|
||||
VALUES (?, ?, ?, ?, ?)
|
||||
");
|
||||
$stmt->bind_param('sssss',
|
||||
$data['emp_no'],
|
||||
$data['name'],
|
||||
$data['email'],
|
||||
$data['type'],
|
||||
$data['date']
|
||||
);
|
||||
$stmt->execute();
|
||||
|
||||
$dbInserted = [
|
||||
'affected_rows' => $stmt->affected_rows,
|
||||
'insert_id' => $stmt->insert_id
|
||||
];
|
||||
$stmt->close();
|
||||
} catch (mysqli_sql_exception $e) {
|
||||
if ($e->getCode() === 1062) {
|
||||
$db->close();
|
||||
respond([
|
||||
'status' => 'error',
|
||||
'step' => 'db_insert',
|
||||
'message' => '이미 등록된 퇴사자 정보입니다. (PK/UNIQUE 중복)',
|
||||
'detail' => $e->getMessage()
|
||||
], 409);
|
||||
}
|
||||
$db->close();
|
||||
respond([
|
||||
'status' => 'error',
|
||||
'step' => 'db_insert',
|
||||
'message' => '퇴사자 정보를 저장하는 데 실패했습니다.',
|
||||
'detail' => $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
|
||||
// ===== 6) 후속 작업: Descope 삭제 → (성공시에만) BEPS 상태 업데이트 =====
|
||||
$result = [
|
||||
'status' => 'success',
|
||||
'message' => '퇴사자 정보가 DB에 정상적으로 등록되었습니다.',
|
||||
'db' => ['status' => 'ok', 'meta' => $dbInserted],
|
||||
'descope' => null,
|
||||
'emp_status' => null
|
||||
];
|
||||
|
||||
$descope_ok = false;
|
||||
|
||||
// 6-1) Descope 사용자 삭제
|
||||
// if (!empty($data['email'])) {
|
||||
// $headers = [
|
||||
// 'Content-Type: application/json',
|
||||
// "Authorization: Bearer {$DESCOPE_PROJECT_ID}:{$DESCOPE_MGMT_KEY}"
|
||||
// ];
|
||||
// $body = json_encode(['loginId' => $data['email']]);
|
||||
|
||||
// $ch = curl_init($DESCOPE_DELETE_URL);
|
||||
// curl_setopt_array($ch, [
|
||||
// CURLOPT_RETURNTRANSFER => true,
|
||||
// CURLOPT_POST => true,
|
||||
// CURLOPT_POSTFIELDS => $body,
|
||||
// CURLOPT_HTTPHEADER => $headers,
|
||||
// CURLOPT_TIMEOUT => 15
|
||||
// ]);
|
||||
// $resBody = curl_exec($ch);
|
||||
// $resCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
// $resErr = curl_error($ch);
|
||||
// curl_close($ch);
|
||||
|
||||
// if ($resErr) {
|
||||
// $result['descope'] = [
|
||||
// 'status' => 'error',
|
||||
// 'message' => 'Descope 사용자 삭제 중 cURL 오류',
|
||||
// 'detail' => $resErr
|
||||
// ];
|
||||
// $result['status'] = 'partial_success';
|
||||
// } elseif ($resCode >= 200 && $resCode < 300) {
|
||||
// $result['descope'] = ['status' => 'ok', 'message' => 'Descope 사용자 삭제에 성공했습니다.'];
|
||||
// $descope_ok = true;
|
||||
// } else {
|
||||
// $result['descope'] = [
|
||||
// 'status' => 'error',
|
||||
// 'message' => "Descope API 에러 (HTTP {$resCode})",
|
||||
// 'response' => json_decode($resBody, true)
|
||||
// ];
|
||||
// $result['status'] = 'partial_success';
|
||||
// }
|
||||
// } else {
|
||||
// $result['descope'] = [
|
||||
// 'status' => 'skipped',
|
||||
// 'message' => '이메일 값이 없어 Descope 삭제를 생략했습니다.'
|
||||
// ];
|
||||
// }
|
||||
|
||||
// 6-1) Descope 사용자 상태 비활성화
|
||||
if (!empty($data['email'])) {
|
||||
$headers = [
|
||||
'Content-Type: application/json',
|
||||
"Authorization: Bearer {$DESCOPE_PROJECT_ID}:{$DESCOPE_MGMT_KEY}"
|
||||
];
|
||||
$body = json_encode(['loginId'=>$data['email'],'status'=>'disabled']);
|
||||
|
||||
$ch = curl_init($DESCOPE_STATUS_URL);
|
||||
curl_setopt_array($ch, [
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_POST => true,
|
||||
CURLOPT_POSTFIELDS => $body,
|
||||
CURLOPT_HTTPHEADER => $headers,
|
||||
CURLOPT_TIMEOUT => 15
|
||||
]);
|
||||
$resBody = curl_exec($ch);
|
||||
$resCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
$resErr = curl_error($ch);
|
||||
curl_close($ch);
|
||||
|
||||
if ($resErr) {
|
||||
$result['descope'] = ['status'=>'error','detail'=>$resErr];
|
||||
$result['status'] = 'partial_success';
|
||||
} elseif ($resCode >= 200 && $resCode < 300) {
|
||||
$result['descope'] = ['status'=>'ok','message'=>'Descope 사용자 상태를 disabled로 변경했습니다.'];
|
||||
$descope_ok = true;
|
||||
} else {
|
||||
$result['descope'] = [
|
||||
'status'=>'error',
|
||||
'http_code'=>$resCode,
|
||||
'response'=>json_decode($resBody,true)
|
||||
];
|
||||
$result['status'] = 'partial_success';
|
||||
}
|
||||
} else {
|
||||
$result['descope'] = [
|
||||
'status'=>'skipped',
|
||||
'message'=>'이메일 값이 없어 Descope 상태 변경 생략'
|
||||
];
|
||||
}
|
||||
|
||||
// 6-2) (조건부) BEPS 사내 emp_status 업데이트 — 오직 Descope 성공 시에만
|
||||
if ($descope_ok) {
|
||||
$bepsPayload = [
|
||||
'email' => $data['email'],
|
||||
'status' => 'inactive'
|
||||
];
|
||||
$ch2 = curl_init($BEPS_URL);
|
||||
curl_setopt_array($ch2, [
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_POST => true,
|
||||
CURLOPT_POSTFIELDS => json_encode($bepsPayload),
|
||||
CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
|
||||
CURLOPT_TIMEOUT => 15
|
||||
]);
|
||||
$bepsRes = curl_exec($ch2);
|
||||
$bepsCode = curl_getinfo($ch2, CURLINFO_HTTP_CODE);
|
||||
$bepsErr = curl_error($ch2);
|
||||
curl_close($ch2);
|
||||
|
||||
if ($bepsErr) {
|
||||
$result['emp_status'] = [
|
||||
'status' => 'error',
|
||||
'message' => 'BEPs 상태 업데이트 중 cURL 오류',
|
||||
'detail' => $bepsErr
|
||||
];
|
||||
$result['status'] = 'partial_success';
|
||||
} elseif ($bepsCode >= 200 && $bepsCode < 300) {
|
||||
$result['emp_status'] = ['status' => 'ok', 'message' => 'BEPs 상태 업데이트 성공'];
|
||||
} else {
|
||||
$result['emp_status'] = [
|
||||
'status' => 'error',
|
||||
'message' => "BEPs API 에러 (HTTP {$bepsCode})",
|
||||
'response' => json_decode($bepsRes, true)
|
||||
];
|
||||
$result['status'] = 'partial_success';
|
||||
}
|
||||
} else {
|
||||
$result['emp_status'] = [
|
||||
'status' => 'skipped',
|
||||
'message' => 'Descope 삭제 성공시에만 BEPS 전송 정책으로 인해 전송 생략'
|
||||
];
|
||||
}
|
||||
|
||||
// 정리 및 응답
|
||||
$db->close();
|
||||
respond($result, 200);
|
||||
@@ -0,0 +1,439 @@
|
||||
<?php
|
||||
// // 에러 출력 설정
|
||||
// ini_set('display_errors', 1);
|
||||
// error_reporting(E_ALL);
|
||||
|
||||
// // JSON 요청 파싱
|
||||
// header('Content-Type: application/json');
|
||||
// $data = json_decode(file_get_contents("php://input"), true);
|
||||
// print_r($data);
|
||||
|
||||
// // 인증키 확인
|
||||
// $headers = getallheaders();
|
||||
// if (!isset($headers['Authorization']) || $headers['Authorization'] !== 'abcd1234efgh5678') {
|
||||
// http_response_code(401);
|
||||
// echo json_encode(['status' => 'error', 'message' => '인증 실패']);
|
||||
// exit;
|
||||
// }
|
||||
|
||||
// // 필수 파라미터 확인
|
||||
// $required = ['emp_no', 'name', 'email', 'type', 'date'];
|
||||
// foreach ($required as $key) {
|
||||
// if (empty($data[$key])) {
|
||||
// http_response_code(400);
|
||||
// echo json_encode(['status' => 'error', 'message' => "$key 값이 누락되었습니다."]);
|
||||
// exit;
|
||||
// }
|
||||
// }
|
||||
|
||||
// // DB 연결
|
||||
// $conn = new mysqli('localhost', 'egbim', 'baron3840!!', 'egbim');
|
||||
// if ($conn->connect_error) {
|
||||
// http_response_code(500);
|
||||
// echo json_encode(['status' => 'error', 'message' => 'DB 연결 실패']);
|
||||
// exit;
|
||||
// }
|
||||
// mysqli_set_charset($conn, 'utf8mb4');
|
||||
|
||||
// // 중복 체크
|
||||
// $chk_stmt = $conn->prepare("SELECT COUNT(*) FROM resign_info WHERE emp_no = ? AND date = ?");
|
||||
// $chk_stmt->bind_param("ss", $data['emp_no'], $data['date']);
|
||||
// $chk_stmt->execute();
|
||||
// $chk_stmt->bind_result($exists);
|
||||
// $chk_stmt->fetch();
|
||||
// $chk_stmt->close();
|
||||
|
||||
// if ($exists > 0) {
|
||||
// http_response_code(409);
|
||||
// echo json_encode(['status' => 'error', 'message' => '이미 등록된 퇴사자 정보입니다.']);
|
||||
// exit;
|
||||
// }
|
||||
|
||||
// // INSERT 실행
|
||||
// $stmt = $conn->prepare("INSERT INTO resign_info (emp_no, name, email, type, date) VALUES (?, ?, ?, ?, ?)");
|
||||
// $stmt->bind_param("sssss", $data['emp_no'], $data['name'], $data['email'], $data['type'], $data['date']);
|
||||
|
||||
// if ($stmt->execute()) {
|
||||
// echo json_encode(['status' => 'success', 'message' => '퇴사자 정보가 등록되었습니다.']);
|
||||
// } else {
|
||||
// http_response_code(500);
|
||||
// echo json_encode(['status' => 'error', 'message' => 'DB insert 실패: ' . $stmt->error]);
|
||||
// }
|
||||
// $stmt->close();
|
||||
// $conn->close();
|
||||
?>
|
||||
<?php
|
||||
// 응답 타입 설정
|
||||
// header('Content-Type: application/json');
|
||||
|
||||
// // 1. Authorization 헤더 검사
|
||||
// $authHeader = '';
|
||||
|
||||
// // 다양한 환경에서 헤더를 안전하게 읽는 방법
|
||||
// if (function_exists('getallheaders')) {
|
||||
// $headers = getallheaders();
|
||||
// if (isset($headers['authorization'])) {
|
||||
// $authHeader = $headers['authorization'];
|
||||
// }
|
||||
// else if (isset($headers['Authorization'])) {
|
||||
// $authHeader = $headers['Authorization'];
|
||||
// }
|
||||
// } elseif (isset($_SERVER['HTTP_AUTHORIZATION'])) {
|
||||
// $authHeader = $_SERVER['HTTP_AUTHORIZATION'];
|
||||
// }
|
||||
|
||||
// // 정해진 인증키 (여기서 설정)
|
||||
// $expectedKey = 'abcd1234efgh5678';
|
||||
|
||||
// if ($authHeader !== $expectedKey) {
|
||||
// echo json_encode(["status" => "error", "message" => "인증 실패"]);
|
||||
// exit;
|
||||
// }
|
||||
|
||||
// // 2. POST된 JSON 데이터 수신
|
||||
// $input = file_get_contents('php://input');
|
||||
// $data = json_decode($input, true);
|
||||
|
||||
|
||||
|
||||
// // 3. 필수 파라미터 확인
|
||||
// $required = ['emp_no', 'name', 'email', 'type', 'date'];
|
||||
// foreach ($required as $key) {
|
||||
// if (empty($data[$key])) {
|
||||
// echo json_encode(["status" => "error", "message" => "누락된 필드: $key"]);
|
||||
// exit;
|
||||
// }
|
||||
// }
|
||||
|
||||
// // 4. DB 연결
|
||||
// $mysqli = new mysqli('localhost', 'egbim', 'baron3840!!', 'egbim');
|
||||
// if ($mysqli->connect_error) {
|
||||
// echo json_encode(["status" => "error", "message" => "DB 연결 실패"]);
|
||||
// exit;
|
||||
// }
|
||||
|
||||
// // 5. INSERT 실행
|
||||
// $stmt = $mysqli->prepare("
|
||||
// INSERT INTO resign_info (emp_no, name, email, type, date)
|
||||
// VALUES (?, ?, ?, ?, ?)
|
||||
// ");
|
||||
|
||||
// if (!$stmt) {
|
||||
// echo json_encode(["status" => "error", "message" => "쿼리 준비 실패"]);
|
||||
// exit;
|
||||
// }
|
||||
|
||||
// $stmt->bind_param("sssss", $data['emp_no'], $data['name'], $data['email'], $data['type'], $data['date']);
|
||||
|
||||
// if ($stmt->execute()) {
|
||||
// echo json_encode(["status" => "success", "message" => "퇴사자 정보가 등록되었습니다"]);
|
||||
// } else {
|
||||
// echo json_encode(["status" => "error", "message" => "DB insert 실패"]);
|
||||
// }
|
||||
|
||||
// $stmt->close();
|
||||
// $mysqli->close();
|
||||
|
||||
// // 6. Descope API로 **삭제** 호출
|
||||
// $projectId = 'P2wON5fy1K6kyia269VpeIzYP8oP';
|
||||
// $managementKey = 'K2ycqpjeh1voPBdxXxzB3ScZOQ6v9aiLmU2cIj70X1H8Kcoz0KWfCWmofUwAsAkJroXA8QC';
|
||||
// $loginId = $data['email'];
|
||||
|
||||
|
||||
// // 7. Descope 관리 API: 사용자 삭제 (delete user)
|
||||
// $url = 'https://api.descope.com/v1/mgmt/user/delete';
|
||||
// $headers = [
|
||||
// 'Content-Type: application/json',
|
||||
// "Authorization: Bearer {$projectId}:{$managementKey}"
|
||||
// ];
|
||||
// $body = json_encode([
|
||||
// 'loginId' => $loginId
|
||||
// ]);
|
||||
|
||||
// $ch = curl_init($url);
|
||||
// curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
// curl_setopt($ch, CURLOPT_POST, true);
|
||||
// curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
|
||||
// curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||||
|
||||
// $response = curl_exec($ch);
|
||||
// $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
// $curlErr = curl_error($ch);
|
||||
// curl_close($ch);
|
||||
|
||||
|
||||
// // 8. 사내 emp_status 업데이트 API
|
||||
// $internalUrl = 'http://172.16.10.191:20000/user/emp_status';
|
||||
// $payload2 = [
|
||||
// 'email' => $data['email'],
|
||||
// 'status' => 'inactive', // 'active' or 'inactive'
|
||||
// ];
|
||||
|
||||
// $ch2 = curl_init($internalUrl);
|
||||
// curl_setopt_array($ch2, [
|
||||
// CURLOPT_RETURNTRANSFER => true,
|
||||
// CURLOPT_POST => true,
|
||||
// CURLOPT_POSTFIELDS => json_encode($payload2),
|
||||
// CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
|
||||
// ]);
|
||||
// $res2 = curl_exec($ch2);
|
||||
// $code2 = curl_getinfo($ch2, CURLINFO_HTTP_CODE);
|
||||
// $err2 = curl_error($ch2);
|
||||
// curl_close($ch2);
|
||||
|
||||
// // 결과 리턴
|
||||
// if ($curlErr) {
|
||||
// echo json_encode([
|
||||
// 'status'=>'partial_success',
|
||||
// 'message'=>'DB 등록은 성공했으나 Descope 삭제 중 오류: '.$curlErr
|
||||
// ]);
|
||||
// } else {
|
||||
// $resData = json_decode($response, true);
|
||||
// if ($httpCode >= 200 && $httpCode < 300) {
|
||||
// echo json_encode([
|
||||
// 'status' => 'success',
|
||||
// 'message' => '퇴사자 DB 등록 및 Descope 사용자 삭제 완료',
|
||||
// 'descopeCode'=> $httpCode,
|
||||
// 'descopeRes' => $resData
|
||||
// ]);
|
||||
// } else {
|
||||
// echo json_encode([
|
||||
// 'status' => 'partial_success',
|
||||
// 'message' => 'DB 등록은 성공했으나 Descope API 에러',
|
||||
// 'descopeCode'=> $httpCode,
|
||||
// 'descopeRes' => $resData
|
||||
// ]);
|
||||
// }
|
||||
// }
|
||||
// exit;
|
||||
?>
|
||||
|
||||
<?php
|
||||
// resign_and_update.php
|
||||
header('Content-Type: application/json');
|
||||
|
||||
|
||||
// 1. Authorization 헤더 검사
|
||||
$authHeader = '';
|
||||
if (function_exists('getallheaders')) {
|
||||
$hdrs = getallheaders();
|
||||
if (!empty($hdrs['authorization'])) {
|
||||
$authHeader = $hdrs['authorization'];
|
||||
} elseif (!empty($hdrs['Authorization'])) {
|
||||
$authHeader = $hdrs['Authorization'];
|
||||
}
|
||||
} elseif (!empty($_SERVER['HTTP_AUTHORIZATION'])) {
|
||||
$authHeader = $_SERVER['HTTP_AUTHORIZATION'];
|
||||
}
|
||||
|
||||
$expectedKey = 'abcd1234efgh5678';
|
||||
if ($authHeader !== $expectedKey) {
|
||||
echo json_encode([
|
||||
'status' => 'error',
|
||||
'step' => 'auth',
|
||||
'message' => '인증에 실패했습니다. 올바른 인증키를 사용했는지 확인해 주세요.'
|
||||
], JSON_UNESCAPED_UNICODE);
|
||||
exit;
|
||||
}
|
||||
|
||||
// 2. POST된 JSON 데이터 수신
|
||||
$input = file_get_contents('php://input');
|
||||
$data = json_decode($input, true);
|
||||
if (!is_array($data)) {
|
||||
echo json_encode([
|
||||
'status' => 'error',
|
||||
'step' => 'parse',
|
||||
'message' => '전달된 JSON이 올바르지 않습니다.'
|
||||
], JSON_UNESCAPED_UNICODE);
|
||||
exit;
|
||||
}
|
||||
|
||||
// 3. 필수 파라미터 확인
|
||||
$required = ['emp_no','name','email','type','date'];
|
||||
foreach ($required as $key) {
|
||||
if (empty($data[$key])) {
|
||||
$friendly = [
|
||||
'emp_no' => '사번',
|
||||
'name' => '이름',
|
||||
'email' => '이메일',
|
||||
'type' => '퇴사 유형',
|
||||
'date' => '퇴사 일자'
|
||||
][$key] ?? $key;
|
||||
echo json_encode([
|
||||
'status' => 'error',
|
||||
'step' => 'validation',
|
||||
'message' => "필수 항목이 누락되었습니다: {$friendly} 누락."
|
||||
], JSON_UNESCAPED_UNICODE);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
// 4. DB 연결 및 INSERT
|
||||
$db = new mysqli('localhost','egbim','baron3840!!','egbim');
|
||||
if ($db->connect_error) {
|
||||
echo json_encode([
|
||||
'status' => 'error',
|
||||
'step' => 'db_connect',
|
||||
'message' => '데이터베이스 연결에 실패했습니다.'
|
||||
], JSON_UNESCAPED_UNICODE);
|
||||
exit;
|
||||
}
|
||||
$stmt = $db->prepare("
|
||||
INSERT INTO resign_info (emp_no,name,email,type,date)
|
||||
VALUES (?,?,?,?,?)
|
||||
");
|
||||
$stmt->bind_param('sssss',
|
||||
$data['emp_no'],
|
||||
$data['name'],
|
||||
$data['email'],
|
||||
$data['type'],
|
||||
$data['date']
|
||||
);
|
||||
|
||||
|
||||
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
|
||||
|
||||
try {
|
||||
$stmt->execute();
|
||||
if ($stmt->affected_rows === 0) {
|
||||
echo "중복된 데이터로 저장되지 않았습니다.";
|
||||
} else {
|
||||
echo "정상 저장되었습니다.";
|
||||
}
|
||||
} catch (mysqli_sql_exception $e) {
|
||||
if ($e->getCode() === 1062) {
|
||||
echo "중복된 키가 존재합니다: " . $e->getMessage();
|
||||
} else {
|
||||
echo "데이터베이스 오류 발생: " . $e->getMessage();
|
||||
}
|
||||
}
|
||||
exit;
|
||||
|
||||
if (!$stmt->execute()) {
|
||||
// 중복 키(Primary Key/email) 에러
|
||||
if ($stmt->errno === 1062) {
|
||||
echo json_encode([
|
||||
'status' => 'error',
|
||||
'step' => 'db_insert',
|
||||
'message' => '이미 동일한 이메일의 퇴사자 정보가 등록되어 있습니다.'
|
||||
], JSON_UNESCAPED_UNICODE);
|
||||
} else {
|
||||
echo json_encode([
|
||||
'status' => 'error',
|
||||
'step' => 'db_insert',
|
||||
'message' => '퇴사자 정보를 저장하는 데 실패했습니다: ' . $stmt->error
|
||||
], JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
$stmt->close();
|
||||
$db->close();
|
||||
exit;
|
||||
}
|
||||
else{
|
||||
// execute()는 성공했지만 변경된 행이 없는 경우
|
||||
if ($stmt->affected_rows === 0) {
|
||||
echo json_encode([
|
||||
'status' => 'error',
|
||||
'step' => 'db_insert',
|
||||
'message' => '이미 동일한 이메일의 퇴사자 정보가 존재하여 저장되지 않았습니다.'
|
||||
], JSON_UNESCAPED_UNICODE);
|
||||
$stmt->close();
|
||||
$db->close();
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$stmt->close();
|
||||
$db->close();
|
||||
|
||||
// 초기 응답 객체
|
||||
$result = [
|
||||
'status' => 'success',
|
||||
'db' => 'ok',
|
||||
'descope' => null,
|
||||
'emp_status' => null,
|
||||
'message' => '퇴사자 정보가 DB에 정상적으로 등록되었습니다.'
|
||||
];
|
||||
|
||||
// DB 실패 시 바로 리턴
|
||||
if (! $dbResult) {
|
||||
$result['status'] = 'error';
|
||||
echo json_encode($result, JSON_UNESCAPED_UNICODE);
|
||||
exit;
|
||||
}
|
||||
|
||||
// 이메일이 비어 있으면 나머지 호출 생략
|
||||
if (empty($data['email'])) {
|
||||
$result['status'] = 'partial_success';
|
||||
$result['message'] = '(이메일 정보가 없어 Descope 삭제 및 사내 상태 업데이트는 생략되었습니다.)';
|
||||
echo json_encode($result, JSON_UNESCAPED_UNICODE);
|
||||
exit;
|
||||
}
|
||||
|
||||
// 5. Descope 사용자 삭제
|
||||
$projectId = 'P2wON5fy1K6kyia269VpeIzYP8oP';
|
||||
$managementKey = 'K2ycqpjeh1voPBdxXxzB3ScZOQ6v9aiLmU2cIj70X1H8Kcoz0KWfCWmofUwAsAkJroXA8QC';
|
||||
|
||||
$ch1 = curl_init('https://api.descope.com/v1/mgmt/user/delete');
|
||||
curl_setopt_array($ch1, [
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_POST => true,
|
||||
CURLOPT_POSTFIELDS => json_encode(['loginId'=>$data['email']]),
|
||||
CURLOPT_HTTPHEADER => [
|
||||
'Content-Type: application/json',
|
||||
"Authorization: Bearer {$projectId}:{$managementKey}"
|
||||
],
|
||||
]);
|
||||
$res1 = curl_exec($ch1);
|
||||
$code1 = curl_getinfo($ch1, CURLINFO_HTTP_CODE);
|
||||
$err1 = curl_error($ch1);
|
||||
curl_close($ch1);
|
||||
|
||||
|
||||
if ($err1) {
|
||||
$result['descope'] = [
|
||||
'status' => 'error',
|
||||
'message' => 'Descope 사용자 삭제 중 오류가 발생했습니다: ' . $err1
|
||||
];
|
||||
} elseif ($code1 >= 200 && $code1 < 300) {
|
||||
$result['descope'] = ['status'=>'ok','message'=>'Descope 사용자 삭제에 성공했습니다.'];
|
||||
} else {
|
||||
$result['descope'] = [
|
||||
'status' => 'error',
|
||||
'message' => "Descope API 에러 (HTTP {$code1})",
|
||||
'response' => json_decode($res1, true)
|
||||
];
|
||||
}
|
||||
|
||||
// 6. 사내 emp_status 업데이트
|
||||
$ch2 = curl_init('http://172.16.10.191:20000/user/emp_status');
|
||||
curl_setopt_array($ch2, [
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_POST => true,
|
||||
CURLOPT_POSTFIELDS => json_encode([
|
||||
'email' => $data['email'],
|
||||
'status' => 'inactive'
|
||||
]),
|
||||
CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
|
||||
]);
|
||||
$res2 = curl_exec($ch2);
|
||||
$code2 = curl_getinfo($ch2, CURLINFO_HTTP_CODE);
|
||||
$err2 = curl_error($ch2);
|
||||
curl_close($ch2);
|
||||
|
||||
if ($err2) {
|
||||
$result['emp_status'] = [
|
||||
'status' => 'error',
|
||||
'message' => 'BEPs에 전송 오류가 발생했습니다: ' . $err2
|
||||
];
|
||||
} elseif ($code2 >= 200 && $code2 < 300) {
|
||||
$result['emp_status'] = ['status'=>'ok','message'=>'BEPs에 전송 성공했습니다.'];
|
||||
} else {
|
||||
$result['emp_status'] = [
|
||||
'status' => 'error',
|
||||
'message' => "BEPS API 에러 (HTTP {$code2})",
|
||||
'response' => json_decode($res2, true)
|
||||
];
|
||||
}
|
||||
echo json_encode($result, JSON_UNESCAPED_UNICODE);
|
||||
exit;
|
||||
@@ -0,0 +1,229 @@
|
||||
<?php
|
||||
/**
|
||||
* resign_and_update.php
|
||||
* - 기본: Authorization + JSON 입력 필수
|
||||
* - ?test=1 붙이면 하드코딩 데이터로 테스트 가능
|
||||
*/
|
||||
|
||||
header('Content-Type: application/json');
|
||||
|
||||
ini_set('display_errors', '1');
|
||||
error_reporting(E_ALL);
|
||||
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
|
||||
|
||||
$EXPECTED_AUTH = 'abcd1234efgh5678';
|
||||
|
||||
$MYSQL_HOST = 'localhost';
|
||||
$MYSQL_USER = 'egbim';
|
||||
$MYSQL_PASS = 'baron3840!!';
|
||||
$MYSQL_DB = 'egbim';
|
||||
|
||||
$DESCOPE_PROJECT_ID = 'P2wON5fy1K6kyia269VpeIzYP8oP';
|
||||
$DESCOPE_MGMT_KEY = 'K32l5ORmzy32OvaaPvpdZsMY3JmKQb7a3vvrl10PgjlJUGk3K7EssMH3uW5VGQSbrgtEdPj';
|
||||
$DESCOPE_STATUS_URL = 'https://api.descope.com/v1/mgmt/user/update/status';
|
||||
|
||||
$BEPS_URL = 'http://1.234.37.173:13000/user/emp_status';
|
||||
|
||||
function respond($payload, $status = 200) {
|
||||
http_response_code($status);
|
||||
echo json_encode($payload, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
|
||||
exit;
|
||||
}
|
||||
|
||||
// ===== 1) 인증 검사 =====
|
||||
if (!(isset($_GET['test']) && $_GET['test'] == '1')) {
|
||||
$authHeader = '';
|
||||
if (function_exists('getallheaders')) {
|
||||
$hdrs = getallheaders();
|
||||
if (!empty($hdrs['Authorization'])) $authHeader = $hdrs['Authorization'];
|
||||
if (!empty($hdrs['authorization'])) $authHeader = $hdrs['authorization'];
|
||||
}
|
||||
if (!$authHeader && !empty($_SERVER['HTTP_AUTHORIZATION'])) {
|
||||
$authHeader = $_SERVER['HTTP_AUTHORIZATION'];
|
||||
}
|
||||
if ($authHeader !== $EXPECTED_AUTH) {
|
||||
respond([
|
||||
'status' => 'error',
|
||||
'step' => 'auth',
|
||||
'message' => '인증에 실패했습니다. 올바른 인증키를 사용해 주세요.'
|
||||
], 401);
|
||||
}
|
||||
}
|
||||
|
||||
// ===== 2) 데이터 소스: test=1 → 하드코딩, 아니면 JSON 입력 =====
|
||||
if (isset($_GET['test']) && $_GET['test'] == '1') {
|
||||
$data = [
|
||||
'emp_no' => 'b24014',
|
||||
'name' => '송대일',
|
||||
'email' => 'b24014@hanmaceng.co.kr',
|
||||
'type' => '퇴사',
|
||||
'date' => date('Y-m-d')
|
||||
];
|
||||
} else {
|
||||
$input = file_get_contents('php://input');
|
||||
$data = json_decode($input, true);
|
||||
if (!is_array($data)) {
|
||||
respond([
|
||||
'status' => 'error',
|
||||
'step' => 'parse',
|
||||
'message' => '전달된 JSON이 올바르지 않습니다.'
|
||||
], 400);
|
||||
}
|
||||
}
|
||||
|
||||
// ===== 3) 필수 항목 검증 =====
|
||||
$required = ['emp_no','name','email','type','date'];
|
||||
$labels = [
|
||||
'emp_no' => '사번',
|
||||
'name' => '이름',
|
||||
'email' => '이메일',
|
||||
'type' => '퇴사 유형',
|
||||
'date' => '퇴사 일자'
|
||||
];
|
||||
foreach ($required as $k) {
|
||||
if (!isset($data[$k]) || $data[$k] === '') {
|
||||
respond([
|
||||
'status' => 'error',
|
||||
'step' => 'validation',
|
||||
'message' => "필수 항목이 누락되었습니다: {$labels[$k]} 누락."
|
||||
], 400);
|
||||
}
|
||||
}
|
||||
|
||||
// ===== 4) DB 연결 =====
|
||||
try {
|
||||
$db = new mysqli($MYSQL_HOST, $MYSQL_USER, $MYSQL_PASS, $MYSQL_DB);
|
||||
$db->set_charset('utf8mb4');
|
||||
} catch (mysqli_sql_exception $e) {
|
||||
respond([
|
||||
'status' => 'error',
|
||||
'step' => 'db_connect',
|
||||
'message' => '데이터베이스 연결에 실패했습니다.',
|
||||
'detail' => $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
|
||||
// ===== 5) INSERT (중복 무시) =====
|
||||
try {
|
||||
$stmt = $db->prepare("
|
||||
INSERT INTO resign_info (emp_no, name, email, type, date)
|
||||
VALUES (?, ?, ?, ?, ?)
|
||||
");
|
||||
$stmt->bind_param('sssss',
|
||||
$data['emp_no'],
|
||||
$data['name'],
|
||||
$data['email'],
|
||||
$data['type'],
|
||||
$data['date']
|
||||
);
|
||||
$stmt->execute();
|
||||
|
||||
$dbInserted = [
|
||||
'affected_rows' => $stmt->affected_rows,
|
||||
'insert_id' => $stmt->insert_id
|
||||
];
|
||||
$stmt->close();
|
||||
} catch (mysqli_sql_exception $e) {
|
||||
if ($e->getCode() === 1062) {
|
||||
$dbInserted = ['affected_rows'=>0, 'insert_id'=>null, 'message'=>'중복으로 스킵됨'];
|
||||
} else {
|
||||
$db->close();
|
||||
respond([
|
||||
'status' => 'error',
|
||||
'step' => 'db_insert',
|
||||
'message' => '퇴사자 정보를 저장하는 데 실패했습니다.',
|
||||
'detail' => $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
// ===== 6) Descope 상태 변경 → BEPS 전송 =====
|
||||
$result = [
|
||||
'status' => 'success',
|
||||
'message' => '퇴사자 정보가 DB에 정상적으로 처리되었습니다.',
|
||||
'db' => ['status'=>'ok','meta'=>$dbInserted],
|
||||
'descope' => null,
|
||||
'emp_status' => null
|
||||
];
|
||||
|
||||
$descope_ok = false;
|
||||
|
||||
if (!empty($data['email'])) {
|
||||
$headers = [
|
||||
'Content-Type: application/json',
|
||||
"Authorization: Bearer {$DESCOPE_PROJECT_ID}:{$DESCOPE_MGMT_KEY}"
|
||||
];
|
||||
$body = json_encode(['loginId'=>$data['email'],'status'=>'disabled']);
|
||||
|
||||
$ch = curl_init($DESCOPE_STATUS_URL);
|
||||
curl_setopt_array($ch, [
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_POST => true,
|
||||
CURLOPT_POSTFIELDS => $body,
|
||||
CURLOPT_HTTPHEADER => $headers,
|
||||
CURLOPT_TIMEOUT => 15
|
||||
]);
|
||||
$resBody = curl_exec($ch);
|
||||
$resCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
$resErr = curl_error($ch);
|
||||
curl_close($ch);
|
||||
|
||||
if ($resErr) {
|
||||
$result['descope'] = ['status'=>'error','detail'=>$resErr];
|
||||
$result['status'] = 'partial_success';
|
||||
} elseif ($resCode >= 200 && $resCode < 300) {
|
||||
$result['descope'] = ['status'=>'ok','message'=>'Descope 사용자 상태를 disabled로 변경했습니다.'];
|
||||
$descope_ok = true;
|
||||
} else {
|
||||
$result['descope'] = [
|
||||
'status'=>'error',
|
||||
'http_code'=>$resCode,
|
||||
'response'=>json_decode($resBody,true)
|
||||
];
|
||||
$result['status'] = 'partial_success';
|
||||
}
|
||||
} else {
|
||||
$result['descope'] = [
|
||||
'status'=>'skipped',
|
||||
'message'=>'이메일 값이 없어 Descope 상태 변경 생략'
|
||||
];
|
||||
}
|
||||
|
||||
// BEPS 전송 (Descope 성공시에만)
|
||||
if ($descope_ok) {
|
||||
$bepsPayload = ['email'=>$data['email'],'status'=>'inactive'];
|
||||
$ch2 = curl_init($BEPS_URL);
|
||||
curl_setopt_array($ch2, [
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_POST => true,
|
||||
CURLOPT_POSTFIELDS => json_encode($bepsPayload),
|
||||
CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
|
||||
CURLOPT_TIMEOUT => 15
|
||||
]);
|
||||
$bepsRes = curl_exec($ch2);
|
||||
$bepsCode = curl_getinfo($ch2, CURLINFO_HTTP_CODE);
|
||||
$bepsErr = curl_error($ch2);
|
||||
curl_close($ch2);
|
||||
|
||||
if ($bepsErr) {
|
||||
$result['emp_status'] = ['status'=>'error','detail'=>$bepsErr];
|
||||
$result['status'] = 'partial_success';
|
||||
} elseif ($bepsCode >= 200 && $bepsCode < 300) {
|
||||
$result['emp_status'] = ['status'=>'ok','message'=>'BEPs 상태 업데이트 성공'];
|
||||
} else {
|
||||
$result['emp_status'] = [
|
||||
'status'=>'error',
|
||||
'http_code'=>$bepsCode,
|
||||
'response'=>json_decode($bepsRes,true)
|
||||
];
|
||||
$result['status'] = 'partial_success';
|
||||
}
|
||||
} else {
|
||||
$result['emp_status'] = [
|
||||
'status'=>'skipped',
|
||||
'message'=>'Descope 상태 변경 성공시에만 BEPS 전송'
|
||||
];
|
||||
}
|
||||
|
||||
$db->close();
|
||||
respond($result,200);
|
||||
@@ -0,0 +1,138 @@
|
||||
<?php
|
||||
if (!defined('_GNUBOARD_')) exit; // 개별 페이지 접근 불가
|
||||
|
||||
if (!defined('G5_USE_SHOP') || !G5_USE_SHOP) return;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// 쇼핑몰 상수 모음 시작
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
define('G5_SHOP_DIR', 'shop');
|
||||
|
||||
define('G5_SHOP_PATH', G5_PATH.'/'.G5_SHOP_DIR);
|
||||
define('G5_SHOP_URL', G5_URL.'/'.G5_SHOP_DIR);
|
||||
define('G5_MSHOP_PATH', G5_MOBILE_PATH.'/'.G5_SHOP_DIR);
|
||||
define('G5_MSHOP_URL', G5_MOBILE_URL.'/'.G5_SHOP_DIR);
|
||||
|
||||
define('G5_SHOP_IMG_URL', G5_SHOP_URL.'/'.G5_IMG_DIR);
|
||||
define('G5_MSHOP_IMG_URL', G5_MSHOP_URL.'/'.G5_IMG_DIR);
|
||||
|
||||
// 보안서버주소 설정
|
||||
if (G5_HTTPS_DOMAIN) {
|
||||
define('G5_HTTPS_SHOP_URL', G5_HTTPS_DOMAIN.'/'.G5_SHOP_DIR);
|
||||
define('G5_HTTPS_MSHOP_URL', G5_HTTPS_DOMAIN.'/'.G5_MOBILE_DIR.'/'.G5_SHOP_DIR);
|
||||
} else {
|
||||
define('G5_HTTPS_SHOP_URL', G5_SHOP_URL);
|
||||
define('G5_HTTPS_MSHOP_URL', G5_MSHOP_URL);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// 쇼핑몰 상수 모음 끝
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
|
||||
//==============================================================================
|
||||
// 쇼핑몰 필수 실행코드 모음 시작
|
||||
//==============================================================================
|
||||
|
||||
// 쇼핑몰 설정값 배열변수
|
||||
$default = sql_fetch(" select * from {$g5['g5_shop_default_table']} ");
|
||||
|
||||
if(!defined('_THEME_PREVIEW_')) {
|
||||
// 테마 경로 설정
|
||||
if(defined('G5_THEME_PATH')) {
|
||||
define('G5_THEME_SHOP_PATH', G5_THEME_PATH.'/'.G5_SHOP_DIR);
|
||||
define('G5_THEME_SHOP_URL', G5_THEME_URL.'/'.G5_SHOP_DIR);
|
||||
define('G5_THEME_MSHOP_PATH', G5_THEME_PATH.'/'.G5_MOBILE_DIR.'/'.G5_SHOP_DIR);
|
||||
define('G5_THEME_MSHOP_URL', G5_THEME_URL.'/'.G5_MOBILE_DIR.'/'.G5_SHOP_DIR);
|
||||
}
|
||||
|
||||
// 스킨 경로 설정
|
||||
if(preg_match('#^theme/(.+)$#', $default['de_shop_skin'], $match)) {
|
||||
if(defined('G5_THEME_PATH')) {
|
||||
define('G5_SHOP_SKIN_PATH', G5_THEME_PATH.'/'.G5_SKIN_DIR.'/shop/'.$match[1]);
|
||||
define('G5_SHOP_SKIN_URL', G5_THEME_URL .'/'.G5_SKIN_DIR.'/shop/'.$match[1]);
|
||||
} else {
|
||||
define('G5_SHOP_SKIN_PATH', G5_PATH.'/'.G5_SKIN_DIR.'/shop/'.$match[1]);
|
||||
define('G5_SHOP_SKIN_URL', G5_URL .'/'.G5_SKIN_DIR.'/shop/'.$match[1]);
|
||||
}
|
||||
} else {
|
||||
define('G5_SHOP_SKIN_PATH', G5_PATH.'/'.G5_SKIN_DIR.'/shop/'.$default['de_shop_skin']);
|
||||
define('G5_SHOP_SKIN_URL', G5_URL .'/'.G5_SKIN_DIR.'/shop/'.$default['de_shop_skin']);
|
||||
}
|
||||
|
||||
if(preg_match('#^theme/(.+)$#', $default['de_shop_mobile_skin'], $match)) {
|
||||
if(defined('G5_THEME_PATH')) {
|
||||
define('G5_MSHOP_SKIN_PATH', G5_THEME_MOBILE_PATH.'/'.G5_SKIN_DIR.'/shop/'.$match[1]);
|
||||
define('G5_MSHOP_SKIN_URL', G5_THEME_URL .'/'.G5_MOBILE_DIR.'/'.G5_SKIN_DIR.'/shop/'.$match[1]);
|
||||
} else {
|
||||
define('G5_MSHOP_SKIN_PATH', G5_MOBILE_PATH.'/'.G5_SKIN_DIR.'/shop/'.$match[1]);
|
||||
define('G5_MSHOP_SKIN_URL', G5_MOBILE_URL .'/'.G5_SKIN_DIR.'/shop/'.$match[1]);
|
||||
}
|
||||
} else {
|
||||
define('G5_MSHOP_SKIN_PATH', G5_MOBILE_PATH.'/'.G5_SKIN_DIR.'/shop/'.$default['de_shop_mobile_skin']);
|
||||
define('G5_MSHOP_SKIN_URL', G5_MOBILE_URL .'/'.G5_SKIN_DIR.'/shop/'.$default['de_shop_mobile_skin']);
|
||||
}
|
||||
}
|
||||
|
||||
if( !isset($g5['g5_shop_post_log_table']) || !$g5['g5_shop_post_log_table'] ){
|
||||
$g5['g5_shop_post_log_table'] = G5_SHOP_TABLE_PREFIX.'order_post_log'; // 주문요청 로그 테이블
|
||||
}
|
||||
|
||||
// 옵션 ID 특수문자 필터링 패턴
|
||||
define('G5_OPTION_ID_FILTER', '/[\'\"\\\'\\\"]/');
|
||||
|
||||
if(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS']=='on') {
|
||||
// 토스페이먼츠 현금영수증 실결제 URL 상수
|
||||
define('SHOP_TOSSPAYMENTS_CASHRECEIPT_REAL_JS', 'https://pgweb.tosspayments.com/WEB_SERVER/js/receipt_link.js');
|
||||
// 토스페이먼츠 현금영수증 테스트 URL 상수
|
||||
define('SHOP_TOSSPAYMENTS_CASHRECEIPT_TEST_JS', 'https://pgweb.tosspayments.com:7085/WEB_SERVER/js/receipt_link.js');
|
||||
} else {
|
||||
// 토스페이먼츠 현금영수증 실결제 URL 상수
|
||||
define('SHOP_TOSSPAYMENTS_CASHRECEIPT_REAL_JS', 'http://pgweb.tosspayments.com/WEB_SERVER/js/receipt_link.js');
|
||||
// 토스페이먼츠 현금영수증 테스트 URL 상수
|
||||
define('SHOP_TOSSPAYMENTS_CASHRECEIPT_TEST_JS', 'http://pgweb.tosspayments.com:7085/WEB_SERVER/js/receipt_link.js');
|
||||
}
|
||||
|
||||
// 네이버페이를 신용카드 결제창에서 지원하고 있으므로 네이버에 직접신청하는 결제 기능을 미사용(false:기본설정) 합니다. (kagla,211019)
|
||||
// 네이버에서 직접신청 결제를 사용(true)하시는 경우 모든 문제를 직접 해결해 주셔야 합니다.
|
||||
define('G5_SHOP_DIRECT_NAVERPAY', false); // false 미사용(기본설정), true 사용
|
||||
|
||||
/*
|
||||
// 주문상태 상수
|
||||
define('G5_OD_STATUS_ORDER' , '입금확인중');
|
||||
define('G5_OD_STATUS_SETTLE' , '결제완료');
|
||||
define('G5_OD_STATUS_READY' , '배송준비중');
|
||||
define('G5_OD_STATUS_DELIVERY' , '배송중');
|
||||
define('G5_OD_STATUS_FINISH' , '배송완료');
|
||||
*/
|
||||
|
||||
/*
|
||||
# 주문상태는 상수로 처리하지 않고 실제 문자열 값을 처리한다.
|
||||
|
||||
'쇼핑' : 고객이 장바구니에 상품을 담고 있는 경우 입니다.
|
||||
'입금확인중' : 무통장, 가상계좌의 경우 결제하기 전을 말합니다.
|
||||
'결제완료' : 결제가 완료된 상태를 말합니다.
|
||||
'배송준비중' : 배송준비중이 되면 취소가 불가합니다.
|
||||
'배송중' : 배송중이면 반품이 불가합니다.
|
||||
'배송완료' : 배송이 완료된 상태에서만 포인트적립이 가능합니다.
|
||||
'취소' : 입금확인중이나 결제완료후 취소가 가능합니다.
|
||||
'반품' : 배송완료 후에만 반품처리가 가능합니다.
|
||||
'품절' :
|
||||
|
||||
|
||||
# 13.10.04
|
||||
|
||||
'쇼핑' : 고객이 장바구니에 상품을 담고 있는 경우 입니다.
|
||||
'주문' : 무통장, 가상계좌의 경우 결제하기 전을 말합니다.
|
||||
'입금' : 신용카드, 계좌이체, 휴대폰결제가 된 상태, 무통장, 가상계좌는 주문후 입금한 상태를 말합니다.
|
||||
'배송' : 배송이 되면 취소가 불가합니다.
|
||||
'완료' : 배송이 완료된 상태에서만 포인트적립이 가능합니다.
|
||||
'취소' : 입금이후로는 고객의 취소가 불가합니다.
|
||||
'반품' : 배송완료 후에만 반품처리가 가능합니다.
|
||||
'품절' : 주문이나 입금후 상품의 품절된 상태를 나타냅니다.
|
||||
*/
|
||||
|
||||
//==============================================================================
|
||||
// 쇼핑몰 필수 실행코드 모음 끝
|
||||
//==============================================================================;
|
||||
@@ -0,0 +1,193 @@
|
||||
<?php
|
||||
// // test_resign_disable.php
|
||||
|
||||
// // 응답 타입
|
||||
// header('Content-Type: application/json');
|
||||
|
||||
// // 1) 테스트용 하드코딩 데이터
|
||||
// $data = [
|
||||
// 'emp_no' => 'b24014',
|
||||
// 'name' => '테스트유저',
|
||||
// 'email' => 'b24014@hanmaceng.co.kr',
|
||||
// 'type' => '퇴사',
|
||||
// 'date' => date('Y-m-d'),
|
||||
// ];
|
||||
|
||||
// // 2) DB 연결
|
||||
// $mysqli = new mysqli('localhost', 'egbim', 'baron3840!!', 'egbim');
|
||||
// if ($mysqli->connect_error) {
|
||||
// echo json_encode(["status" => "error", "message" => "DB 연결 실패: " . $mysqli->connect_error]);
|
||||
// exit;
|
||||
// }
|
||||
|
||||
// // 3) INSERT 실행
|
||||
// $stmt = $mysqli->prepare("
|
||||
// INSERT INTO resign_info (emp_no, name, email, type, date)
|
||||
// VALUES (?, ?, ?, ?, ?)
|
||||
// ");
|
||||
// if (!$stmt) {
|
||||
// echo json_encode(["status" => "error", "message" => "쿼리 준비 실패: " . $mysqli->error]);
|
||||
// exit;
|
||||
// }
|
||||
// $stmt->bind_param("sssss",
|
||||
// $data['emp_no'],
|
||||
// $data['name'],
|
||||
// $data['email'],
|
||||
// $data['type'],
|
||||
// $data['date']
|
||||
// );
|
||||
|
||||
// if (!$stmt->execute()) {
|
||||
// echo json_encode(["status" => "error", "message" => "DB insert 실패: " . $stmt->error]);
|
||||
// exit;
|
||||
// }
|
||||
// $stmt->close();
|
||||
// $mysqli->close();
|
||||
|
||||
// // 4) Descope API 호출
|
||||
// $projectId = 'P2wON5fy1K6kyia269VpeIzYP8oP';
|
||||
// $managementKey = 'K2ycqpjeh1voPBdxXxzB3ScZOQ6v9aiLmU2cIj70X1H8Kcoz0KWfCWmofUwAsAkJroXA8QC';
|
||||
// $loginId = $data['email'];
|
||||
// $status = 'disabled';
|
||||
|
||||
// $descopeUrl = 'https://api.descope.com/v1/mgmt/user/update/status';
|
||||
// $headers = [
|
||||
// "Content-Type: application/json",
|
||||
// "Authorization: Bearer {$projectId}:{$managementKey}"
|
||||
// ];
|
||||
// $body = json_encode([
|
||||
// "loginId" => $loginId,
|
||||
// "status" => $status
|
||||
// ]);
|
||||
|
||||
// $ch = curl_init($descopeUrl);
|
||||
// curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
// curl_setopt($ch, CURLOPT_POST, true);
|
||||
// curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
|
||||
// curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||||
|
||||
// $response = curl_exec($ch);
|
||||
// $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
// $curlErr = curl_error($ch);
|
||||
// curl_close($ch);
|
||||
|
||||
// // 5) 결과 출력
|
||||
// if ($curlErr) {
|
||||
// echo json_encode([
|
||||
// "status" => "partial_success",
|
||||
// "message" => "DB는 성공, Descope 호출 중 오류: " . $curlErr
|
||||
// ]);
|
||||
// } else {
|
||||
// $resData = json_decode($response, true);
|
||||
// if ($httpCode >= 200 && $httpCode < 300) {
|
||||
// echo json_encode([
|
||||
// "status" => "success",
|
||||
// "message" => "테스트 완료: DB 등록 및 Descope 비활성화 성공",
|
||||
// "descopeCode" => $httpCode,
|
||||
// "descopeRes" => $resData
|
||||
// ]);
|
||||
// } else {
|
||||
// echo json_encode([
|
||||
// "status" => "partial_success",
|
||||
// "message" => "DB 등록은 성공했지만 Descope API 에러",
|
||||
// "descopeCode" => $httpCode,
|
||||
// "descopeRes" => $resData
|
||||
// ]);
|
||||
// }
|
||||
// }
|
||||
?>
|
||||
<?php
|
||||
// resign_and_delete.php
|
||||
header('Content-Type: application/json');
|
||||
|
||||
// 0) 테스트용 하드코딩 (원한다면 POST 데이터로 바꿀 수 있습니다)
|
||||
$data = [
|
||||
'emp_no' => 'b24014',
|
||||
'name' => '테스트유저',
|
||||
'email' => 'b24014@hanmaceng.co.kr',
|
||||
'type' => '퇴사',
|
||||
'date' => date('Y-m-d'),
|
||||
];
|
||||
|
||||
// 1) DB 연결 & INSERT
|
||||
$mysqli = new mysqli('localhost', 'egbim', 'baron3840!!', 'egbim');
|
||||
if ($mysqli->connect_error) {
|
||||
echo json_encode(['status'=>'error','message'=>'DB 연결 실패: '.$mysqli->connect_error]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$stmt = $mysqli->prepare("
|
||||
INSERT INTO resign_info (emp_no, name, email, type, date)
|
||||
VALUES (?, ?, ?, ?, ?)
|
||||
");
|
||||
$stmt->bind_param(
|
||||
'sssss',
|
||||
$data['emp_no'],
|
||||
$data['name'],
|
||||
$data['email'],
|
||||
$data['type'],
|
||||
$data['date']
|
||||
);
|
||||
if (! $stmt->execute()) {
|
||||
echo json_encode(['status'=>'error','message'=>'DB insert 실패: '.$stmt->error]);
|
||||
exit;
|
||||
}
|
||||
$stmt->close();
|
||||
$mysqli->close();
|
||||
|
||||
// 2) Descope API로 **삭제** 호출
|
||||
$projectId = 'P2wON5fy1K6kyia269VpeIzYP8oP';
|
||||
$managementKey = 'K2ycqpjeh1voPBdxXxzB3ScZOQ6v9aiLmU2cIj70X1H8Kcoz0KWfCWmofUwAsAkJroXA8QC';
|
||||
$loginId = $data['email'];
|
||||
|
||||
// Descope 관리 API: 사용자 삭제 (delete user)
|
||||
$url = 'https://api.descope.com/v1/mgmt/user/delete';
|
||||
$headers = [
|
||||
'Content-Type: application/json',
|
||||
"Authorization: Bearer {$projectId}:{$managementKey}"
|
||||
];
|
||||
$body = json_encode([
|
||||
'loginId' => $loginId
|
||||
]);
|
||||
|
||||
$ch = curl_init($url);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_POST, true);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||||
|
||||
$response = curl_exec($ch);
|
||||
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
$curlErr = curl_error($ch);
|
||||
curl_close($ch);
|
||||
|
||||
|
||||
// 3) 사내 emp_status 업데이트 API
|
||||
$internalUrl = 'http://172.16.10.191:20000/user/emp_status';
|
||||
$payload2 = [
|
||||
'email' => $data['email'],
|
||||
'status' => 'inactive', // 'active' or 'inactive'
|
||||
];
|
||||
|
||||
$ch2 = curl_init($internalUrl);
|
||||
curl_setopt_array($ch2, [
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_POST => true,
|
||||
CURLOPT_POSTFIELDS => json_encode($payload2),
|
||||
CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
|
||||
]);
|
||||
$res2 = curl_exec($ch2);
|
||||
$code2 = curl_getinfo($ch2, CURLINFO_HTTP_CODE);
|
||||
$err2 = curl_error($ch2);
|
||||
curl_close($ch2);
|
||||
|
||||
// 4) 결과 리턴
|
||||
$result = [
|
||||
'db' => ['status'=>'ok'],
|
||||
'descope' => $code1>=200&&$code1<300 ? 'deleted' : ['error'=>$err1,'code'=>$code1,'res'=>json_decode($res1,true)],
|
||||
'emp_status' => $code2>=200&&$code2<300 ? 'updated' : ['error'=>$err2,'code'=>$code2,'res'=>json_decode($res2,true)],
|
||||
];
|
||||
|
||||
echo json_encode($result, JSON_PRETTY_PRINT);
|
||||
exit;
|
||||
?>
|
||||
Reference in New Issue
Block a user