GPS对接
parent
33b10ec846
commit
ab9935ab8a
|
|
@ -13,7 +13,7 @@ import java.time.Duration;
|
|||
@Getter
|
||||
@Setter
|
||||
@Accessors(chain = true)
|
||||
@ConfigurationProperties("okhttp-client")
|
||||
@ConfigurationProperties("http-client")
|
||||
public class HttpClientProperties {
|
||||
|
||||
public static final HttpClientProperties DEFAULT = new HttpClientProperties();
|
||||
|
|
|
|||
|
|
@ -25,22 +25,20 @@ public class CompositeInterceptor implements RequestInterceptor, ResponseInterce
|
|||
|
||||
@Override
|
||||
public Object process(RequestInfo requestInfo, ResponseInfo responseInfo, Type responseType) {
|
||||
System.out.println(Jackson.toJsonStr(requestInfo));
|
||||
System.out.println(new String(requestInfo.body));
|
||||
log.info("响应拦截器: {}、{}、{}", Jackson.toJsonStr(requestInfo), new String(responseInfo.body), responseType);
|
||||
Object data = null;
|
||||
|
||||
Object data = new String(responseInfo.body);
|
||||
|
||||
/* if (responseInfo.success) {
|
||||
if (responseInfo.success) {
|
||||
if (responseInfo.body != null) {
|
||||
data = Jackson.toBean(responseInfo.body, responseType);
|
||||
log.info("Jackson: {}", JSON.toJSONString(data));
|
||||
data = JSON.parseObject(responseInfo.body, responseType);
|
||||
log.info("Fastjson: {}", JSON.toJSONString(data));
|
||||
if (responseType == String.class) {
|
||||
data = new String(responseInfo.body);
|
||||
} else {
|
||||
data = Jackson.toBean(responseInfo.body, responseType);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
log.error("HTTP请求失败");
|
||||
} */
|
||||
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,6 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties
|
|||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
@EnableConfigurationProperties(AppProperties.class)
|
||||
@EnableConfigurationProperties({AppProperties.class, JimiProperties.class})
|
||||
public class AppConfiguration {
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,19 +1,20 @@
|
|||
package com.njzscloud.common.core.http;
|
||||
package com.njzscloud.supervisory.config;
|
||||
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import com.njzscloud.common.core.http.HttpClient;
|
||||
import com.njzscloud.common.core.http.HttpClientDecorator;
|
||||
import com.njzscloud.common.core.http.HttpClientProperties;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
*
|
||||
* http客户端自动配置
|
||||
*/
|
||||
@Configuration
|
||||
@EnableConfigurationProperties(HttpClientProperties.class)
|
||||
public class HttpClientAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public HttpClient httpClient(HttpClientProperties httpClientProperties) {
|
||||
return new HttpClient(httpClientProperties);
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
package com.njzscloud.supervisory.config;
|
||||
|
||||
import com.njzscloud.common.core.http.HttpClientDecorator;
|
||||
import com.njzscloud.supervisory.gps.tuqiang.jimi.support.JimiApi;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
@ConditionalOnBean(HttpClientDecorator.class)
|
||||
public class JimiApiAutoConfiguration {
|
||||
@Bean
|
||||
public JimiApi jimiApi(HttpClientDecorator httpClientDecorator) {
|
||||
return httpClientDecorator.decorate(JimiApi.class);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
package com.njzscloud.supervisory.config;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@Accessors(chain = true)
|
||||
@ConfigurationProperties("app.jimi")
|
||||
public class JimiProperties {
|
||||
/**
|
||||
* 应用ID
|
||||
*/
|
||||
private String appKey;
|
||||
/**
|
||||
* 应用密钥
|
||||
*/
|
||||
private String appSecret;
|
||||
/**
|
||||
* 用户ID
|
||||
*/
|
||||
private String userId;
|
||||
/**
|
||||
* 密码
|
||||
*/
|
||||
private String pwd;
|
||||
/**
|
||||
* 过期时间
|
||||
*/
|
||||
private Integer expires = 7200;
|
||||
}
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
package com.njzscloud.supervisory.gps.controller;
|
||||
|
||||
import com.njzscloud.common.core.utils.R;
|
||||
import com.njzscloud.supervisory.gps.tuqiang.jimi.DeviceLocationGetParam;
|
||||
import com.njzscloud.supervisory.gps.tuqiang.jimi.DeviceLocationGetResult;
|
||||
import com.njzscloud.supervisory.gps.tuqiang.jimi.DeviceTrackListParam;
|
||||
import com.njzscloud.supervisory.gps.tuqiang.jimi.DeviceTrackListResult;
|
||||
import com.njzscloud.supervisory.gps.tuqiang.jimi.util.JimiUtil;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* GPS
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/gps")
|
||||
public class GPSController {
|
||||
/**
|
||||
* 实时定位
|
||||
*/
|
||||
@RequestMapping("/obtain_location")
|
||||
public R<?> obtainLocation(DeviceLocationGetParam param) {
|
||||
DeviceLocationGetResult result = JimiUtil.request(param);
|
||||
if (result.isSucc()) {
|
||||
return R.success(result.getResult());
|
||||
}
|
||||
return R.failed();
|
||||
}
|
||||
|
||||
/**
|
||||
* 轨迹查询
|
||||
*/
|
||||
@RequestMapping("/track_list")
|
||||
public R<?> trackList(DeviceTrackListParam param) {
|
||||
DeviceTrackListResult result = JimiUtil.request(param);
|
||||
if (result.isSucc()) {
|
||||
return R.success(result.getResult());
|
||||
}
|
||||
return R.failed();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
package com.njzscloud.supervisory.gps.tuqiang.jimi;
|
||||
|
||||
import com.njzscloud.supervisory.gps.tuqiang.jimi.support.JimiParam;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* 根据IMEI获取最新定位数据
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@Accessors(chain = true)
|
||||
public class DeviceLocationGetParam extends JimiParam<DeviceLocationGetResult> {
|
||||
/**
|
||||
* 设备imei号,多个中间用英文逗号隔开。 如果设备过多,建议采用POST方式(一次最多100个IMEI)
|
||||
*/
|
||||
private String imeis;
|
||||
/**
|
||||
* 如果要显示在百度地图上,map_type=BAIDU此时返回的经纬度将经过baidu校准方式校准
|
||||
* 如果要显示在google地图上,map_type=GOOGLE,此时返回的经纬度将经过google校准方式校准
|
||||
* map_type如果不填,则返回原始经纬度
|
||||
*/
|
||||
private String map_type;
|
||||
|
||||
public DeviceLocationGetParam() {
|
||||
super("jimi.device.location.get");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<DeviceLocationGetResult> resultType() {
|
||||
return DeviceLocationGetResult.class;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,113 @@
|
|||
package com.njzscloud.supervisory.gps.tuqiang.jimi;
|
||||
|
||||
import com.njzscloud.supervisory.gps.tuqiang.jimi.support.JimiResult;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@Accessors(chain = true)
|
||||
public class DeviceLocationGetResult extends JimiResult {
|
||||
private List<Result> result;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@Accessors(chain = true)
|
||||
public static class Result {
|
||||
/**
|
||||
* 设备IMEI
|
||||
*/
|
||||
private String imei;
|
||||
|
||||
/**
|
||||
* 设备名称
|
||||
*/
|
||||
private String deviceName;
|
||||
|
||||
/**
|
||||
* 车辆图标
|
||||
*/
|
||||
private String icon;
|
||||
|
||||
/**
|
||||
* 设备状态 0-离线; 1-在线
|
||||
*/
|
||||
private String status;
|
||||
|
||||
/**
|
||||
* 经度 (如果设备过期,值为0)
|
||||
*/
|
||||
private Double lng;
|
||||
|
||||
/**
|
||||
* 纬度 (如果设备过期,值为0)
|
||||
*/
|
||||
private Double lat;
|
||||
|
||||
/**
|
||||
* 是否过期 1-未过期 0-过期
|
||||
*/
|
||||
private String expireFlag;
|
||||
|
||||
/**
|
||||
* 是否激活 1-激活 0-未激活
|
||||
*/
|
||||
private String activationFlag;
|
||||
|
||||
/**
|
||||
* 定位类型 卫星定位-GPS, 基站定位-LBS, WIFI定位-WIFI, 蓝牙定位-BEACON
|
||||
*/
|
||||
private String posType;
|
||||
|
||||
/**
|
||||
* GPS定位时间
|
||||
*/
|
||||
private String gpsTime;
|
||||
|
||||
/**
|
||||
* 心跳时间 UTC秒数(如果设备过期,值为0)
|
||||
*/
|
||||
private String hbTime;
|
||||
|
||||
/**
|
||||
* 速度 (单位:km/h)
|
||||
*/
|
||||
private String speed;
|
||||
|
||||
/**
|
||||
* Acc状态 0:关闭 1:打开
|
||||
*/
|
||||
private String accStatus;
|
||||
|
||||
/**
|
||||
* 设备电量(0-100),部分设备型号不支持
|
||||
*/
|
||||
private String electQuantity;
|
||||
|
||||
/**
|
||||
* 外电电压(0-100),部分设备支持
|
||||
*/
|
||||
private String powerValue;
|
||||
|
||||
/**
|
||||
* 参与定位卫星数
|
||||
*/
|
||||
private String gpsNum;
|
||||
|
||||
/**
|
||||
* 移动的方向角度0~360
|
||||
*/
|
||||
private String direction;
|
||||
|
||||
/**
|
||||
* 里程统计
|
||||
*/
|
||||
private String mileage;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
package com.njzscloud.supervisory.gps.tuqiang.jimi;
|
||||
|
||||
import com.njzscloud.supervisory.gps.tuqiang.jimi.support.JimiParam;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* 根据IMEI获取轨迹数据
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@Accessors(chain = true)
|
||||
public class DeviceTrackListParam extends JimiParam<DeviceTrackListResult> {
|
||||
/**
|
||||
* 设备imei号(一次只能一个IMEI)
|
||||
*/
|
||||
private String imei;
|
||||
/**
|
||||
* 开始时间,格式为yyyy-MM-dd HH:mm:ss
|
||||
*/
|
||||
private String begin_time;
|
||||
/**
|
||||
* 结束时间,格式为yyyy-MM-dd HH:mm:ss
|
||||
* end_time不应大于当前时间。
|
||||
*/
|
||||
private String end_time;
|
||||
/**
|
||||
* 如果要显示在百度地图上,map_type=BAIDU此时返回的经纬度将经过baidu校准方式校准
|
||||
* 如果要显示在google地图上,map_type=GOOGLE,此时返回的经纬度将经过google校准方式校准
|
||||
* map_type如果不填,则返回原始经纬度
|
||||
*/
|
||||
private String map_type;
|
||||
|
||||
public DeviceTrackListParam() {
|
||||
super("jimi.device.track.list");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<DeviceTrackListResult> resultType() {
|
||||
return DeviceTrackListResult.class;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
package com.njzscloud.supervisory.gps.tuqiang.jimi;
|
||||
|
||||
import com.njzscloud.supervisory.gps.tuqiang.jimi.support.JimiResult;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@Accessors(chain = true)
|
||||
public class DeviceTrackListResult extends JimiResult {
|
||||
private List<Result> result;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@Accessors(chain = true)
|
||||
public static class Result {
|
||||
/**
|
||||
* 经度
|
||||
*/
|
||||
private String lng;
|
||||
/**
|
||||
* 纬度
|
||||
*/
|
||||
private Integer lat;
|
||||
/**
|
||||
* gps定位时间 格式yyyy-MM-dd HH:mm:ss
|
||||
*/
|
||||
private String gpsTime;
|
||||
/**
|
||||
* 方位,正北开始的一个360度的极坐标方向
|
||||
*/
|
||||
private String direction;
|
||||
/**
|
||||
* GPS速度
|
||||
*/
|
||||
private String gpsSpeed;
|
||||
/**
|
||||
* 定位类型1是卫星定位 2是基站定位 3是wifi定位
|
||||
*/
|
||||
private String posType;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
package com.njzscloud.supervisory.gps.tuqiang.jimi;
|
||||
|
||||
import cn.hutool.crypto.digest.DigestUtil;
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import com.njzscloud.supervisory.config.JimiProperties;
|
||||
import com.njzscloud.supervisory.gps.tuqiang.jimi.support.JimiParam;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* 获取access_token
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@Accessors(chain = true)
|
||||
public class OauthTokenGetParam extends JimiParam<OauthTokenGetResult> {
|
||||
private String user_id;
|
||||
private String user_pwd_md5;
|
||||
private String expires_in;
|
||||
|
||||
public OauthTokenGetParam() {
|
||||
super("jimi.oauth.token.get");
|
||||
JimiProperties jimiProperties = SpringUtil.getBean(JimiProperties.class);
|
||||
this.user_id = jimiProperties.getUserId();
|
||||
this.user_pwd_md5 = DigestUtil.md5Hex(jimiProperties.getPwd());
|
||||
this.expires_in = jimiProperties.getExpires().toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<OauthTokenGetResult> resultType() {
|
||||
return OauthTokenGetResult.class;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
package com.njzscloud.supervisory.gps.tuqiang.jimi;
|
||||
|
||||
|
||||
import com.njzscloud.supervisory.gps.tuqiang.jimi.support.JimiResult;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@Accessors(chain = true)
|
||||
public class OauthTokenGetResult extends JimiResult {
|
||||
private Result result;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@Accessors(chain = true)
|
||||
public static class Result {
|
||||
/**
|
||||
* 后续接口访问的访问令牌,对应到公司下的帐号
|
||||
*/
|
||||
private String accessToken;
|
||||
/**
|
||||
* 有效期
|
||||
*/
|
||||
private Integer expiresIn;
|
||||
/**
|
||||
* 请求的账号
|
||||
*/
|
||||
private String account;
|
||||
/**
|
||||
* 几米分给给客户的APP_KEY
|
||||
*/
|
||||
private String appKey;
|
||||
/**
|
||||
* 刷新令牌,用于更新accessToken
|
||||
*/
|
||||
private String refreshToken;
|
||||
/**
|
||||
* 令牌生成的时间
|
||||
*/
|
||||
private String time;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
package com.njzscloud.supervisory.gps.tuqiang.jimi;
|
||||
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import com.njzscloud.supervisory.config.JimiProperties;
|
||||
import com.njzscloud.supervisory.gps.tuqiang.jimi.support.JimiParam;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* 刷新access_token
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@Accessors(chain = true)
|
||||
public class OauthTokenRefreshParam extends JimiParam<OauthTokenRefreshResult> {
|
||||
private String access_token;
|
||||
private String refresh_token;
|
||||
private String expires_in;
|
||||
|
||||
public OauthTokenRefreshParam() {
|
||||
super("jimi.oauth.token.refresh");
|
||||
JimiProperties jimiProperties = SpringUtil.getBean(JimiProperties.class);
|
||||
this.expires_in = jimiProperties.getExpires().toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<OauthTokenRefreshResult> resultType() {
|
||||
return OauthTokenRefreshResult.class;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
package com.njzscloud.supervisory.gps.tuqiang.jimi;
|
||||
|
||||
import com.njzscloud.supervisory.gps.tuqiang.jimi.support.JimiResult;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@Accessors(chain = true)
|
||||
public class OauthTokenRefreshResult extends JimiResult {
|
||||
|
||||
private Result result;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@Accessors(chain = true)
|
||||
public static class Result {
|
||||
/**
|
||||
* 后续接口访问的访问令牌,对应到公司下的帐号
|
||||
*/
|
||||
private String accessToken;
|
||||
/**
|
||||
* 有效期
|
||||
*/
|
||||
private Integer expiresIn;
|
||||
/**
|
||||
* 请求的账号
|
||||
*/
|
||||
private String account;
|
||||
/**
|
||||
* 几米分给给客户的APP_KEY
|
||||
*/
|
||||
private String appKey;
|
||||
/**
|
||||
* 刷新令牌,用于更新accessToken
|
||||
*/
|
||||
private String refreshToken;
|
||||
/**
|
||||
* 令牌生成的时间
|
||||
*/
|
||||
private String time;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
package com.njzscloud.supervisory.gps.tuqiang.jimi;
|
||||
|
||||
import com.njzscloud.supervisory.gps.tuqiang.jimi.support.JimiParam;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* 获取单个或多个设备的详细信息
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@Accessors(chain = true)
|
||||
public class OpenDeviceGetDetailsParam extends JimiParam<OpenDeviceGetDetailsResult> {
|
||||
|
||||
/**
|
||||
* 设备imei号,多个中间用英文逗号隔开; 如果设备过多,建议采用POST方式(一次最多100个IMEI)
|
||||
*/
|
||||
private String imeis;
|
||||
|
||||
public OpenDeviceGetDetailsParam() {
|
||||
super("jimi.open.device.getDetails");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<OpenDeviceGetDetailsResult> resultType() {
|
||||
return OpenDeviceGetDetailsResult.class;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,168 @@
|
|||
package com.njzscloud.supervisory.gps.tuqiang.jimi;
|
||||
|
||||
import com.njzscloud.supervisory.gps.tuqiang.jimi.support.JimiResult;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@Accessors(chain = true)
|
||||
public class OpenDeviceGetDetailsResult extends JimiResult {
|
||||
private List<Result> result;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@Accessors(chain = true)
|
||||
public static class Result {
|
||||
/**
|
||||
* 设备IMEI
|
||||
*/
|
||||
private String imei;
|
||||
|
||||
/**
|
||||
* 设备名称
|
||||
*/
|
||||
private String deviceName;
|
||||
|
||||
/**
|
||||
* 所属用户账号
|
||||
*/
|
||||
private String account;
|
||||
|
||||
/**
|
||||
* 激活时间
|
||||
*/
|
||||
private String activationTime;
|
||||
|
||||
/**
|
||||
* 过期时间
|
||||
*/
|
||||
private String expiration;
|
||||
|
||||
/**
|
||||
* 机型
|
||||
*/
|
||||
private String mcType;
|
||||
|
||||
/**
|
||||
* 卡号
|
||||
*/
|
||||
private String sim;
|
||||
|
||||
/**
|
||||
* 绑定用户账号
|
||||
*/
|
||||
private String bindUserAccount;
|
||||
|
||||
/**
|
||||
* 状态 NORMAL-开机 DISABLE-停机
|
||||
*/
|
||||
private String status;
|
||||
|
||||
/**
|
||||
* 电话
|
||||
*/
|
||||
private String driverPhone;
|
||||
|
||||
/**
|
||||
* 车辆图标
|
||||
*/
|
||||
private String vehicleIcon;
|
||||
|
||||
/**
|
||||
* 设备类型(WIRED:有线 WIRELESS:无线)
|
||||
*/
|
||||
private String equipType;
|
||||
|
||||
/**
|
||||
* 机型使用范围(aotomobile:汽车 electromobile:电动车 personal:个人 pet:宠物 plane:飞机 others:其他)
|
||||
*/
|
||||
private String mcTypeUseScope;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String reMark;
|
||||
|
||||
/**
|
||||
* 箱号
|
||||
*/
|
||||
private String sn;
|
||||
|
||||
/**
|
||||
* 车辆名称
|
||||
*/
|
||||
private String vehicleName;
|
||||
|
||||
/**
|
||||
* 车牌号
|
||||
*/
|
||||
private String vehicleNumber;
|
||||
|
||||
/**
|
||||
* 车辆品牌
|
||||
*/
|
||||
private String vehicleModels;
|
||||
|
||||
/**
|
||||
* 车架号
|
||||
*/
|
||||
private String carFrame;
|
||||
|
||||
/**
|
||||
* 司机名
|
||||
*/
|
||||
private String driverName;
|
||||
|
||||
/**
|
||||
* 身份证
|
||||
*/
|
||||
private String idCard;
|
||||
|
||||
/**
|
||||
* 发动机号
|
||||
*/
|
||||
private String engineNumber;
|
||||
|
||||
/**
|
||||
* 安装时间
|
||||
*/
|
||||
private String installTime;
|
||||
|
||||
/**
|
||||
* 安装地址
|
||||
*/
|
||||
private String installAddress;
|
||||
|
||||
/**
|
||||
* 安装公司
|
||||
*/
|
||||
private String installCompany;
|
||||
|
||||
/**
|
||||
* 安装位置
|
||||
*/
|
||||
private String installPosition;
|
||||
|
||||
/**
|
||||
* 安装人员
|
||||
*/
|
||||
private String installPersonnel;
|
||||
|
||||
/**
|
||||
* 安装图片
|
||||
*/
|
||||
private String installImage;
|
||||
|
||||
/**
|
||||
* 业务员
|
||||
*/
|
||||
private String salesMan;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,65 @@
|
|||
package com.njzscloud.supervisory.gps.tuqiang.jimi;
|
||||
|
||||
import com.njzscloud.supervisory.gps.tuqiang.jimi.support.JimiParam;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* 提供通过设备imei号更改车辆信息。
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@Accessors(chain = true)
|
||||
public class OpenDeviceUpdateParam extends JimiParam<DeviceLocationGetResult> {
|
||||
/**
|
||||
* 设备imei号
|
||||
*/
|
||||
private String imei;
|
||||
|
||||
/**
|
||||
* 设备名称
|
||||
*/
|
||||
private String device_name;
|
||||
|
||||
/**
|
||||
* 车辆名称
|
||||
*/
|
||||
private String vehicle_name;
|
||||
|
||||
/**
|
||||
* 车辆图标
|
||||
*/
|
||||
private String vehicle_icon;
|
||||
|
||||
/**
|
||||
* 车牌号
|
||||
*/
|
||||
private String vehicle_number;
|
||||
|
||||
/**
|
||||
* 车辆品牌
|
||||
*/
|
||||
private String vehicle_models;
|
||||
|
||||
/**
|
||||
* 司机名称
|
||||
*/
|
||||
private String driver_name;
|
||||
|
||||
/**
|
||||
* 司机电话
|
||||
*/
|
||||
private String driver_phone;
|
||||
|
||||
public OpenDeviceUpdateParam() {
|
||||
super("jimi.open.device.update");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<DeviceLocationGetResult> resultType() {
|
||||
return DeviceLocationGetResult.class;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
package com.njzscloud.supervisory.gps.tuqiang.jimi;
|
||||
|
||||
import com.njzscloud.supervisory.gps.tuqiang.jimi.support.JimiResult;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@Accessors(chain = true)
|
||||
public class OpenDeviceUpdateResult extends JimiResult {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
package com.njzscloud.supervisory.gps.tuqiang.jimi.support;
|
||||
|
||||
import com.njzscloud.common.core.http.annotation.FormBodyParam;
|
||||
import com.njzscloud.common.core.http.annotation.PostEndpoint;
|
||||
import com.njzscloud.common.core.http.annotation.RemoteServer;
|
||||
|
||||
@RemoteServer(value = "http://open.aichezaixian.com/route/rest", requestInterceptor = JimiRequestInterceptor.class)
|
||||
public interface JimiApi {
|
||||
|
||||
@PostEndpoint
|
||||
<T> T doRequest(@FormBodyParam JimiParam<T> jimiParam);
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
package com.njzscloud.supervisory.gps.tuqiang.jimi.support;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@Accessors(chain = true)
|
||||
public abstract class JimiParam<T> {
|
||||
private String method;
|
||||
private String timestamp;
|
||||
private String app_key;
|
||||
private String sign;
|
||||
private String sign_method;
|
||||
private String v;
|
||||
private String format;
|
||||
private String access_token;
|
||||
|
||||
public JimiParam(String method) {
|
||||
this.method = method;
|
||||
this.timestamp = DateUtil.now();
|
||||
this.sign_method = "md5";
|
||||
this.v = "1.0";
|
||||
this.format = "json";
|
||||
}
|
||||
|
||||
public abstract Class<T> resultType();
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
package com.njzscloud.supervisory.gps.tuqiang.jimi.support;
|
||||
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import com.njzscloud.common.core.http.constant.HttpMethod;
|
||||
import com.njzscloud.common.core.http.interceptor.RequestInterceptor;
|
||||
import com.njzscloud.supervisory.config.JimiProperties;
|
||||
|
||||
public class JimiRequestInterceptor implements RequestInterceptor {
|
||||
private final String appKey;
|
||||
private final String appSecret;
|
||||
|
||||
public JimiRequestInterceptor() {
|
||||
JimiProperties jimiProperties = SpringUtil.getBean(JimiProperties.class);
|
||||
this.appSecret = jimiProperties.getAppSecret();
|
||||
this.appKey = jimiProperties.getAppKey();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] process(HttpMethod method, String url, Object[] args) {
|
||||
if (args == null || args.length == 0) {
|
||||
return args;
|
||||
}
|
||||
if (JimiParam.class.isAssignableFrom(args[0].getClass())) {
|
||||
JimiParam jimiParam = (JimiParam) args[0];
|
||||
jimiParam.setApp_key(appKey);
|
||||
String sign = JimiSignUtil.sign(jimiParam, appSecret, jimiParam.getSign_method());
|
||||
jimiParam.setSign(sign);
|
||||
}
|
||||
return args;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
package com.njzscloud.supervisory.gps.tuqiang.jimi.support;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@Accessors(chain = true)
|
||||
public class JimiResult {
|
||||
private Integer code;
|
||||
private String message;
|
||||
|
||||
public boolean isSucc() {
|
||||
return code == 0;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,108 @@
|
|||
package com.njzscloud.supervisory.gps.tuqiang.jimi.support;
|
||||
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.util.ReflectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import javax.crypto.Mac;
|
||||
import javax.crypto.SecretKey;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
|
||||
@Slf4j
|
||||
public class JimiSignUtil {
|
||||
public static String sign(Object data, String secret, String signMethod) {
|
||||
Map<String, String> params = MapUtil.newHashMap();
|
||||
|
||||
Field[] fields = ReflectUtil.getFields(data.getClass());
|
||||
for (Field field : fields) {
|
||||
field.setAccessible(true);
|
||||
try {
|
||||
Object o = field.get(data);
|
||||
params.put(field.getName(), o == null ? null : o.toString());
|
||||
} catch (IllegalAccessException e) {
|
||||
log.error("sign error", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 第一步:检查参数是否已经排序
|
||||
String[] keys = params.keySet().toArray(new String[0]);
|
||||
Arrays.sort(keys);
|
||||
|
||||
// 第二步:把所有参数名和参数值串在一起
|
||||
StringBuilder query = new StringBuilder();
|
||||
if ("md5".equals(signMethod)) {
|
||||
query.append(secret);
|
||||
}
|
||||
for (String key : keys) {
|
||||
String value = params.get(key);
|
||||
if (StrUtil.isNotBlank(key) && StrUtil.isNotBlank(value)) {
|
||||
query.append(key).append(value);
|
||||
}
|
||||
}
|
||||
|
||||
// 第三步:使用MD5/HMAC加密
|
||||
byte[] bytes;
|
||||
if ("hmac".equals(signMethod)) {
|
||||
bytes = encryptHMAC(query.toString(), secret);
|
||||
} else {
|
||||
query.append(secret);
|
||||
bytes = encryptMD5(query.toString());
|
||||
}
|
||||
|
||||
// 第四步:把二进制转化为大写的十六进制
|
||||
return byte2hex(bytes);
|
||||
}
|
||||
|
||||
public static byte[] encryptHMAC(String data, String secret) {
|
||||
byte[] bytes = null;
|
||||
try {
|
||||
SecretKey secretKey = new SecretKeySpec(secret.getBytes("UTF-8"), "HmacMD5");
|
||||
Mac mac = Mac.getInstance(secretKey.getAlgorithm());
|
||||
mac.init(secretKey);
|
||||
bytes = mac.doFinal(data.getBytes("UTF-8"));
|
||||
} catch (Exception gse) {
|
||||
log.error("encrypt HMAC error", gse);
|
||||
throw new RuntimeException(gse);
|
||||
}
|
||||
return bytes;
|
||||
}
|
||||
|
||||
public static byte[] encryptMD5(String data) {
|
||||
try {
|
||||
return encryptMD5(data.getBytes("UTF-8"));
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private static byte[] encryptMD5(byte[] bytes) {
|
||||
MessageDigest md = null;
|
||||
try {
|
||||
md = MessageDigest.getInstance("MD5");
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return md.digest(bytes);
|
||||
}
|
||||
|
||||
public static String byte2hex(byte[] bytes) {
|
||||
StringBuilder sign = new StringBuilder();
|
||||
for (int i = 0; i < bytes.length; i++) {
|
||||
String hex = Integer.toHexString(bytes[i] & 0xFF);
|
||||
if (hex.length() == 1) {
|
||||
sign.append("0");
|
||||
}
|
||||
sign.append(hex.toUpperCase());
|
||||
}
|
||||
return sign.toString();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
package com.njzscloud.supervisory.gps.tuqiang.jimi.util;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import com.njzscloud.supervisory.gps.tuqiang.jimi.OauthTokenGetParam;
|
||||
import com.njzscloud.supervisory.gps.tuqiang.jimi.OauthTokenGetResult;
|
||||
import com.njzscloud.supervisory.gps.tuqiang.jimi.OauthTokenRefreshParam;
|
||||
import com.njzscloud.supervisory.gps.tuqiang.jimi.OauthTokenRefreshResult;
|
||||
import com.njzscloud.supervisory.gps.tuqiang.jimi.support.JimiApi;
|
||||
import com.njzscloud.supervisory.gps.tuqiang.jimi.support.JimiParam;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class JimiUtil {
|
||||
private static final JimiApi API = SpringUtil.getBean(JimiApi.class);
|
||||
|
||||
private static String accessToken = "";
|
||||
private static String refreshToken = "";
|
||||
private static long tokenCreateTime = 0;
|
||||
|
||||
public static <T> T request(JimiParam<T> jimiParam) {
|
||||
auth();
|
||||
jimiParam.setAccess_token(accessToken);
|
||||
return API.doRequest(jimiParam);
|
||||
}
|
||||
|
||||
private static void auth() {
|
||||
if (tokenCreateTime == 0) {
|
||||
OauthTokenGetResult oauthTokenGetResult = API.doRequest(new OauthTokenGetParam());
|
||||
if (!oauthTokenGetResult.isSucc()) {
|
||||
accessToken = "";
|
||||
refreshToken = "";
|
||||
tokenCreateTime = 0;
|
||||
return;
|
||||
}
|
||||
accessToken = oauthTokenGetResult.getResult().getAccessToken();
|
||||
refreshToken = oauthTokenGetResult.getResult().getRefreshToken();
|
||||
tokenCreateTime = DateUtil.parse(oauthTokenGetResult.getResult().getTime()).getTime() / 1000;
|
||||
return;
|
||||
}
|
||||
|
||||
if (tokenCreateTime < new Date().getTime() / 1000 + 60) {
|
||||
OauthTokenRefreshResult oauthTokenRefreshResult = API.doRequest(new OauthTokenRefreshParam()
|
||||
.setAccess_token(accessToken)
|
||||
.setRefresh_token(refreshToken)
|
||||
);
|
||||
if (!oauthTokenRefreshResult.isSucc()) {
|
||||
accessToken = "";
|
||||
refreshToken = "";
|
||||
tokenCreateTime = 0;
|
||||
}
|
||||
accessToken = oauthTokenRefreshResult.getResult().getAccessToken();
|
||||
refreshToken = oauthTokenRefreshResult.getResult().getRefreshToken();
|
||||
tokenCreateTime = DateUtil.parse(oauthTokenRefreshResult.getResult().getTime()).getTime() / 1000;
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -10,6 +10,7 @@ spring:
|
|||
- /oss/**
|
||||
- /district/tree
|
||||
- /sys_sn_config/add
|
||||
- /test/**
|
||||
|
||||
app:
|
||||
default-place:
|
||||
|
|
|
|||
Loading…
Reference in New Issue