package com.mosty.lzother.utils;

import com.google.common.collect.Maps;
import com.mosty.base.utils.Constant;
import com.mosty.common.core.util.HttpClientUtil;
import com.mosty.common.core.util.http.HttpUtils;
import okhttp3.*;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.Header;
import org.apache.http.HttpResponse;

import javax.crypto.Cipher;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.security.KeyFactory;
import java.security.PublicKey;
import java.security.spec.X509EncodedKeySpec;
import java.util.Base64;
import java.util.HashMap;
import java.util.Map;

public class ArthenaTest {

    /**
     * 注册到网关的调用方应用所属的公钥,用于加密需要加密的参数
     */
    private static final String publicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCOA2uL+d+0/DC8laEG9xbsfYZd9eoSJephsUdrnF4zLV+btHVCu/9MMwN0KMomgL63VjDI/w8VwL7urDhW6jG8jmVcXJezU5VetfPpFIupNEYIgdOJ2V0nMJlbYPNXfTNHDx1V7hDb4gbCOxXIda8tJHWhTk0gMls84ElqK0+G2wIDAQAB";

    private static final String rsaKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDbDiY4EyIXyS94pRMS18KP4wwCwnpncNYjj6y9WjdIxyz35Cs8UCKztPeeHZi7Pqovln/4ul3yzyU/A4RYEhwVLUr8bC8HHCHkINbI0aNLvS5uq3uZd7NbgjA/F1O0XvC0whVqCBLNM0HNtkUyGDGz9r1+X2DpaYyvCxD+Mt8BOQIDAQAB";
    /**
     * 注册到网关的调用方应用的key,作为唯一标识符
     */
    private static final String athenaAppKey = "afbbc6936d0243aea4f421fbf2b6b75d";
    /**
     * 注册到网关的调用方应用的名字
     */
    private static final String athenaAppName = "智慧派出所";

    private static final String url = "/athena/forward/93AD36543A39D2505C70A56C66D6B9FCF195D02A717E51E34E29703D5C49ACC6";

    private static final String ysToken = "bc837f91-76a7-4314-b4c0-db98d62b2931";


    private static String encryptData(String str, String publicKeyText) throws Exception {
        byte[] decoded = Base64.getDecoder().decode(publicKeyText);
        X509EncodedKeySpec keySpec = new X509EncodedKeySpec(decoded);
        KeyFactory keyFactory = KeyFactory.getInstance("RSA");
        PublicKey pk = keyFactory.generatePublic(keySpec);
        Cipher cipher = Cipher.getInstance("RSA");
        cipher.init(Cipher.ENCRYPT_MODE, pk);
        byte[] encryptedData = cipher.doFinal(str.getBytes());
        return Base64.getEncoder().encodeToString(encryptedData);
    }

}
