如果您目前需要关于IP地理位置的查询服务,或者正在考虑选购、或者已经购买了本产品,希望可以通过这篇文档帮助您更多的了解产品,更快的使用服务。
产品选购指南
IP地址库目前有四款产品,每种产品均已包含国内IP(含港澳台)/国外IP
1、在线版ipv4
2、离线版ipv4
3、在线版ipv6
4、离线版ipv6
主要区别及对比:
在线版产品:
优点:价格超实惠,多种规格可选,使用方便,多语言支持,通过安装sdk,简单封装后即可立即使用
缺点:处于公网环境,从客户端到阿里网关容易受网络影响造成时延波动,QPS目前最多支持5000
离线版产品:
优点:不需要公网环境,可与外界完全隔离,无延迟,RT超低、QPS目前支持15万以上至无限
缺点:需要经常更新离线文件库,才能保持最新数据
离线版需要下载对应的授权文件、离线库、sdk,可通过集成sdk/http/rpc等方式使用,尤其适合公司内部有多个业务场景同时需要使用ip查询服务。
更多产品详情请查阅 产品简介
购买前测试产品数据准确率:

2、批量ip查询服务(免费),需要的请钉钉联系:behladu 获取帮助
在线版最低购买1个月且支持退款,离线版最低购买1年并且不支持退款,两种版本结果是一致的。
产品对接指南
1、购买产品
2、API对接常用参数(后文产品对接中会用到)
regionId目前仅支持cn-hangzhou节点,国外用户强烈不推荐使用在线版
3、API快速入门
4、API在线调试
产品使用指南
本部分主要介绍代码如何使用及演示,如果已经看过产品文档,已理解如何使用,可忽略以下文档。
1、IP地理位置库(在线版)对接指南
在线版服务支持用户调用阿里云API获取IP地理定位能力,在具体对接时,我们建议您通过集成阿里云开放平台SDK来调用服务(前往下载SDK)。
下文中以集成java版本阿里云SDK为例,演示如何对接在线版IP地理位置库服务:
(1)、使用idea开发工具创建Maven全新项目
(2)、添加jar包依赖,下载jar文件坐标
(3)、创建com.example包下的DescribeIpv4Online.java文件,填写AK信息(即前文提到的AccessKeyID、Secret)
package com.example;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.profile.DefaultProfile;
import com.google.gson.Gson;
import java.util.*;
import com.aliyuncs.geoip.model.v20200101.*;
public class DescribeIpv4Online {
public static void main(String[] args) {
DefaultProfile profile = DefaultProfile.getProfile(
"cn-hangzhou", //此处配置regionId(固定是cn-hangzhou)
"AccessKeyID",
"Secret"
);
IAcsClient client = new DefaultAcsClient(profile);
DescribeIpv4LocationRequest request = new DescribeIpv4LocationRequest();
request.setIp("221.206.131.10");
try {
DescribeIpv4LocationResponse response = client.getAcsResponse(request);
System.out.println(new Gson().toJson(response));
} catch (ServerException e) {
e.printStackTrace();
} catch (ClientException e) {
System.out.println("ErrCode:" + e.getErrCode());
System.out.println("ErrMsg:" + e.getErrMsg());
System.out.println("RequestId:" + e.getRequestId());
}
}
}
(4)、运行DescribeIpv4Online.java示例,在控制台得到以下结果
此时返回值是小驼峰格式,如果想返回标准API大驼峰格式可以使用以下代码代替,或者直接使用response.get**()方法返回具体值,不用考虑字段大小写。
HttpResponse httpResponse = client.doAction(request);
System.out.println("responseURL:\n" + new String(httpResponse.getHttpContent()));
2、IP地理位置库(离线版)对接指南
为了不发生混乱我们重新创建个Maven项目用于离线版的演示
离线版服务支持用户将加密IP库离线下载到本地,在本地搭建服务使用(前往下载离线SDK)。
购买开通服务后可以在控制台下载文件/API调用(详情参考离线升级文档)得到以下三个文件
.lic为授权文件
.dex为离线库文件
离线SDK文件(选择需要的开发语言版本即可,下文以java版本为例演示对接)
例如:
下文基于以上3个文件(SDK以java版本做演示),开始演示如何使用。
普通sdk方式:
(1)、复制jar文件到项目中,文件位置可自行设置,并添加引用
File > Project Structure > Modules > Dependencies > + > JARs or directories
添加commons-lang3、guava、commons-codec、fastjson、slf4j-api的Maven坐标并下载
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>untitled1</artifactId>
<version>1.0-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.5.RELEASE</version>
</parent>
<properties>
<java.version>1.8</java.version>
</properties>
<repositories>
<repository>
<id>sonatype-nexus-staging</id>
<name>Sonatype Nexus Staging</name>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.10</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>28.2-jre</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.11</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.68</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.26</version>
</dependency>
</dependencies>
</project>
(2)、创建com.example.DescribeIpv4Offline.java,配置授权文件和离线库文件访问路径
package com.example;
import com.alibaba.sec.client.FastIPGeoClient;
import com.alibaba.sec.domain.FastGeoConf;
import com.alibaba.sec.exception.FastIPGeoException;
import com.alibaba.sec.license.exception.LicenseException;
import org.springframework.stereotype.Service;
@Service
public class DescribeIpv4Offline {
private static final String DATA_FILE_PATH = "v1.20201013183640.dex";
private static final String LICENSE_FILE_PATH = "v1.20201013183640.lic";
public static void main(String[] args) throws Exception {
FastGeoConf geoConf = new FastGeoConf();
geoConf.setDataFilePath(DATA_FILE_PATH);
geoConf.setLicenseFilePath(LICENSE_FILE_PATH);
//普通对象方式
//FastIPGeoClient fastIpGeoClient = new FastIPGeoClient(geoConf);
//单例模式
FastIPGeoClient fastIpGeoClient = FastIPGeoClient.getSingleton(geoConf);
String result = null;
try {
result = fastIpGeoClient.search("221.206.131.10");
System.out.println(result);
} catch (LicenseException | FastIPGeoException e) {
e.printStackTrace();
}
}
}
运行DescribeIpv4Offline.java示例,在控制台得到以下结果
SpringBoot方式:
使用idea的JBLSpringBootAppGen插件创建启动引导类
(1)、创建com.example.service.GeoipService,配置授权文件和离线库文件访问路径
package com.example.service;
import com.alibaba.sec.client.FastIPGeoClient;
import com.alibaba.sec.domain.FastGeoConf;
import com.alibaba.sec.exception.FastIPGeoException;
import com.alibaba.sec.license.exception.LicenseException;
import org.springframework.stereotype.Service;
@Service
public class GeoipService {
private static final String DATA_FILE_PATH = "v1.20201013183640.dex";
private static final String LICENSE_FILE_PATH = "v1.20201013183640.lic";
private FastIPGeoClient fastIPGeoClient;
@PostConstruct
public void init() throws Exception {
FastGeoConf geoConf = new FastGeoConf();
geoConf.setDataFilePath(DATA_FILE_PATH);
geoConf.setLicenseFilePath(LICENSE_FILE_PATH);
//普通对象
//FastIPGeoClient fastIpGeoClient = new FastIPGeoClient(geoConf);
//单例模式
fastIPGeoClient = FastIPGeoClient.getSingleton(geoConf);
}
public String searchIpv4(String ip) throws Exception {
String result = null;
try {
result = fastIpGeoClient.search(ip);
} catch (LicenseException | FastIPGeoException e) {
e.printStackTrace();
}
return result;
}
}
(2)、创建com.example.controller.GeoipController.java
package com.example.controller;
import com.example.service.GeoipService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/http")
public class GeoipController {
@Autowired
private GeoipService geoipService;
@GetMapping("/offline/ipv4/{ip}")
public String offline(@PathVariable String ip) throws Exception {
return geoipService.searchIpv4(ip);
}
}
离线版项目结构参考
(3)、启动SpringBoot项目,在浏览器访问
http://127.0.0.1:8080/http/offline/ipv4/221.206.131.10

在文档使用中是否遇到以下问题
更多建议
匿名提交