diff --git a/jsowell-common/src/main/java/com/jsowell/common/util/StringUtils.java b/jsowell-common/src/main/java/com/jsowell/common/util/StringUtils.java index 8466d0acc..6b681a87d 100644 --- a/jsowell-common/src/main/java/com/jsowell/common/util/StringUtils.java +++ b/jsowell-common/src/main/java/com/jsowell/common/util/StringUtils.java @@ -227,6 +227,23 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils { return StringUtils.startsWithAny(link, Constants.HTTP, Constants.HTTPS); } + /** + * 去除http(s)://开头 + * @param link + * @return + */ + public static String removeHttp(String link) { + String result; + if (StringUtils.startsWith(link, Constants.HTTP)) { + result = link.replace(Constants.HTTP, ""); + } else if (StringUtils.startsWith(link, Constants.HTTPS)) { + result = link.replace(Constants.HTTPS, ""); + } else { + result = link; + } + return result; + } + /** * 字符串转set * diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/PileRemoteService.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/PileRemoteService.java index fccf99619..21f0de9ca 100644 --- a/jsowell-pile/src/main/java/com/jsowell/pile/service/PileRemoteService.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/PileRemoteService.java @@ -2,6 +2,7 @@ package com.jsowell.pile.service; import com.google.common.collect.Lists; import com.jsowell.common.constant.CacheConstants; +import com.jsowell.common.constant.Constants; import com.jsowell.common.core.redis.RedisCache; import com.jsowell.common.enums.ykc.ReturnCodeEnum; import com.jsowell.common.exception.BusinessException; @@ -223,7 +224,8 @@ public class PileRemoteService { String ip; try { - ip = InetAddress.getByName(serverAddress).getHostAddress(); + String server = StringUtils.removeHttp(serverAddress); + ip = InetAddress.getByName(server).getHostAddress(); } catch (UnknownHostException e) { throw new BusinessException("", "无法解析出IP"); } @@ -238,6 +240,32 @@ public class PileRemoteService { ykcPushCommandService.pushUpdateFileCommand(command); } + public static void main(String[] args) { + //获取百度IP地址 + try { + System.out.println("www.baidu.com的地址: "+InetAddress.getByName("www.baidu.com").getHostAddress()); + } catch (UnknownHostException e) { + throw new RuntimeException(e); + } + + //获取百度IP地址 + try { + System.out.println("jsowell的地址: "+InetAddress.getByName("apitest.jsowellcloud.com").getHostAddress()); + } catch (UnknownHostException e) { + throw new RuntimeException(e); + } + + String serverAddress = "http://apitest.jsowellcloud.com"; + String ip; + try { + String server = StringUtils.removeHttp(serverAddress);; + ip = InetAddress.getByName(server).getHostAddress(); + } catch (UnknownHostException e) { + throw new BusinessException("", "无法解析出IP"); + } + System.out.println("=====" + ip); + } + /** * 远程账户余额更新 */