package com.clx.performance.component;

import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.msl.common.dto.HttpDTO;
import com.msl.common.result.Result;
import com.msl.common.utils.EncryptUtil;
import com.msl.common.utils.HttpUtil;
import lombok.extern.slf4j.Slf4j;

import java.security.GeneralSecurityException;

@Slf4j
public class ThirdComponent {

    public static final String TRANSPORT_USER = "13403503399";
    public static final String TRANSPORT_KEY = "9Y1N5AUP8N2TI359";


    public static String encrypt(String param){

        HttpDTO httpDTO = null;
        try {
            httpDTO = EncryptUtil.buildDTO(TRANSPORT_USER, param, TRANSPORT_KEY, System.currentTimeMillis());
        } catch (GeneralSecurityException e) {
            throw new RuntimeException(e);
        }
        return JSONUtil.parse(httpDTO).toString();

    }

    public static String decrypt(String data) {
        try {
            String decrypt = EncryptUtil.decrypt(data, TRANSPORT_KEY);
            log.info("解密：{}", decrypt);
            return decrypt;
        } catch (GeneralSecurityException e) {
            throw new RuntimeException(e);
        }
    }


}
