me.zhyd.oauth.utils.UrlBuilder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of JustAuth Show documentation
Show all versions of JustAuth Show documentation
史上最全的整合第三方登录的开源库。目前已支持Github、Gitee、微博、钉钉、百度、Coding、腾讯云开发者平台、OSChina、支付宝、
QQ、微信开放平台、微信公众平台、淘宝、Google、Facebook、抖音、领英、小米、微软、今日头条、Teambition、StackOverflow、Pinterest、人人、华为、
企业微信、酷家乐、Gitlab、美团、饿了么和推特等第三方平台的授权登录。
Login, so easy!
The newest version!
package me.zhyd.oauth.utils;
import com.xkcoding.http.util.MapUtil;
import com.xkcoding.http.util.StringUtil;
import lombok.Setter;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
/**
*
* 构造URL
*
*
* @author yangkai.shen (https://xkcoding.com)
* @since 1.9.0
*/
@Setter
public class UrlBuilder {
private final Map params = new LinkedHashMap<>(7);
private String baseUrl;
private UrlBuilder() {
}
/**
* @param baseUrl 基础路径
* @return the new {@code UrlBuilder}
*/
public static UrlBuilder fromBaseUrl(String baseUrl) {
UrlBuilder builder = new UrlBuilder();
builder.setBaseUrl(baseUrl);
return builder;
}
/**
* 只读的参数Map
*
* @return unmodifiable Map
* @since 1.15.0
*/
public Map getReadOnlyParams() {
return Collections.unmodifiableMap(params);
}
/**
* 添加参数
*
* @param key 参数名称
* @param value 参数值
* @return this UrlBuilder
*/
public UrlBuilder queryParam(String key, Object value) {
if (StringUtil.isEmpty(key)) {
throw new RuntimeException("参数名不能为空");
}
String valueAsString = (value != null ? value.toString() : null);
this.params.put(key, valueAsString);
return this;
}
/**
* 构造url
*
* @return url
*/
public String build() {
return this.build(false);
}
/**
* 构造url
*
* @param encode 转码
* @return url
*/
public String build(boolean encode) {
if (MapUtil.isEmpty(this.params)) {
return this.baseUrl;
}
String baseUrl = StringUtils.appendIfNotContain(this.baseUrl, "?", "&");
String paramString = MapUtil.parseMapToString(this.params, encode);
return baseUrl + paramString;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy