问题描述:通过ip地址查询ip归属省市,只能到市一级。通常用于(防串货等业务)
1、导包
<dependency>
<groupId>com.github.jarod</groupId>
<artifactId>qqwry-java</artifactId>
<version>0.7.0</version>
</dependency>
2、service层代码实现 (我这里只需要市级,所以就把省级去掉了,根据自己的业务来哈)
public int insert(CarDto resources) throws IOException, GeoIp2Exception {
//1、获取前端传回来的参数
//1、获取ip
String address = resources.getIpAddress();
QQWry wry = new QQWry();
IPZone zone = wry.findIP(address);
String city = zone.getMainInfo().split("省")[1];
System.out.println(city);