依托北斗地基增强基站提供定位服务,根据精度不同分为:亚米级、厘米级、静态毫米级的位置监控,自己有一套后台原始数据系统,并对初始数据进行处理,形成新的服务,称之FindS(云踪)、FindS等等,同时支持开发平台有Android、IOS、Linux嵌入式、Web API。
a) 首先需要注册千寻的账号,有试用期,实名认证试用期会长一些。
b) 购买或者试用对应的服务
c) 激活服务实例
d) 获取对应的appkey 和 appScrete, 或者 sik和sis 接入千寻平台需要的
e) 下载千寻的开发的demo
3、 下面以千寻云踪FindS的WEB开发为例
Step1 : 进入千寻官网:https://www.qxwz.com/
Step2:注册或登录
Step3:跳过注册部分直接登录
Step 4:获取 sik 和sis
Step5:了解一下API概述
Step6:下载demo
Step7.这是开发就可以参考手册
实体管理:创建一个实体对象
位置管理:GPS位置相关数据
配置管理:主要是抽稀配置(也就是去掉部分数据换取性能)地理围栏配置(是否支持地理围栏)
事件管理:终端事件发生,例如共享单车的急刹车,急转弯
行程管理:骑行的过程,从开始到结束
地理围栏:划分一个GPS地理区域
规则引擎:配合规则引擎和消息通道使用,触发地理围栏需要自动做一些事情
消息通道:支持阿里云MNS
关系管理:将规则引擎和地理围栏与对应实体进行相应的关联
统计报表:统计一段时间内关于实体的相关的属性
a) 工程结构:
a) 代码展示:
pox.xml
4.0.0
com.jack
qianxun
0.0.1-SNAPSHOT
com.alibaba
fastjson
1.1.26
junit
junit
4.7
test
org.apache.httpcomponents
httpclient
4.3.5
org.apache.httpcomponents
httpcore
4.3.3
commons-logging
commons-logging
1.1.1
package com.jack.util;
public class Consts {
public final static String SIK = "你自己sik";
public final static String SIS = "你自己的sis";
public final static String QXWZURL = "http://openapi.qxwz.com";
}
package com.jack.util;
import java.nio.charset.Charset;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import org.apache.http.HttpEntity;
import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
public class Utils {
/**
* @param paramMap 参数列表(加签的时候需要进行字典序升序排序)
* @param apiName 访问的API接口名称
* @throws Exception
*/
public static void doWork(Map paramMap, String apiName) throws Exception {
String apiPath = "/rest/" + apiName + "/" + "sik" + "/"+Consts.SIK;// API路径,注意没有问号
// 毫秒级时间戳,一定是毫秒级!重要!!!
String timestamp = String.valueOf(System.currentTimeMillis());
String signatureStr = doHmacSHA2(apiPath, paramMap, Consts.SIS, timestamp);
System.out.println("加签值:"+signatureStr);//打印sign值
String qxwzUrl = "http://openapi.qxwz.com";//千寻的服务器地址
String queryUrl = qxwzUrl + apiPath + "?_sign=" + signatureStr;
System.out.println(queryUrl);
//发送http请求,获取返回值
doHttpPost(queryUrl,paramMap,timestamp);
}
public static void doHttpPost(String url,Map paramMap, String timestamp) throws Exception {
CloseableHttpClient httpClient = HttpClients.createDefault();
HttpPost httpPost = new HttpPost(url);
httpPost.setHeader("Accept-Encoding", "gzip, deflate");
httpPost.setHeader("wz-acs-timestamp", timestamp);//此处注意加上时间戳,否则http请求将无效
List nvps = new ArrayList();
for (Map.Entry entry : paramMap.entrySet()){
if (entry.getValue() == null) continue;
nvps.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
}
httpPost.setEntity(new UrlEncodedFormEntity(nvps, "UTF-8"));//处理中文编码的问题
System.out.println(httpPost.getEntity().toString());
try {
CloseableHttpResponse response = (CloseableHttpResponse) httpClient.execute(httpPost);
try {
HttpEntity entity = response.getEntity();
if (entity != null) {
System.out.println("返回值:"+EntityUtils.toString(entity));
/*
* 此处针对返回结果进行不同的处理
*/
EntityUtils.consume(entity);
}
} finally {
response.close();
}
} catch (Exception e) {
e.printStackTrace();
}finally {
if (httpPost != null) {
httpPost.releaseConnection();//释放资源
}
if(httpClient != null){
httpClient.close();//释放资源
}
}
}
/*
* 将字节数组转换成16进制字符串
* */
public static String encodeHexStr(final byte[] bytes){
if (bytes == null) {
return null;
}
char[] digital = "0123456789ABCDEF".toCharArray();
char[] result = new char[bytes.length * 2];
for (int i = 0; i < bytes.length; i++) {
result[i * 2] = digital[(bytes[i] & 0xf0) >> 4];
result[i * 2 + 1] = digital[bytes[i] & 0x0f];
}
return new String(result);
}
/*
* 加签算法
* */
public static String doHmacSHA2(String path, Map params, String key, String timestamp) {
List> parameters = new ArrayList>(params.entrySet());
SecretKeySpec signingKey = new SecretKeySpec(key.getBytes(), "HmacSHA256");
Charset CHARSET_UTF8 = Charset.forName("UTF-8");
Mac mac;
try {
mac = Mac.getInstance("HmacSHA256");
mac.init(signingKey);
} catch (NoSuchAlgorithmException e) {
throw new IllegalStateException(e.getMessage(), e);
} catch (InvalidKeyException e) {
throw new IllegalStateException(e.getMessage(), e);
}
if(path != null && path.length() > 0){
mac.update(path.getBytes(CHARSET_UTF8));
}
if(parameters != null){
Collections.sort(parameters, new MapEntryComparator());
for (Map.Entry parameter : parameters) {
byte[] name = parameter.getKey().getBytes(CHARSET_UTF8);
Object value = parameter.getValue();
if(value instanceof Collection){
for (Object o : (Collection)value){
mac.update(name);
if(o != null){
mac.update(o.toString().getBytes(CHARSET_UTF8));
}
}
}else{
mac.update(name);
if(value != null){
mac.update(value.toString().getBytes(CHARSET_UTF8));
}
}
}
}
if(timestamp != null && timestamp.length() > 0){
mac.update(timestamp.toString().getBytes(CHARSET_UTF8));
}
return encodeHexStr(mac.doFinal());
}
}
/*
* Map参数排序类
* */
class MapEntryComparator implements Comparator> {
public int compare(Entry o1, Entry o2) {
if (o1 == o2) {
return 0;
}
final String k1 = o1.getKey().toString();
final String k2 = o2.getKey().toString();
int l1 = k1.length();
int l2a = k2.length();
for (int i = 0; i < l1; i++) {
char c1 = k1.charAt(i);
char c2;
if (i < l2a) {
c2 = k2.charAt(i);
} else {
return 1;
}
if (c1 > c2) {
return 1;
} else if (c1 < c2) {
return -1;
}
}
if (l1 < l2a) {
return -1;
}else if(l1 == l2a) {
return 0;
}else {
return -1;
}
}
}
package com.jack.test;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.junit.Test;
import com.alibaba.fastjson.JSONObject;
import com.jack.test.entity.Entity;
import com.jack.util.Utils;
public class EntityManager {
Map paramMap = new HashMap();
/**
* 创建实体
* @throws Exception
*/
@Test
public void createEntity() throws Exception{
String API_NAME= "gpsp.entity.createEntity";
Entity entity = new Entity();
entity.setEntityName("yerewererw");
entity.setEntityType("奶制品");
Map attr = new HashMap();
attr.put("color", "白色");
attr.put("contain", "蛋白质");
entity.setAttributes(attr);
paramMap.put("entity",JSONObject.toJSONString(entity) );
Utils.doWork(paramMap, API_NAME);
}
/**
* 创建JT808实体
* @throws Exception
*/
@Test
public void createJT808Entity()throws Exception{
String API_NAME= "gpsp.jt808.entity.createEntity";
Entity entity = new Entity();
entity.setEntityName("大卡");
entity.setEntityType("湘A00110");
Map attr = new HashMap();
attr.put("qx_simCard", "1872451551");
attr.put("qx_terminalId", "01");
attr.put("qx_plateNumber", "湘A00110");
entity.setAttributes(attr);
paramMap.put("entity",JSONObject.toJSONString(entity) );
Utils.doWork(paramMap, API_NAME);
}
/**
* 删除实体
* @throws Exception
*/
@Test
public void deleteEntity() throws Exception{
String API_NAME= "gpsp.entity.deleteEntity";
paramMap.put("entityName","y" );
Utils.doWork(paramMap, API_NAME);
}
/**
* 更新实体
* @throws Exception
*/
@Test
public void updateEntity() throws Exception{
String API_NAME= "gpsp.entity.updateEntity";
Map attr = new HashMap();
attr.put("颜色", "白色");
attr.put("哈哈", "蛋白质");
System.out.println(JSONObject.toJSONString(attr) );
paramMap.put("attributes",JSONObject.toJSONString(attr) );
paramMap.put("entityName","阳" );
Utils.doWork(paramMap, API_NAME);
}
/**
* 查询单个实体
* @throws Exception
*/
@Test
public void queryEntity() throws Exception{
String API_NAME= "gpsp.entity.queryEntity";
paramMap.put("entityName","阳" );
Utils.doWork(paramMap, API_NAME);
}
/**
* 查询多个实体
* @throws Exception
*/
@Test
public void queryMoreEntity() throws Exception{
String API_NAME= "gpsp.entity.queryEntities";
List list = new ArrayList();
list.add("阳");
list.add("牛奶");
list.add("demo");
paramMap.put("entityNames",JSONObject.toJSONString(list) );
System.out.println(paramMap);
Utils.doWork(paramMap, API_NAME);
}
@Test
public void queryEntityList() throws Exception{
String API_NAME= "gpsp.entity.queryEntitiesByApp";
paramMap.put("pageNum", "1");
paramMap.put("pageSize", "10");
paramMap.put("returnType", "ALL");
Utils.doWork(paramMap, API_NAME);
}
@Test
public void queryEntityCount() throws Exception{
String API_NAME= "gpsp.entity.getCountByApp";
paramMap.put("type","ALL" );
Utils.doWork(paramMap, API_NAME);
}
}