package com.ffcs.ebp.ebpsdk;

import com.ffcs.ebp.ebpsdk.common.Response;
import org.apache.commons.lang.StringEscapeUtils;

import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

/**
 * 鉴权代码示例，非API接口示例，需自行按说明替换AK/SK/URL/请求方式等
 */
public class Main {
    public static void main(String[] args) throws UnsupportedEncodingException {
        String requestId = UUID.randomUUID().toString();
        //GET请求参数可拼接在url后
        String url = "https://kqa-global.ctapi.ctyun.cn/openapi/****";
        String ctyunAk = "官网ak";
        String ctyunSk = "官网sk";
        //POST时请求体，按接口文档要求修改
        String body = "{\"zjp\":\"zjp\"}";
        Map<String, Object> headerMap = new HashMap<>();
        headerMap.put("tenantId", "替换为租户ID");
        YunSign yunSign = new YunSign(url, ctyunAk, ctyunSk, requestId, body, 0, "application/json", null, headerMap);
        //GET请求传入GET
        Response response = yunSign.toDo("POST");
        System.out.println(response.getBody());

        //若有unicode编码问题参照此处做处理
        System.out.println(StringEscapeUtils.escapeJava("我的"));
        System.out.println(StringEscapeUtils.unescapeJava("\\\u6211\\\u7684"));

        //若有ISO乱码问题参照此处做处理
        byte[] raw = response.getBody().getBytes(StandardCharsets.ISO_8859_1);
        String resData = new String(raw, StandardCharsets.UTF_8);
    }
}
