package com.mortals.httpclient;

import cn.hutool.core.codec.Base64;
import cn.hutool.core.io.FileUtil;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import java.security.NoSuchAlgorithmException;

/**
 * @author: zxfei
 * @date: 2022/5/18 10:35
 * @description:
 **/
public class Test {
    public static void main(String[] args) throws NoSuchAlgorithmException {
//        SM4Utils sm4 = new SM4Utils();
//        sm4.secretKey = "JeF8U9wHFOMfs2Y8";
//        sm4.hexString = false;
//        String transformation = "SM4/ECB/Padding";
//        SMCipher clipher = SMCipher.getInstance(transformation);
//        clipher.init(1, sm4.secretKey.getBytes(), sm4.iv.getBytes());
//        byte[] result = clipher.doFinal(plainText.getBytes());
//        System.out.println(Base64.encodeBase64URLSafeString(result));

        String encode = Base64.encode(FileUtil.readBytes("F:\\pics\\background.jpg"));

        JSONObject jsonObject = new JSONObject();

        JSONArray jsonArray = new JSONArray();
        JSONObject jsonObj = new JSONObject();
        jsonObj.put("imageBase64",encode);
        jsonArray.add(jsonObj);
        jsonObject.put("userMatterDetails",jsonArray);

        System.out.println(JSON.toJSONString(jsonObject));
        String post = HttpUtil.post("http://192.168.0.98:11078/sst/user/matter/apply/save", JSON.toJSONString(jsonObject));
        //String post = HttpUtil.post("http://192.168.0.98:11059/basics_api/sst/user/matter/apply/save", JSON.toJSONString(jsonObject));

        System.out.println(post);


    }
}
