Files
egbim_homepage/eng/skin/member/basic/descope_user_search.php
T
2026-07-23 16:15:57 +09:00

94 lines
3.4 KiB
PHP

<?php
// header('Content-Type: application/json');
// $management_key = 'P2wON5fy1K6kyia269VpeIzYP8oP:K2ycqpjeh1voPBdxXxzB3ScZOQ6v9aiLmU2cIj70X1H8Kcoz0KWfCWmofUwAsAkJroXA8QC';
// $loginId = $_POST['loginId'] ?? '';
// $url = "https://api.descope.com/v2/mgmt/user/search";
// $payload = json_encode([
// "loginId" => $loginId,
// "limit" => 1
// ]);
// $headers = [
// "Authorization: Bearer $management_key",
// "Content-Type: application/json"
// ];
// $ch = curl_init($url);
// curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
// curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
// $response = curl_exec($ch);
// $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
// curl_close($ch);
// if ($http_code === 200) {
// $res = json_decode($response, true);
// if (!empty($res['users'][0])) {
// // ✅ 먼저 $user에 복사
// $user = $res['users'][0];
// // ✅ 값이 없으면 테스트용 기본값 삽입
// $user['name'] = $user['name'] ?: '홍길동';
// $user['phone'] = $user['phone'] ?: '01012345678';
// $user['customAttributes']['company'] = $user['customAttributes']['company'] ?? '한맥ENG';
// $user['customAttributes']['team'] = $user['customAttributes']['team'] ?? '설계팀';
// $user['customAttributes']['employeeId'] = $user['customAttributes']['employeeId'] ?? 'HM2024';
// // ✅ 수정된 $user 사용
// echo json_encode(['status' => 'ok', 'user' => $user]);
// } else {
// echo json_encode(['status' => 'fail', 'message' => '사용자를 찾을 수 없음']);
// }
// } else {
// echo json_encode(['status' => 'fail', 'message' => 'Descope API 오류', 'code' => $http_code]);
// }
?>
<?php
header('Content-Type: application/json');
$management_key = 'P2wON5fy1K6kyia269VpeIzYP8oP:K32l5ORmzy32OvaaPvpdZsMY3JmKQb7a3vvrl10PgjlJUGk3K7EssMH3uW5VGQSbrgtEdPj';
$loginId = $_POST['loginId'] ?? '';
$url = "https://api.descope.com/v2/mgmt/user/search";
$payload = json_encode([
"loginId" => $loginId,
"limit" => 1
]);
$headers = [
"Authorization: Bearer $management_key",
"Content-Type: application/json"
];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($http_code === 200) {
$res = json_decode($response, true);
if (!empty($res['users'][0])) {
$user = $res['users'][0];
// ✅ 실제 값이 있으면 그대로 사용, 없으면 빈 문자열
$user['name'] = $user['name'] ?? '';
$user['phone'] = $user['phone'] ?? '';
$user['customAttributes']['company'] = $user['customAttributes']['company'] ?? '';
$user['customAttributes']['team'] = $user['customAttributes']['team'] ?? '';
$user['customAttributes']['employeeId'] = $user['customAttributes']['employeeId'] ?? '';
echo json_encode(['status' => 'ok', 'user' => $user]);
} else {
echo json_encode(['status' => 'fail', 'message' => '사용자를 찾을 수 없음']);
}
} else {
echo json_encode(['status' => 'fail', 'message' => 'Descope API 오류', 'code' => $http_code]);
}