parent
3681028b75
commit
d058de5e30
@ -1,56 +0,0 @@ |
||||
package com.hfkj.common.utils; |
||||
|
||||
import com.alibaba.fastjson.JSONObject; |
||||
import org.apache.http.HttpResponse; |
||||
import org.apache.http.util.EntityUtils; |
||||
|
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* 阿里云业务服务 |
||||
* @className: AliyunService |
||||
* @author: HuRui |
||||
* @date: 2024/4/3 |
||||
**/ |
||||
public class AliyunService { |
||||
|
||||
/** |
||||
* 查询ip地址 |
||||
* @param ip ip地址 |
||||
* @return |
||||
*/ |
||||
public static JSONObject queryAddress(String ip) { |
||||
try { |
||||
String host = "https://ipaddquery.market.alicloudapi.com"; |
||||
String path = "/ip/address-query"; |
||||
String method = "POST"; |
||||
String appcode = "f9ace4c915054ca697a76fb9a4e1e8c0"; |
||||
|
||||
Map<String, String> headers = new HashMap<>(); |
||||
headers.put("Authorization", "APPCODE " + appcode); |
||||
headers.put("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"); |
||||
|
||||
Map<String, String> bodys = new HashMap<>(); |
||||
bodys.put("ip", ip); |
||||
|
||||
HttpResponse response = HttpUtils.doPost(host, path, method, headers, new HashMap<>(), bodys); |
||||
JSONObject resObj = JSONObject.parseObject(EntityUtils.toString(response.getEntity())); |
||||
if (resObj.getString("code").equals("200")) { |
||||
return resObj.getJSONObject("data"); |
||||
} |
||||
return null; |
||||
|
||||
} catch (Exception e) { |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
public static void main(String[] args) { |
||||
try { |
||||
System.out.println(queryAddress("123.147.76.209")); |
||||
} catch (Exception e) { |
||||
e.printStackTrace(); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,28 @@ |
||||
package com.hfkj.common.utils; |
||||
|
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.hfkj.common.exception.ErrorCode; |
||||
import com.hfkj.common.exception.ErrorHelp; |
||||
import com.hfkj.common.exception.SysCode; |
||||
|
||||
/** |
||||
* 高德API服务 |
||||
* @className: AmapApiService |
||||
* @author: HuRui |
||||
* @date: 2024/6/28 |
||||
**/ |
||||
public class AmapApiService { |
||||
|
||||
/** |
||||
* 获取ip |
||||
*/ |
||||
public static JSONObject queryIp(String ip) { |
||||
JSONObject obj = HttpsUtils.doGet("https://restapi.amap.com/v3/ip?key=0083a5b1cc5289d7e9691424ee62136e&ip="+ip); |
||||
if (obj.getString("status").equals("1")) { |
||||
return obj; |
||||
} else { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, obj.getString("info")); |
||||
} |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue