팁과노하우

2024.11.19 15:50

카카오소셜 토큰 연결끊기

kakao로그인후에 연결해제하거나 탈퇴해도 연결이 토큰 끊기지 않는 부분 아래 admin키를 발급받아서 처리하면됩니다.


function getKakaoUserIdByMbId($mb_id) {

    global $g5;

    $sql = "SELECT identifier FROM g5_member_social_profiles WHERE mb_id = '{$mb_id}'";

    $row = sql_fetch($sql);


    if ($row && isset($row['identifier'])) {

        return $row['identifier']; // 카카오 user_id 반환

    } else {

        return null; // 카카오 user_id가 없음

    }

}



function kakaoUnlinkUser($kakaoUserId) {

    $adminKey = 'xxxxxxxxxxxxxxxxxxxxxxxxxxx'; // 카카오 앱의 관리자 키

    $url = 'https://kapi.kakao.com/v1/user/unlink';


    $headers = array(

        "Authorization: KakaoAK $adminKey",

        "Content-Type: application/x-www-form-urlencoded;charset=utf-8"

    );


    $postData = array(

        'target_id_type' => 'user_id',

        'target_id' => $kakaoUserId

    );


    $ch = curl_init();

    curl_setopt($ch, CURLOPT_URL, $url);

    curl_setopt($ch, CURLOPT_POST, true);

    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postData));

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);


    $response = curl_exec($ch);

    $statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

    curl_close($ch);


    if ($statusCode == 200) {

        echo "사용자의 카카오 연결이 성공적으로 해제되었습니다.";

        return true;

    } else {

        echo "연결 해제 실패: " . $response;

        return false;

    }

}


[사용법]

$kakaoUserId = getKakaoUserIdByMbId($mb_id);//소셜 아이디 구하기
kakaoUnlinkUser($kakaoUserId);//카카오 연결끊기
  • 공유링크 복사
    미니홈 쪽지 구독하기
    구독하고 알림받기