http get请求参数工具类:
public class UrlSpiltUtils {
/**
* 小程序拼接
* @param url
* @return
*/
public static String urlSpilt(String url) {
if (StringUtils.isNotBlank(url)) {
if (url.startsWith("https://shop.m.suning.com/")) {//店铺页拼接url
String shopHtml = url.split("/")[3].split("\\.")[0];
String relShopHtml;
if (8 == shopHtml.length()) {
relShopHtml = "00" + shopHtml;
} else if (10 == shopHtml.length()) {
relShopHtml = shopHtml;
} else {
return null;
}
return "/pages/shop/index/index?shopId=" + relShopHtml;
} else if (url.contains("/pages/cuxiao/")) {//活动促销页-原生
return url;
} else if (url.contains("cuxiao.m.suning.com")) {//活动促销页-H5页面(泰坦)
return "/pages/webView/index?webViewSrc=" + url;
} else if (url.startsWith("https://m.suning.com/product/")) {//四级页
String shopId = url.split("/")[4];
String productId = url.split("/")[5].split("\\.")[0];
return "/pages/fourth/fourth?productId=" + productId + "&shop=" + shopId + "&title=";
}
}
return null;
}
/**
* 将url中参数封装成map
* @param url
* @return
*/
public static Map<String, String> getUrlMap(String url) {
Map<String, String> map = new HashMap<String, String>();
URL urls = null;
try {
urls = new URL(url);
String param = urls.getQuery();
if (StringUtils.isNotBlank(param)) {
String[] arr = param.split("&");
for (String s : arr) {
String key = s.split("=")[0];
String value = s.split("=")[1];
map.put(key, value);
}
}
} catch (MalformedURLException e) {
log.warn("getUrlMap", "MalformedURLException e={}" + e);
}
return map;
}
/**
* hashMap 转化成表单字符串
* @param map
* @return
*/
public static String map2Form(Map<String, String> map) {
StringBuilder stringBuilder = new StringBuilder();
if (map == null || map.size() == 0) {
return stringBuilder.toString();
} else {
for (Map.Entry<String, String> entry : map.entrySet()) {
stringBuilder.append(entry.getKey()).append("=").append(entry.getValue()).append("&");
}
return stringBuilder.substring(0, stringBuilder.length() - 1);
}
}
/**
* 表单字符串转化成 hashMap
*
* @param orderinfo
* @return
*/
public static HashMap<String, String> form2Map( String orderinfo) {
String listinfo[];
HashMap<String, String> map = new HashMap<String, String>();
listinfo = orderinfo.split("&");
for(String s : listinfo)
{
String list[] = s.split("=");
if(list.length>1)
{
map.put(list[0], list[1]);
}
}
return map;
}
}