package com.hzya.frame.u8.util;

import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpRequest;
import com.alibaba.fastjson.JSONObject;
import com.hzya.frame.u8.dto.U8ResponseDTO;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

/**
 * @Description
 * @Author xiangerlin
 * @Date 2024/5/14 15:30
 **/
public class U8Util {

    static Logger logger = LogManager.getLogger(U8Util.class);

    //获取token
    public static String getToken() {
        String url = "http://127.0.0.1:51910/Api/Base/GetToken";
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("secretkey", "L1NhkDrQhtBDzTxFxPI0jxWcBzTBSPvaI5xZusRRi9ofS9d6ngxrj1erwbdjxtUT");
        logger.info("获取U8token参数:{}", jsonObject.toJSONString());
        String token = HttpRequest.post( url).body(jsonObject.toJSONString()).timeout(60000).execute().body();
        logger.info("token返回参数:{}", jsonObject.toJSONString());
        if (StrUtil.isNotEmpty(token)) {
            U8ResponseDTO u8ResponseDTO = JSONObject.parseObject(token, U8ResponseDTO.class);
            return u8ResponseDTO.getMessage();
        }
        return token;

    }
}
