StringKit.java 1.7 KB
Newer Older
D
dingzhiwei 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/*
 * Copyright (c) 2021-2031, 河北计全科技有限公司 (https://www.jeequan.com & jeequan@126.com).
 * <p>
 * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.gnu.org/licenses/lgpl.html
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.jeequan.jeepay.core.utils;

D
dingzhiwei 已提交
18 19 20 21
import cn.hutool.core.net.url.UrlBuilder;
import org.apache.commons.lang3.StringUtils;

import java.util.Map;
D
dingzhiwei 已提交
22 23 24 25
import java.util.UUID;

/*
* String 工具类
terrfly's avatar
terrfly 已提交
26
*
D
dingzhiwei 已提交
27 28 29 30 31 32 33 34 35 36 37 38 39
* @author terrfly
* @site https://www.jeepay.vip
* @date 2021/6/8 16:58
*/
public class StringKit {

	public static String getUUID(){
		return UUID.randomUUID().toString().replace("-", "") + Thread.currentThread().getId();
	}

	public static String getUUID(int endAt){
		return getUUID().substring(0, endAt);
	}
D
dingzhiwei 已提交
40 41 42 43 44 45 46 47 48 49 50 51 52 53

	/** 拼接url参数 **/
	public static String appendUrlQuery(String url, Map<String, Object> map){

		if(StringUtils.isEmpty(url) || map == null || map.isEmpty()){
			return url;
		}
		UrlBuilder result = UrlBuilder.create().of(url);
		map.forEach((k, v) -> {
			if(k != null && v != null){
				result.addQuery(k, v.toString());
			}
		});

terrfly's avatar
terrfly 已提交
54
		return result.build();
D
dingzhiwei 已提交
55 56 57 58 59 60 61 62 63 64 65 66 67
	}


	/** 是否 http 或 https连接 **/
	public static boolean isAvailableUrl(String url){

		if(StringUtils.isEmpty(url)){
			return false;
		}

		return url.startsWith("http://") ||url.startsWith("https://");
	}

D
dingzhiwei 已提交
68
}