Commit b405fce7 by fz

1.添加异常处理

2.拦截器开放接口鉴权
3.添加接口model
4.引入平台相关的dubbo服务接口
1 parent d75b47d5
Showing 35 changed files with 607 additions and 162 deletions
...@@ -62,5 +62,11 @@ ...@@ -62,5 +62,11 @@
<artifactId>lombok</artifactId> <artifactId>lombok</artifactId>
<version>${org.projectlombok.version}</version> <version>${org.projectlombok.version}</version>
</dependency> </dependency>
<dependency>
<groupId>cn.com.glsx.openplatform</groupId>
<artifactId>rpc-openplatform-api</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies> </dependencies>
</project> </project>
\ No newline at end of file \ No newline at end of file
...@@ -4,6 +4,12 @@ import com.glsx.config.SystemProperty; ...@@ -4,6 +4,12 @@ import com.glsx.config.SystemProperty;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
/**
* @Description: service基类
* @author fengzhi
* @version V1.0
*/
@Slf4j @Slf4j
public class BaseService { public class BaseService {
@Autowired @Autowired
......
package com.glsx.config;
import cn.com.glsx.openplatform.service.IceOpenApiService;
import org.oreframework.boot.autoconfigure.dubbo.reference.ReferenceBuilderFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* @Title: DubboConfig.java
* @Description: Dubbo服务注册配置
* @author deployer name
* @version V1.0
* @Company: Didihu.com.cn
* @Copyright Copyright (c) 2018
*/
@Configuration
public class DubboConfig {
@Autowired
private ReferenceBuilderFactory factory;
/**
* 注册远程服务IceOpenApiService
* @return
*/
@Bean
public IceOpenApiService rpcApiMethodRemote(){
return factory.builder(IceOpenApiService.class).check(false).timeout(30000).build();
}
}
...@@ -7,12 +7,10 @@ import org.springframework.context.annotation.Configuration; ...@@ -7,12 +7,10 @@ import org.springframework.context.annotation.Configuration;
import javax.servlet.Filter; import javax.servlet.Filter;
/** /**
* @author 01 * @Description: 过滤器配置类
* @program wrapper-demo * @author fengzhi
* @description 过滤器配置类 * @version V1.0
* @create 2018-12-24 21:06 */
* @since 1.0
**/
@Configuration @Configuration
public class FilterConfig { public class FilterConfig {
/** /**
......
...@@ -6,6 +6,12 @@ import org.springframework.context.annotation.Configuration; ...@@ -6,6 +6,12 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry; import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
/**
* @Description: 拦截器配置类
* @author fengzhi
* @version V1.0
*/
@Configuration @Configuration
public class WebConfig implements WebMvcConfigurer { public class WebConfig implements WebMvcConfigurer {
@Autowired @Autowired
...@@ -15,6 +21,6 @@ public class WebConfig implements WebMvcConfigurer { ...@@ -15,6 +21,6 @@ public class WebConfig implements WebMvcConfigurer {
public void addInterceptors(InterceptorRegistry registry) { public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(authIntercepter) registry.addInterceptor(authIntercepter)
.addPathPatterns("/**") .addPathPatterns("/**")
.excludePathPatterns("/openApi/v1.0/token/**"); .excludePathPatterns("/openApi/v1.0/token");
} }
} }
package com.glsx.constant; package com.glsx.constant;
/**
* @Description: 全局变量
* @author fengzhi
* @version V1.0
*/
public class OpenAPIConstant { public class OpenAPIConstant {
public static final String TEST_PRIVATE_KEY = "MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAJLYAe7vz8bZX0/Ro1c7SxwoAmzbH85MfPTWIPl4QQ6QRoZTThlzsRqDggGsRXPc1PVXv02o6v+oC7xV8ewG4GKJJ6RScuVVcGPbgDMIrc6J3LLKl5ullUDA3+KiWrAOQ8mHD9KcO9tN8y8uii3aDQapKl4DtyThaKyx37oYJ1BJAgMBAAECgYBhpzLJ8kML6zzeOPzWIwFVLSpHuAVTzTwAGnJ9VMJ26+1qoPW8KVrq1e/cKvNZFM+uhPccryvwbpG3YrRqkTwgZoodnBe06WlQH2iqdXfeW5bXcVfcbFNMlztDO2JgXuhPHajvgb28+4bd2wHr0aQk6cDSxWo3jOUpY9eezGoY7QJBAOCLz7/wtVEH5CfbD7K6707l8NNgZbxGqs41WtVWCLoUAx3WOPj0GR6p8ns7Ng5zykn8nnO72qqfVP/s5Q6alGcCQQCnac1Jmbfa7P38Or7qZYfTIvVNUxPXiMpK5GieYFEF0FAnKtmVGvLUk70ghDKi4Bm+/RYTs+e7fX3qjgb7gYfPAkA1FFezw67YzMi+MyZu1YmkWO6oyOzDqODPhgVG0OOXOQvTjcRB9VHK0dmkD8cje3OiMbkzGoECPE/Xf6RV42yZAkBCl8ZuEXRd5El/jIqmyG5H4S78bCCHasU1Fzg6T4vLKTrI6bWVJxwSzRW9Gnjd6xCytQ+UFMsH/Hoa1BYY80RnAkEArY7J7I37JsL1L+tNaSsD7vdb/+9eSv81n5dzh2yhyMCKgMhvPbqFn3V5p6gaL5YnCjN4ulxqvay79cohnyn9+A=="; public static final String TEST_PRIVATE_KEY = "MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAJLYAe7vz8bZX0/Ro1c7SxwoAmzbH85MfPTWIPl4QQ6QRoZTThlzsRqDggGsRXPc1PVXv02o6v+oC7xV8ewG4GKJJ6RScuVVcGPbgDMIrc6J3LLKl5ullUDA3+KiWrAOQ8mHD9KcO9tN8y8uii3aDQapKl4DtyThaKyx37oYJ1BJAgMBAAECgYBhpzLJ8kML6zzeOPzWIwFVLSpHuAVTzTwAGnJ9VMJ26+1qoPW8KVrq1e/cKvNZFM+uhPccryvwbpG3YrRqkTwgZoodnBe06WlQH2iqdXfeW5bXcVfcbFNMlztDO2JgXuhPHajvgb28+4bd2wHr0aQk6cDSxWo3jOUpY9eezGoY7QJBAOCLz7/wtVEH5CfbD7K6707l8NNgZbxGqs41WtVWCLoUAx3WOPj0GR6p8ns7Ng5zykn8nnO72qqfVP/s5Q6alGcCQQCnac1Jmbfa7P38Or7qZYfTIvVNUxPXiMpK5GieYFEF0FAnKtmVGvLUk70ghDKi4Bm+/RYTs+e7fX3qjgb7gYfPAkA1FFezw67YzMi+MyZu1YmkWO6oyOzDqODPhgVG0OOXOQvTjcRB9VHK0dmkD8cje3OiMbkzGoECPE/Xf6RV42yZAkBCl8ZuEXRd5El/jIqmyG5H4S78bCCHasU1Fzg6T4vLKTrI6bWVJxwSzRW9Gnjd6xCytQ+UFMsH/Hoa1BYY80RnAkEArY7J7I37JsL1L+tNaSsD7vdb/+9eSv81n5dzh2yhyMCKgMhvPbqFn3V5p6gaL5YnCjN4ulxqvay79cohnyn9+A==";
public static final String TEST_TOKEN = "yRaUk3pOtRxYLH2nNoNBXSEC4zvPicu2d6gAOh+NLXl7TIiR8kDL/aMJQcjN4LDqLAnBosahygnRro6ZCoR7KXoE0bmJ+5Ozhv3Hz+vvzUyGEjGmorIVXIlS/KkZWAwIguFYhXXSDLHwxfZZHMQxTtARAv3hpf7nM++YeGCnNUQ="; public static final String TEST_TOKEN = "yRaUk3pOtRxYLH2nNoNBXSEC4zvPicu2d6gAOh+NLXl7TIiR8kDL/aMJQcjN4LDqLAnBosahygnRro6ZCoR7KXoE0bmJ+5Ozhv3Hz+vvzUyGEjGmorIVXIlS/KkZWAwIguFYhXXSDLHwxfZZHMQxTtARAv3hpf7nM++YeGCnNUQ=";
public static final String TEST_PUBLIC_KEY = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCS2AHu78/G2V9P0aNXO0scKAJs2x/OTHz01iD5eEEOkEaGU04Zc7Eag4IBrEVz3NT1V79NqOr/qAu8VfHsBuBiiSekUnLlVXBj24AzCK3OidyyypebpZVAwN/iolqwDkPJhw/SnDvbTfMvLoot2g0GqSpeA7ck4Wissd+6GCdQSQIDAQAB"; public static final String TEST_PUBLIC_KEY = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCS2AHu78/G2V9P0aNXO0scKAJs2x/OTHz01iD5eEEOkEaGU04Zc7Eag4IBrEVz3NT1V79NqOr/qAu8VfHsBuBiiSekUnLlVXBj24AzCK3OidyyypebpZVAwN/iolqwDkPJhw/SnDvbTfMvLoot2g0GqSpeA7ck4Wissd+6GCdQSQIDAQAB";
public static final String TIME_FROMAT_NORMAL = "yyyy-MM-dd HH:mm:ss";
public static final String PARAM_SIGN = "sign";
} }
...@@ -8,47 +8,53 @@ import lombok.extern.slf4j.Slf4j; ...@@ -8,47 +8,53 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map;
/** /**
* @Title: OpenApiController.java
* @Description: 公共平台对外提供的api * @Description: 公共平台对外提供的api
* @author fengzhi * @author fengzhi
* @version V1.0 * @version V1.0
* @Company: Didihu.com.cn
*/ */
@RestController @RestController
@RequestMapping("/openApi/v1.0") @RequestMapping("/openApi/v1.0")
@Slf4j @Slf4j
public class OpenApiController { public class OpenApiController {
/*
* 开放平台service接口
*/
@Autowired @Autowired
OpenApiService openApiService; OpenApiService openApiService;
//授权管理 /*
* 授权管理
*/
@PostMapping("token") @PostMapping("token")
public Result getToken(@RequestBody TokenBo tokenBo){ public Result getToken(@RequestBody TokenBo tokenBo){
//todo jwt令牌
String jwtToken = openApiService.getToken(tokenBo); String jwtToken = openApiService.getToken(tokenBo);
return Result.ok().data(jwtToken); return Result.ok().data(jwtToken);
} }
//获取设备列表 /*
* 获取设备列表
*/
@PostMapping("deviceList") @PostMapping("deviceList")
public Result getDeviceList(@RequestBody DeviceListBo deviceListBo){ public Result getDeviceList(@RequestBody DeviceListBo deviceListBo){
//todo 接口自己实现
log.info("OpenApiService===getDeviceList==="+deviceListBo);
DeviceListDTO deviceListVo = openApiService.getDeviceList(deviceListBo); DeviceListDTO deviceListVo = openApiService.getDeviceList(deviceListBo);
return Result.ok().data(deviceListVo); return Result.ok().data(deviceListVo);
} }
//下发指令 /*
* 下发指令
*/
@PostMapping("postCommands") @PostMapping("postCommands")
public Result postCommands(@RequestBody CommandsBo commandsBo){ public Result postCommands(@RequestBody CommandsBo commandsBo){
openApiService.postCommands(commandsBo); openApiService.postCommands(commandsBo);
return Result.ok(); return Result.ok();
} }
//查询设备状态 /*
* 查询设备状态
*/
@PostMapping("deviceStatus") @PostMapping("deviceStatus")
public Result getDeviceStatus(@RequestBody DeviceStatusBo deviceStatusBo){ public Result getDeviceStatus(@RequestBody DeviceStatusBo deviceStatusBo){
Integer status = openApiService.getDeviceStatus(deviceStatusBo); Integer status = openApiService.getDeviceStatus(deviceStatusBo);
...@@ -57,53 +63,94 @@ public class OpenApiController { ...@@ -57,53 +63,94 @@ public class OpenApiController {
return Result.ok().data(map); return Result.ok().data(map);
} }
//获取商户下的数据概况信息 /*
* 获取商户下的数据概况信息
*/
@PostMapping("dataView") @PostMapping("dataView")
public Result getDataView(@RequestBody DeviceStatusBo deviceStatusBo){ public Result getDataView(@RequestBody DeviceStatusBo deviceStatusBo){
//todo 与杨林龙对接 Map<String, Integer> dataView = openApiService.getDataView(deviceStatusBo);
DataViewDTO dataView = openApiService.getDataView(deviceStatusBo); log.info("fz===="+dataView.toString());
return Result.ok().data(dataView); return Result.ok().data(dataView);
} }
//消息订阅 /*
* 消息订阅
*/
@PostMapping("subscribeMessage") @PostMapping("subscribeMessage")
public Result subscribeMessage(@RequestBody subscribeMessageBo subscribeMessageBo){ public Result subscribeMessage(@RequestBody subscribeMessageBo subscribeMessageBo){
openApiService.subscribeMessage(subscribeMessageBo); openApiService.subscribeMessage(subscribeMessageBo);
return Result.ok(); return Result.ok();
} }
//查询最新位置点 /*
* 查询最新位置点
*/
@PostMapping("latestGpsRecord") @PostMapping("latestGpsRecord")
public Result getLatestGpsRecord(@RequestBody DeviceStatusBo deviceStatusBo){ public Result getLatestGpsRecord(@RequestBody DeviceStatusBo deviceStatusBo){
LatestGpsRecordDto latestGpsRecordDto = openApiService.getLatestRGPSRecord(deviceStatusBo); LatestGpsRecordDto latestGpsRecordDto = openApiService.getLatestGPSRecord(deviceStatusBo);
return Result.ok().data(latestGpsRecordDto); return Result.ok().data(latestGpsRecordDto);
} }
//查询最新基站信息 /*
* 查询最新基站信息
*/
@PostMapping("latestBsRecord") @PostMapping("latestBsRecord")
public Result getLatestBsRecord(@RequestBody DeviceStatusBo deviceStatusBo){ public Result getLatestBsRecord(@RequestBody DeviceStatusBo deviceStatusBo){
LatestBsRecordDto latestGpsRecordDto = openApiService.getLatestBsRecord(deviceStatusBo); LatestBsRecordDto latestGpsRecordDto = openApiService.getLatestBsRecord(deviceStatusBo);
return Result.ok().data(latestGpsRecordDto); return Result.ok().data(latestGpsRecordDto);
} }
//查询最新GPS和基站信息 /*
* 查询最新GPS和基站信息
*/
@PostMapping("latestGpsBsRecord") @PostMapping("latestGpsBsRecord")
public Result getLatestGpsBsRecord(@RequestBody DeviceStatusBo deviceStatusBo){ public Result getLatestGpsBsRecord(@RequestBody DeviceStatusBo deviceStatusBo){
LatestGpsBsRecordDto latestGpsBsRecordDto = openApiService.getLatestGpsBsRecord(deviceStatusBo); LatestGpsBsRecordDto latestGpsBsRecordDto = openApiService.getLatestGpsBsRecord(deviceStatusBo);
return Result.ok().data(latestGpsBsRecordDto); return Result.ok().data(latestGpsBsRecordDto);
} }
//查询某时间段轨迹信息 /*
* 查询某时间段轨迹信息
*/
@PostMapping("gpsRecords") @PostMapping("gpsRecords")
public Result getGpsRecords(@RequestBody GpsBsRecordsBo gpsRecordsBo){ public Result getGpsRecords(@RequestBody GpsBsRecordsBo gpsRecordsBo){
GpsRecordsDto gpsRecordsDto = openApiService.getGpsRecords(gpsRecordsBo); GpsRecordsDto gpsRecordsDto = openApiService.getGpsRecords(gpsRecordsBo);
return Result.ok().data(gpsRecordsDto); return Result.ok().data(gpsRecordsDto);
} }
//查询某时间段基站信息 /*
* 查询某时间段基站信息
*/
@PostMapping("bsRecords") @PostMapping("bsRecords")
public Result getBsRecords(@RequestBody GpsBsRecordsBo gpsRecordsBo){ public Result getBsRecords(@RequestBody GpsBsRecordsBo gpsRecordsBo){
BsRecordsDto bsRecordsDto = openApiService.getBsRecords(gpsRecordsBo); BsRecordsDto bsRecordsDto = openApiService.getBsRecords(gpsRecordsBo);
return Result.ok().data(bsRecordsDto); return Result.ok().data(bsRecordsDto);
} }
/*
* 查询首次GPS点
*/
@PostMapping("firstGpsRecord")
public Result getFirstGpsRecord(@RequestBody DeviceStatusBo deviceStatusBo){
FirstGpsRecordDto firstGpsRecordDto = openApiService.getFirstGpsRecord(deviceStatusBo);
return Result.ok().data(firstGpsRecordDto);
}
/*
* 查询最近指定条数轨迹信息
*/
@PostMapping("recentGpsRecords")
public Result getRecentGpsRecords(@RequestBody DeviceStatusCountBo deviceStatusBo){
GpsRecordsDto recentGpsRecords = openApiService.getRecentGpsRecords(deviceStatusBo);
return Result.ok().data(recentGpsRecords);
}
/*
* 查询最近指定条数基站信息
*/
@PostMapping("recentBsRecords")
public Result getRecentBsRecords(@RequestBody DeviceStatusCountBo deviceStatusBo){
BsRecordsDto recentBsRecords = openApiService.getRecentBsRecords(deviceStatusBo);
return Result.ok().data(recentBsRecords);
}
} }
package com.glsx.enums;
public enum MapTypeEnum {
NONE_TYPE(0, "NONE"),
DOUBLE_TYPE(1, "googlebaidu"),
GOOGLE_TYPE(2, "google"),
BAIDU_TYPE(3, "baidu");
private Integer id;
private String text;
private MapTypeEnum(Integer id, String text){
this.id = id;
this.text = text;
}
public static MapTypeEnum findById(Integer id) {
MapTypeEnum[] objs = MapTypeEnum.values();
for (MapTypeEnum obj : objs) {
if (id.equals(obj.getId())) {
return obj;
}
}
return null;
}
public String getText() {
return this.text;
}
public Integer getId() {
return this.id;
}
}
package com.glsx.exception;
/**
* @Description: 异常枚举类
* @author fengzhi
* @version V1.0
*/
public enum ApiErrorMessage {
TOKEN_ERROR(1001,"token有误: [%s]"),
ARGS_ERROR(1002,"参数错误: [%s]"),
ILLEGAL_DEVICE_SN(1003,"devicesn不存在"),
AUTH_ERROR(1004,"未授权(Ip与设定的IP不符)"),
ILLEGAL_DEVICE_TYPE(1005,"devicetype不存在"),
PARAM_ERROR(1006,"各项数据格式、长度不正确"),
TOKEN_TIME_OUT(1007,"超时"),
ARGS_NULL(1008,"参数错误,必传参数");
private int code;
private String message;
public ApiException exception(Object ...args){
return new ApiException(this,args);
}
private ApiErrorMessage(int code, String message){
this.code = code;
this.message = message;
}
public int getCode() {
return code;
}
public String getMessage() {
return message;
}
}
package com.glsx.exception;
import com.glsx.model.Result;
/**
* @Description: api业务异常
* @author fengzhi
* @version V1.0
*/
public class ApiException extends BusinessException {
public ApiException(Result resultEntity) {
super(resultEntity);
}
public ApiException(ApiErrorMessage exception, Object... args) {
super(exception.getCode(), String.format(exception.getMessage(), args));
}
public ApiException(String message) {
super(message);
}
}
package com.glsx.exception;
import com.glsx.model.Result;
/**
* @Description: 业务异常
* @author fengzhi
* @version V1.0
*/
public class BusinessException extends RuntimeException{
private static final long serialVersionUID = 1L;
private Result resultEntity;
public BusinessException(String message) {
super(message);
this.resultEntity =Result.error(message);
}
public BusinessException(int errorCode, String message) {
super(message);
this.resultEntity =Result.error(errorCode,message);
}
public BusinessException(Result resultEntity) {
super(resultEntity.getMessage());
this.resultEntity = resultEntity;
}
public Result getResultEntity() {
return resultEntity;
}
}
package com.glsx.exception;
import com.glsx.model.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import javax.servlet.http.HttpServletRequest;
/**
* @Description: 全局异常处理
* @author fengzhi
* @version V1.0
*/
@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {
/**
* 业务异常处理
*
* @param req
* @param e
* @return
*/
@ExceptionHandler(value = BusinessException.class)
public Result businessExceptionHandler(HttpServletRequest req, Exception e) {
log.error("业务异常:" + e.getMessage());
ApiException businessException = (ApiException) e;
return businessException.getResultEntity();
}
}
package com.glsx.ice.iceClient;
import com.glsx.config.SystemProperty;
import com.glsx.ice.DISTRICT.IDistrictFinderPrx;
import com.glsx.ice.DISTRICT.IDistrictFinderPrxHelper;
import com.glsx.model.DTO.BsRecordDto;
import lombok.extern.slf4j.Slf4j;
import java.util.List;
@Slf4j
public class IceDistrictClient {
static String url = SystemProperty.getProperty("ice.districUrl");
static Ice.Communicator ic = Ice.Util.initialize();
static Ice.ObjectPrx base = ic.stringToProxy(url).ice_timeout(Integer.parseInt(SystemProperty.getProperty("ice.connectTimeout")));
static IDistrictFinderPrx prx = IDistrictFinderPrxHelper.checkedCast(base);
/**
* 通过经纬度查询所属行政区域
* @return
*/
public static List<BsRecordDto> getDistInfoByPos(float lng, float lat) {
try {
if (prx == null) {
throw new Exception("Invalid proxy");
}
Ice.IntHolder distCode = new Ice.IntHolder();
Ice.StringHolder strDistName = new Ice.StringHolder();
boolean res = prx.get_distinfo_by_pos(lng,lat,distCode,strDistName);
if (res) {
log.info("success===getDistInfoByPos:" + distCode+"=="+strDistName);
}
} catch (Ice.LocalException e) {
log.error("===getDistInfoByPos_ICE_EXCEP:" + e.getMessage(), e);
} catch (Exception e) {
log.error("===getDistInfoByPos_EXCEP:" + e.getMessage(), e);
}
return null;
}
}
...@@ -2,6 +2,7 @@ package com.glsx.ice.iceClient; ...@@ -2,6 +2,7 @@ package com.glsx.ice.iceClient;
import Ice.Communicator; import Ice.Communicator;
import com.glsx.config.SystemProperty; import com.glsx.config.SystemProperty;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -10,14 +11,12 @@ import org.slf4j.LoggerFactory; ...@@ -10,14 +11,12 @@ import org.slf4j.LoggerFactory;
* @author Administrator * @author Administrator
* *
*/ */
@Slf4j
public class IcePoiSearchClient { public class IcePoiSearchClient {
private static Logger log = LoggerFactory.getLogger(IcePoiSearchClient.class);
// ice接口服务器地址 ice.poisearch.interface.url=PoiSearchNear:default -h 47.107.239.127 -p 10081 // ice接口服务器地址 ice.poisearch.interface.url=PoiSearchNear:default -h 47.107.239.127 -p 10081
private static String ICE_URL = SystemProperty.getProperty("ice.poisearch.interface.url"); private static String ICE_URL = SystemProperty.getProperty("ice.poisearchUrl");
static Communicator ic = Ice.Util.initialize(); static Communicator ic = Ice.Util.initialize();
static Ice.ObjectPrx base = ic.stringToProxy(ICE_URL).ice_timeout(Integer.parseInt(SystemProperty.getProperty("ice.connect.timeout"))); static Ice.ObjectPrx base = ic.stringToProxy(ICE_URL).ice_timeout(Integer.parseInt(SystemProperty.getProperty("ice.connectTimeout")));
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
......
...@@ -3,6 +3,7 @@ package com.glsx.ice.iceClient; ...@@ -3,6 +3,7 @@ package com.glsx.ice.iceClient;
import Ice.Communicator; import Ice.Communicator;
import com.glsx.config.SystemProperty; import com.glsx.config.SystemProperty;
import com.glsx.ice.HDaoMile.*; import com.glsx.ice.HDaoMile.*;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -13,14 +14,13 @@ import java.util.Date; ...@@ -13,14 +14,13 @@ import java.util.Date;
* @author Administrator * @author Administrator
* *
*/ */
@Slf4j
public class IceRtMileStatClient { public class IceRtMileStatClient {
private static Logger log = LoggerFactory.getLogger(IceRtMileStatClient.class);
// ice接口服务器地址 ice.interface.url=FenceUpdate:default -h 192.168.3.153 -p // ice接口服务器地址 ice.interface.url=FenceUpdate:default -h 192.168.3.153 -p
// 10000 // 10000
private static String ICE_URL = SystemProperty.getProperty("ice.mile.interface.url"); private static String ICE_URL = SystemProperty.getProperty("ice.mileUrl");
static Communicator ic = Ice.Util.initialize(); static Communicator ic = Ice.Util.initialize();
static Ice.ObjectPrx base = ic.stringToProxy(ICE_URL).ice_timeout(Integer.parseInt(SystemProperty.getProperty("ice.connect.timeout"))); static Ice.ObjectPrx base = ic.stringToProxy(ICE_URL).ice_timeout(Integer.parseInt(SystemProperty.getProperty("ice.connectTimeout")));
static DaoMileServicePrx daoMileService = DaoMileServicePrxHelper.checkedCast(base); static DaoMileServicePrx daoMileService = DaoMileServicePrxHelper.checkedCast(base);
......
package com.glsx.intercepter; package com.glsx.intercepter;
import com.glsx.utils.JwtTokenUtil; import com.glsx.constant.OpenAPIConstant;
import io.jsonwebtoken.Claims; import com.glsx.exception.ApiErrorMessage;
import com.glsx.utils.JwtUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import net.sf.json.JSONObject; import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -10,39 +11,66 @@ import org.springframework.stereotype.Component; ...@@ -10,39 +11,66 @@ import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor; import org.springframework.web.servlet.HandlerInterceptor;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.text.SimpleDateFormat;
/**
* @Description: 开放平台接口拦截器
* @author fengzhi
* @version V1.0
*/
@Component @Component
@Slf4j @Slf4j
public class AuthIntercepter implements HandlerInterceptor { public class AuthIntercepter implements HandlerInterceptor {
/**
* JWT工具
*/
@Autowired @Autowired
private JwtTokenUtil jwtTokenUtil; private JwtUtil jwtUtil;
/**
* 请求拦截
*
* @param request request 请求对象, 包含请求地址, 头, 参数, body(流)等信息
* @param request response 响应对象, 包含输入流, 响应body类型等信息
* @param handler 指controller的@Controller注解下的"完整"方法名, 是包含exception等字段信息
* @return boolean 是否拦截
*/
@Override @Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
log.info("===拦截=="); log.info("===AuthIntercepter拦截=="+request.getServletPath());
if (isJson(request)) { //非json返回提示
if (!isJson(request))
throw ApiErrorMessage.PARAM_ERROR.exception();
// 获取json字符串 // 获取json字符串
String jsonStr = new RequestWrapper(request).getBodyString(); String jsonStr = new RequestWrapper(request).getBodyString();
log.info("[preHandle] json数据 : {}", jsonStr); log.info("[preHandle] json数据 : {}", jsonStr);
JSONObject jsonParam = JSONObject.fromObject(jsonStr); JSONObject jsonParam = JSONObject.fromObject(jsonStr);
//获取token
String jwtToken = jsonParam.getString("token"); String jwtToken = jsonParam.getString("token");
//判断token是否过期
Claims claims = jwtTokenUtil.getClaimsFromToken(jwtToken); boolean tokenExpired = false;
if (null != claims) { try {
String s1 = (String) claims.get("fzs"); //解析验证token
Integer s2 = (Integer) claims.get("fzn"); tokenExpired = jwtUtil.isTokenExpired(jwtToken);
Integer s3 = (Integer) claims.get("fzl"); }catch (Exception e){
log.info("jwt===s1:" + s1 + "==s2:" + s2 + "==s3:" + s3); throw ApiErrorMessage.TOKEN_ERROR.exception();
}
} }
return true;
if(tokenExpired){
throw ApiErrorMessage.TOKEN_TIME_OUT.exception();
} }
@Override //提示过期时间
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception { SimpleDateFormat sdf = new SimpleDateFormat(OpenAPIConstant.TIME_FROMAT_NORMAL);
String expirTime = sdf.format(jwtUtil.getExpiredDateFromToken(jwtToken));
log.info("token过期时间:"+expirTime);
//验证成功,放行
return true;
} }
/** /**
* 判断本次请求的数据类型是否为json * 判断本次请求的数据类型是否为json
* *
......
package com.glsx.intercepter; package com.glsx.intercepter;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import javax.servlet.*; import javax.servlet.*;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.io.IOException; import java.io.IOException;
/** /**
* 使用HttpServletRequestWrapper + Filter解决输入流不能重复读取问题 * @Description: HttpServletRequestWrapper + Filter解决输入流不能重复读取问题
* @author fengzhi
* @version V1.0
*/ */
@Slf4j @Slf4j
public class ReplaceStreamFilter implements Filter { public class ReplaceStreamFilter implements Filter {
......
...@@ -10,7 +10,9 @@ import java.io.*; ...@@ -10,7 +10,9 @@ import java.io.*;
import java.nio.charset.Charset; import java.nio.charset.Charset;
/** /**
* 使用HttpServletRequestWrapper + Filter解决输入流不能重复读取问题 * @Description: HttpServletRequestWrapper + Filter解决输入流不能重复读取问题
* @author fengzhi
* @version V1.0
*/ */
@Slf4j @Slf4j
public class RequestWrapper extends HttpServletRequestWrapper { public class RequestWrapper extends HttpServletRequestWrapper {
......
package com.glsx.model.BO;
import lombok.Data;
import lombok.ToString;
@Data
@ToString(callSuper = true)
public class DeviceStatusCountBo extends DeviceStatusBo{
private Integer count;
}
package com.glsx.model.BO; package com.glsx.model.BO;
import com.glsx.model.Basemodel;
import lombok.Data; import lombok.Data;
import lombok.ToString;
@Data @Data
@ToString(callSuper = true) public class TokenBo {
public class TokenBo extends Basemodel { /*
* appID,应用唯一标识(可能是用户id,服务商ID或是微信公众号,具体到时候定义)
*/
private Integer appId;
/*
* 当前时间戳,精确到秒。例如时间为2015-03-23 14:58:33 ,则time= 1427093913
*/
private String time;
/*
* 授权类型,1:简单模式
*/
private Integer grantType; private Integer grantType;
/*
* 参数用公钥加密后的密文
*/
private String sign;
} }
...@@ -3,9 +3,11 @@ package com.glsx.model; ...@@ -3,9 +3,11 @@ package com.glsx.model;
import lombok.Data; import lombok.Data;
import lombok.ToString; import lombok.ToString;
import java.util.Date;
@Data @Data
@ToString(callSuper = true) @ToString(callSuper = true)
public class BaseTimeRangeModel extends Basemodel{ public class BaseTimeRangeModel extends Basemodel{
private Long startTime; private Date startTime;
private Long endTime; private Date endTime;
} }
...@@ -5,10 +5,6 @@ import java.io.Serializable; ...@@ -5,10 +5,6 @@ import java.io.Serializable;
@Data @Data
public class Basemodel implements Serializable { public class Basemodel implements Serializable {
private Integer appId; //会话token(jwt令牌)
private String time;
//会话token
private String token; private String token;
} }
package com.glsx.model.DTO;
import lombok.Data;
@Data
public class BsInfoDto {
//基号
private Integer lac;
//塔号
private Integer ci;
//信号强度 0~100
private Integer signal;
}
...@@ -2,12 +2,16 @@ package com.glsx.model.DTO; ...@@ -2,12 +2,16 @@ package com.glsx.model.DTO;
import lombok.Data; import lombok.Data;
import java.util.List;
@Data @Data
public class BsRecordDto { public class BsRecordDto {
//基号 //时间翟10位 1970之后的秒数
private Integer lac; private Integer gpstime;
//塔号 //国家码
private Integer ci; private Integer mcc;
//信号强度 0~100 //所属运商
private Integer signal; private Integer mnc;
private List<BsInfoDto> bsinfo;
} }
...@@ -8,12 +8,10 @@ import java.util.List; ...@@ -8,12 +8,10 @@ import java.util.List;
@Data @Data
@ToString(callSuper = true) @ToString(callSuper = true)
public class BsRecordsDto { public class BsRecordsDto {
//时间翟10位 1970之后的秒数 //设备号
private Integer gpstime; private String sn;
//国家码 //是否还有记录
private Integer mcc; private Boolean has_more;
//所属运商 //bs记录
private Integer mnc;
private List<BsRecordDto> bsrecord; private List<BsRecordDto> bsrecord;
} }
package com.glsx.model.DTO;
import lombok.Data;
@Data
public class DataViewDTO {
//总共激活设备数
private Integer totaldevice;
//总共用户数
private Integer totalusers;
//在线设备数
private Integer onlinedevices;
}
package com.glsx.model.DTO;
import com.glsx.model.GaodeMap;
import lombok.Data;
@Data
public class FirstGpsRecordDto extends GaodeMap {
//10位时间戳(1970之后的秒数)
private Integer gpstime;
//速度
private Integer speed;
//设备号
private String sn;
}
...@@ -15,6 +15,6 @@ public class LatestBsRecordDto { ...@@ -15,6 +15,6 @@ public class LatestBsRecordDto {
//所属运商 //所属运商
private Integer mnc; private Integer mnc;
private List<BsRecordDto> bsrecord; private List<BsInfoDto> bsrecord;
} }
...@@ -13,23 +13,27 @@ import java.util.Map; ...@@ -13,23 +13,27 @@ import java.util.Map;
*/ */
public class Result extends HashMap<String,Object>{ public class Result extends HashMap<String,Object>{
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
public static final String CODE_KEY = "code"; public static final String CODE_KEY = "code";
public static final String SUCCESS_KEY = "success"; public static final String SUCCESS_KEY = "success";
public static final String MSG_KEY = "message"; public static final String MSG_KEY = "message";
private static final String RESULT_KEY = "result"; private static final String RESULT_KEY = "result";
public static final Integer SUCCESS = 0;
public static final Integer ERROR = 9999;
public Result() { public Result() {
this.put(CODE_KEY, 200); this.put(CODE_KEY, SUCCESS);
this.put(SUCCESS_KEY, true); this.put(SUCCESS_KEY, true);
this.put(MSG_KEY, ""); this.put(MSG_KEY, "");
} }
public static Result error() { public static Result error() {
return error(9999, "未知异常,请联系管理员"); return error(ERROR, "未知错误");
} }
public static Result error(String msg) { public static Result error(String msg) {
return error(500, msg); return error(ERROR, msg);
} }
public static Result error(int code, String msg) { public static Result error(int code, String msg) {
......
...@@ -3,6 +3,8 @@ package com.glsx.service; ...@@ -3,6 +3,8 @@ package com.glsx.service;
import com.glsx.model.BO.*; import com.glsx.model.BO.*;
import com.glsx.model.DTO.*; import com.glsx.model.DTO.*;
import java.util.Map;
public interface OpenApiService { public interface OpenApiService {
String getToken(TokenBo grantType); String getToken(TokenBo grantType);
...@@ -13,11 +15,11 @@ public interface OpenApiService { ...@@ -13,11 +15,11 @@ public interface OpenApiService {
Integer getDeviceStatus(DeviceStatusBo deviceStatusBo); Integer getDeviceStatus(DeviceStatusBo deviceStatusBo);
DataViewDTO getDataView(DeviceStatusBo deviceStatusBo); Map<String, Integer> getDataView(DeviceStatusBo deviceStatusBo);
void subscribeMessage(subscribeMessageBo subscribeMessageBo); void subscribeMessage(subscribeMessageBo subscribeMessageBo);
LatestGpsRecordDto getLatestRGPSRecord(DeviceStatusBo deviceStatusBo); LatestGpsRecordDto getLatestGPSRecord(DeviceStatusBo deviceStatusBo);
LatestBsRecordDto getLatestBsRecord(DeviceStatusBo deviceStatusBo); LatestBsRecordDto getLatestBsRecord(DeviceStatusBo deviceStatusBo);
...@@ -26,4 +28,10 @@ public interface OpenApiService { ...@@ -26,4 +28,10 @@ public interface OpenApiService {
GpsRecordsDto getGpsRecords(GpsBsRecordsBo gpsRecordsBo); GpsRecordsDto getGpsRecords(GpsBsRecordsBo gpsRecordsBo);
BsRecordsDto getBsRecords(GpsBsRecordsBo gpsRecordsBo); BsRecordsDto getBsRecords(GpsBsRecordsBo gpsRecordsBo);
FirstGpsRecordDto getFirstGpsRecord(DeviceStatusBo deviceStatusBo);
GpsRecordsDto getRecentGpsRecords(DeviceStatusBo deviceStatusBo);
BsRecordsDto getRecentBsRecords(DeviceStatusBo deviceStatusBo);
} }
package com.glsx.service.impl; package com.glsx.service.impl;
import cn.com.glsx.openplatform.service.IceOpenApiService;
import com.glsx.base.controller.BaseService; import com.glsx.base.controller.BaseService;
import com.glsx.constant.OpenAPIConstant; import com.glsx.constant.OpenAPIConstant;
import com.glsx.enums.MapTypeEnum;
import com.glsx.exception.ApiErrorMessage;
import com.glsx.ice.iceClient.IceHDaoGpsClient;
import com.glsx.model.BO.*; import com.glsx.model.BO.*;
import com.glsx.model.DTO.*; import com.glsx.model.DTO.*;
import com.glsx.service.OpenApiService; import com.glsx.service.OpenApiService;
import com.glsx.utils.JwtTokenUtil; import com.glsx.utils.JwtUtil;
import com.glsx.utils.MapUtils; import com.glsx.utils.MapUtils;
import com.glsx.utils.RSAUtils; import com.glsx.utils.RSAUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.TreeMap; import java.util.TreeMap;
/**
* @Description: 开放平台接口实现类
* @author fengzhi
* @version V1.0
*/
@Service @Service
public class OpenApiServiceImpl extends BaseService implements OpenApiService { public class OpenApiServiceImpl extends BaseService implements OpenApiService {
@Autowired @Autowired
JwtTokenUtil jwtTokenUtil; JwtUtil jwtTokenUtil;
@Autowired
IceOpenApiService iceOpenApiService;
@Override @Override
public String getToken(TokenBo tokenBo) { public String getToken(TokenBo tokenBo) {
logi("OpenApiService===调用getToken===" + tokenBo); logi("OpenApiService===调用getToken开始===" + tokenBo);
//appID,应用唯一标识(可能是用户id,服务商ID或是微信公众号,具体到时候定义) //校验必传参数
Integer appId = tokenBo.getAppId(); TreeMap<String, String> params = MapUtils.transBean2Map(tokenBo);
//授权类型,1:简单模式 logi("参数对象:" + params);
Integer grantType = tokenBo.getGrantType(); boolean miss = params.entrySet().stream().anyMatch(kv->StringUtils.isEmpty(kv.getValue()));
//当前时间戳,精确到秒。例如时间为2015-03-23 14:58:33 ,则time= 1427093913 if(miss)
String time = tokenBo.getTime(); throw ApiErrorMessage.ARGS_NULL.exception();
//获取密文(参数顺序按照字母升序,共钥加密)
String token = tokenBo.getToken();
//todo 根据appID查询客户信息 //todo 根据appID查询客户信息
Integer appId = tokenBo.getAppId();
//获取公钥加密的密文
String sign = tokenBo.getSign();
//todo 获取私钥 //todo 获取私钥
String privateKey = OpenAPIConstant.TEST_PRIVATE_KEY; String privateKey = OpenAPIConstant.TEST_PRIVATE_KEY;
String originalStr = ""; String originalStr = "";
try { try {
//解密获取明文 //私钥解密获取明文
originalStr = RSAUtils.decrypt(token, privateKey); originalStr = RSAUtils.decrypt(sign, privateKey);
} catch (Exception e) { } catch (Exception e) {
loge("OpenApiService===RSA解密错误===", e); throw ApiErrorMessage.ARGS_ERROR.exception("RSA解密错误=="+sign);
} }
//校验参数,防止篡改 //除了sign以外,按照参数字母升序(参数+参数值)拼接
TreeMap<String, String> params = MapUtils.transBean2Map(tokenBo);
params.remove("token");
logi("Map对象:" + params);
//按照参数字母升序(参数+参数值)拼接
StringBuffer paramsStrbuf = new StringBuffer(); StringBuffer paramsStrbuf = new StringBuffer();
for (Map.Entry<String, String> param : params.entrySet()) { params.remove(OpenAPIConstant.PARAM_SIGN);
paramsStrbuf.append(param.getKey()).append(param.getValue()); params.entrySet().stream().forEach(kv->{
} paramsStrbuf.append(kv.getKey()).append(kv.getValue());
});
String paramsStr = paramsStrbuf.toString(); String paramsStr = paramsStrbuf.toString();
//如果与明文不相同,则参数被篡改 //校验参数,防止篡改
if (!paramsStr.equals(originalStr)) { if (!paramsStr.equals(originalStr)) {
logi("参数被篡改"); throw ApiErrorMessage.ARGS_ERROR.exception("请求参数被篡改");
} }
//todo 将客户信息转化为jwt //todo 将客户信息转化为jwt
...@@ -66,66 +77,113 @@ public class OpenApiServiceImpl extends BaseService implements OpenApiService { ...@@ -66,66 +77,113 @@ public class OpenApiServiceImpl extends BaseService implements OpenApiService {
infos.put("fzn", 123); infos.put("fzn", 123);
infos.put("fzl", 22); infos.put("fzl", 22);
String jwtToken = jwtTokenUtil.generateToken(infos); String jwtToken = jwtTokenUtil.generateToken(infos);
logi("OpenApiService===返回jwt===" + jwtToken);
return jwtToken; return jwtToken;
} }
/*
* 参数用公钥加密后的密文
*/
@Override @Override
public DeviceListDTO getDeviceList(DeviceListBo deviceListBo) { public DeviceListDTO getDeviceList(DeviceListBo deviceListBo) {
logi("OpenApiService===getDeviceList===" + deviceListBo); logi("OpenApiService===getDeviceList===" + deviceListBo);
DeviceListDTO deviceListDTO = new DeviceListDTO(); DeviceListDTO deviceListDTO = new DeviceListDTO();
deviceListDTO.setTotal(100); deviceListDTO.setTotal(100);
return null; return deviceListDTO;
} }
//todo 接口还没给
@Override @Override
public void postCommands(CommandsBo commandsBo) { public void postCommands(CommandsBo commandsBo) {
logi("OpenApiService===ImplpostCommands"); logi("OpenApiService===postCommands");
} }
//todo 接口还没给
@Override @Override
public Integer getDeviceStatus(DeviceStatusBo deviceStatusBo) { public Integer getDeviceStatus(DeviceStatusBo deviceStatusBo) {
logi("OpenApiService===getToken"); logi("OpenApiService===getDeviceStatus");
return null; return null;
} }
@Override @Override
public DataViewDTO getDataView(DeviceStatusBo deviceStatusBo) { public Map<String, Integer> getDataView(DeviceStatusBo deviceStatusBo) {
logi("OpenApiService===getToken"); logi("OpenApiService===getDataView");
return null; int userID = 1;
return iceOpenApiService.getDataView(userID);
} }
//todo 接口还没给
@Override @Override
public void subscribeMessage(subscribeMessageBo subscribeMessageBo) { public void subscribeMessage(subscribeMessageBo subscribeMessageBo) {
logi("OpenApiService===getToken"); logi("OpenApiService===subscribeMessage");
} }
@Override @Override
public LatestGpsRecordDto getLatestRGPSRecord(DeviceStatusBo deviceStatusBo) { public LatestGpsRecordDto getLatestGPSRecord(DeviceStatusBo deviceStatusBo) {
logi("OpenApiService===getToken"); logi("OpenApiService===getLatestRGPSRecord");
return null; long dId = 61000593;
Integer dType = 6;
//todo 调用参数
LatestGpsRecordDto gpsRecord = IceHDaoGpsClient.getLatestGpsRecord(dId, dType, MapTypeEnum.NONE_TYPE.getId());
//todo 设置sn
return gpsRecord;
} }
@Override @Override
public LatestBsRecordDto getLatestBsRecord(DeviceStatusBo deviceStatusBo) { public LatestBsRecordDto getLatestBsRecord(DeviceStatusBo deviceStatusBo) {
logi("OpenApiService===getLatestBsRecord" + deviceStatusBo); logi("OpenApiService===getLatestBsRecord" + deviceStatusBo);
return null; long dId = 61000593;
Integer dType = 6;
//todo 调用参数
LatestBsRecordDto bsRecord = IceHDaoGpsClient.getLatestBsRecord(dId, dType);
//todo 设置sn
return bsRecord;
} }
@Override @Override
public LatestGpsBsRecordDto getLatestGpsBsRecord(DeviceStatusBo deviceStatusBo) { public LatestGpsBsRecordDto getLatestGpsBsRecord(DeviceStatusBo deviceStatusBo) {
logi("OpenApiService===getLatestGpsBsRecord===" + deviceStatusBo); logi("OpenApiService===getLatestGpsBsRecord===" + deviceStatusBo);
return null; long[] dId = {61000593};
//todo 调用参数
LatestGpsBsRecordDto latestGpsBsRecordDto = IceHDaoGpsClient.getDevicesGpsInfo(dId, 0,0);
return latestGpsBsRecordDto;
} }
@Override @Override
public GpsRecordsDto getGpsRecords(GpsBsRecordsBo gpsRecordsBo) { public GpsRecordsDto getGpsRecords(GpsBsRecordsBo gpsRecordsBo) {
logi("OpenApiService===getGpsRecords===" + gpsRecordsBo); logi("OpenApiService===getGpsRecords===" + gpsRecordsBo);
return null; GpsRecordsDto gpsRecordsDto = IceHDaoGpsClient.getGpsRecords(1,gpsRecordsBo.getStartTime(),gpsRecordsBo.getEndTime(),1);
return gpsRecordsDto;
} }
@Override @Override
public BsRecordsDto getBsRecords(GpsBsRecordsBo gpsRecordsBo) { public BsRecordsDto getBsRecords(GpsBsRecordsBo gpsRecordsBo) {
return null; logi("OpenApiService===getGpsRecords===" + gpsRecordsBo);
BsRecordsDto bsRecordsDto = IceHDaoGpsClient.getBsRecords(1,gpsRecordsBo.getStartTime(),gpsRecordsBo.getEndTime(),1);
return bsRecordsDto;
} }
@Override
public FirstGpsRecordDto getFirstGpsRecord(DeviceStatusBo deviceStatusBo) {
logi("OpenApiService===getFirstGpsRecord===" + deviceStatusBo);
FirstGpsRecordDto firstGpsRecordDto = IceHDaoGpsClient.getFirstGpsRecord(1,1);
return firstGpsRecordDto;
}
@Override
public GpsRecordsDto getRecentGpsRecords(DeviceStatusBo deviceStatusBo) {
logi("OpenApiService===getRecentGpsRecords===" + deviceStatusBo);
GpsRecordsDto bsRecordsDto = IceHDaoGpsClient.getRecentGpsRecords(1,1,1,1,1);
return bsRecordsDto;
}
@Override
public BsRecordsDto getRecentBsRecords(DeviceStatusBo deviceStatusBo) {
logi("OpenApiService===getRecentBsRecords===" + deviceStatusBo);
BsRecordsDto bsRecordsDto = IceHDaoGpsClient.getRecentBsRecords(1,1);
return bsRecordsDto;
}
} }
package com.glsx.utils; package com.glsx.utils;
import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;
import com.auth0.jwt.exceptions.JWTVerificationException;
import com.auth0.jwt.interfaces.DecodedJWT;
import com.auth0.jwt.interfaces.JWTVerifier;
import com.glsx.config.SystemProperty; import com.glsx.config.SystemProperty;
import io.jsonwebtoken.Claims; import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts; import io.jsonwebtoken.Jwts;
...@@ -12,25 +7,19 @@ import io.jsonwebtoken.SignatureAlgorithm; ...@@ -12,25 +7,19 @@ import io.jsonwebtoken.SignatureAlgorithm;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.Date; import java.util.Date;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
/** /**
* JwtToken生成的工具类 * @Description: Jwt工具类
* JWT token的格式:header.payload.signature * @author fengzhi
* header的格式(算法、token的类型): * @version V1.0
* {"alg": "HS512","type": "JWT"}
* payload的格式(用户名、创建时间、生成时间):
* {"sub":"wang","created":1489079981393,"exp":1489684781}
* signature的生成算法:
* HMACSHA512(base64UrlEncode(header) + "." +base64UrlEncode(payload),secret)
*/ */
@Slf4j @Slf4j
@Component @Component
public class JwtTokenUtil { public class JwtUtil {
private static final String CLAIM_KEY_CREATED = "created"; private static final String CLAIM_KEY_CREATED = "created";
private static final String JWT_SECRET = "jwt.openapi.secret"; private static final String JWT_SECRET = "jwt.secret";
private static final String JWT_EXPIRATION = "jwt.openapi.expiration"; private static final String JWT_EXPIRATION = "jwt.expiration";
/** /**
* 根据负责生成JWT的token * 根据负责生成JWT的token
...@@ -48,14 +37,10 @@ public class JwtTokenUtil { ...@@ -48,14 +37,10 @@ public class JwtTokenUtil {
*/ */
public Claims getClaimsFromToken(String token) { public Claims getClaimsFromToken(String token) {
Claims claims = null; Claims claims = null;
try {
claims = Jwts.parser() claims = Jwts.parser()
.setSigningKey(SystemProperty.getProperty(JWT_SECRET)) .setSigningKey(SystemProperty.getProperty(JWT_SECRET))
.parseClaimsJws(token) .parseClaimsJws(token)
.getBody(); .getBody();
} catch (Exception e) {
log.info("JWT格式验证失败:{}",token);
}
return claims; return claims;
} }
......
...@@ -6,6 +6,12 @@ import java.beans.PropertyDescriptor; ...@@ -6,6 +6,12 @@ import java.beans.PropertyDescriptor;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.TreeMap; import java.util.TreeMap;
/**
* @Description: 将实体类属性转为map
* @author fengzhi
* @version V1.0
*/
public class MapUtils { public class MapUtils {
public static TreeMap<String, String> transBean2Map(Object obj) { public static TreeMap<String, String> transBean2Map(Object obj) {
......
...@@ -11,9 +11,16 @@ import java.security.spec.X509EncodedKeySpec; ...@@ -11,9 +11,16 @@ import java.security.spec.X509EncodedKeySpec;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
/**
* @Description: RSA工具类
* @author fengzhi
* @version V1.0
*/
@Component @Component
public class RSAUtils { public class RSAUtils {
/*private static Map<Integer, String> keyMap = new HashMap<Integer, String>(); //用于封装随机产生的公钥与私钥 private static Map<Integer, String> keyMap = new HashMap<Integer, String>(); //用于封装随机产生的公钥与私钥
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
//生成公钥和私钥 //生成公钥和私钥
genKeyPair(); genKeyPair();
...@@ -28,10 +35,10 @@ public class RSAUtils { ...@@ -28,10 +35,10 @@ public class RSAUtils {
System.out.println("还原后的字符串为:" + messageDe); System.out.println("还原后的字符串为:" + messageDe);
} }
*//** /**
* 随机生成密钥对 * 随机生成密钥对
* @throws NoSuchAlgorithmException * @throws NoSuchAlgorithmException
*//* */
public static void genKeyPair() throws NoSuchAlgorithmException { public static void genKeyPair() throws NoSuchAlgorithmException {
// KeyPairGenerator类用于生成公钥和私钥对,基于RSA算法生成对象 // KeyPairGenerator类用于生成公钥和私钥对,基于RSA算法生成对象
KeyPairGenerator keyPairGen = KeyPairGenerator.getInstance("RSA"); KeyPairGenerator keyPairGen = KeyPairGenerator.getInstance("RSA");
...@@ -47,7 +54,8 @@ public class RSAUtils { ...@@ -47,7 +54,8 @@ public class RSAUtils {
// 将公钥和私钥保存到Map // 将公钥和私钥保存到Map
keyMap.put(0,publicKeyString); //0表示公钥 keyMap.put(0,publicKeyString); //0表示公钥
keyMap.put(1,privateKeyString); //1表示私钥 keyMap.put(1,privateKeyString); //1表示私钥
}*/ }
/** /**
* RSA公钥加密 * RSA公钥加密
* *
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!