package com.malk.server.ekuaibao;

import com.alibaba.fastjson.JSON;
import com.malk.utils.UtilHttp;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * 读取配置文件参考FilePah
 */
@Data
@Component
@ConfigurationProperties(prefix = "ekuaibao")
public class EKBConf {

    // 易快报 corpId
    private String corpId;

    // 易快报不同平台获取前缀的方式不同
    private String platformApi;

    private String appKey;

    private String appSecurity;

    /**
     * 获取地址前缀
     */
    private static String platformUrl;

    public String getPlatformUrl() {
        if (StringUtils.isBlank(platformUrl)) {
            String rsp = UtilHttp.doGet(platformApi + "/api/openapi/v2/location?corpId=" + corpId, null, (Map) null);
            platformUrl = String.valueOf(((Map) JSON.parse(rsp)).get("value"));
        }
        return platformUrl;
    }
}
