'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 // ]); // } // } ?> '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; ?>