package org.springblade.datamigration.util;


import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import okhttp3.*;


/**
 * @author lidexi
 * @date 2021/6/11 18:33
 */

public class TokenUtil {

	public static String getWuyeSystemToken(){
		try {
			OkHttpClient client = new OkHttpClient().newBuilder()
				.build();
			MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded");
			RequestBody body = RequestBody.create(mediaType, "loginName=admin&loginPwd=nxdxadmin");
			Request request = new Request.Builder()
				.url("http://139.9.103.171:9091/permissions/authentication/login")
				.method("POST", body)
				.addHeader("Content-Type", "application/x-www-form-urlencoded")
				.addHeader("Cookie", "access-token=df966584-9318-401c-8a77-3a1914d332cf")
				.build();
			Response response = client.newCall(request).execute();
			JSONObject jsonObject = JSONUtil.parseObj(response.body().string());

			if("200".equals(jsonObject.get("code").toString())){
				return jsonObject.getStr("data");
			}else{
				return "error";
			}


		} catch (Exception e) {
			throw new RuntimeException(e.getMessage());
		}
	}


}
