package com.dkl.framework.util;

import okhttp3.*;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Repository;

import java.io.IOException;

/**
 * @Author :rq
 * @Description : 退出系统 登出接口注销
 * @Date :2025/06/30 09:12
 * @Param :
 * @return :
 **/
@Repository
public class BackendServiceOutToken {


    @Value("${outData.url}")
    String outUrl;


    //登出接口
    public void subsystemToken(String token) {
        String url = outUrl + "/ht/uaa/clients/sysLogout";
        // 1. 创建OkHttpClient实例
        OkHttpClient client = new OkHttpClient();

        Request request = new Request.Builder()
                .url(url)
                .post(RequestBody.create(MediaType.parse("application/json"), "")) // 若Body为空，可写空字符串
                .addHeader("Authorization", "Bearer " + token) // 设置Authorization头
                .build();

        // 3. 执行请求并处理响应
        try (Response response = client.newCall(request).execute()) {
            if (response.isSuccessful()) { // 检查请求是否成功（HTTP状态码200-299）
                String responseBody = response.body().string(); // 获取响应体
                System.out.println("Response: " + responseBody);
            } else {
                System.err.println("Request failed with code: " + response.code());
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


}
