package com.fs.kingbos.util;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

import static com.fs.kingbos.util.SignUtil.currentSeconds;

public class UrlUtil {
    public static String getUrl(String url, String sign) {
        String updatedUrl = updateURLParams(url, "timestep", String.valueOf(currentSeconds()));
        updatedUrl = updateURLParams(updatedUrl, "sign", sign);
        return updatedUrl;
    }

    public static String updateURLParams(String url, String param, String value) {
        String encodedValue;
        try {
            encodedValue = URLEncoder.encode(value, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            encodedValue = value;
            e.printStackTrace();
        }

        return url.replaceAll(param + "=", param + encodedValue);
    }
}
