|
@@ -24,6 +24,7 @@ import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
import java.sql.Timestamp;
|
|
|
import java.util.*;
|
|
|
|
|
@@ -143,8 +144,8 @@ public class DeviceController {
|
|
|
HttpUtil.responseApiCode(request, response, ApiCode.RECORD_EXIST);
|
|
|
return;
|
|
|
}
|
|
|
- List<Channel> channelList = channelService.SearchById(Long.valueOf(idChannel));
|
|
|
- if(channelList==null || channelList.size()<1){
|
|
|
+ Channel channel = channelService.SearchById(Long.valueOf(idChannel));
|
|
|
+ if(Objects.isNull(channel)){
|
|
|
HttpUtil.responseApiCode(request, response, ApiCode.PARAMETER_ERROR);
|
|
|
return;
|
|
|
}
|
|
@@ -209,8 +210,58 @@ public class DeviceController {
|
|
|
|
|
|
|
|
|
|
|
|
- List<Channel> channelList = channelService.SearchById(Long.valueOf(idChannel));
|
|
|
- if(channelList==null || channelList.size()<1){
|
|
|
+ Channel channel = channelService.SearchById(Long.valueOf(idChannel));
|
|
|
+ if(Objects.isNull(channel)){
|
|
|
+ HttpUtil.responseApiCode(request, response, ApiCode.CHANNEL_NOT_FOUND_ERROR);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ Device device = deviceService.findToken(Long.valueOf(idChannel), idDevice);
|
|
|
+
|
|
|
+ if(Objects.isNull(device)){
|
|
|
+ HttpUtil.responseApiCode(request, response, ApiCode.NO_REGISTER_FAIL);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ device.setIaas_eid("");
|
|
|
+ device.setIaas_name("");
|
|
|
+ device.setIaas_uid("");
|
|
|
+ device.setIaas_token("");
|
|
|
+ device.setIaas_pwd("");
|
|
|
+ device.setTokenOld("");
|
|
|
+ HttpUtil.responseOkData(request, response, device);
|
|
|
+
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @RequestMapping(value = "/v2/token",method = RequestMethod.GET)
|
|
|
+ public void tokenV2(HttpServletRequest request, HttpServletResponse response){
|
|
|
+ String idChannel = request.getParameter("idChannel");
|
|
|
+ String idDevice = request.getParameter("idDevice");
|
|
|
+ String ts = request.getParameter("ts");
|
|
|
+ String sign = request.getParameter("sign");
|
|
|
+
|
|
|
+ if(StringUtils.isBlank(idChannel) || StringUtils.isBlank(idDevice) || StringUtils.isBlank(sign)){
|
|
|
+ HttpUtil.responseApiCode(request, response, ApiCode.PARAMETER_ERROR);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Map<String,String> param = new HashMap<>();
|
|
|
+ param.put("idChannel",idChannel);
|
|
|
+ param.put("idDevice",idDevice);
|
|
|
+ param.put("ts",ts);
|
|
|
+ String signStr = Encrypt.createHMACSHA256(param,signKey);
|
|
|
+
|
|
|
+ String decode = new String(Base64.getDecoder().decode(sign), StandardCharsets.UTF_8);
|
|
|
+
|
|
|
+
|
|
|
+ if (!signStr.equalsIgnoreCase(decode)) {
|
|
|
+ HttpUtil.responseApiCode(request, response, ApiCode.SIGN_FAIL);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ Channel channel = channelService.SearchById(Long.valueOf(idChannel));
|
|
|
+ if(Objects.isNull(channel)){
|
|
|
HttpUtil.responseApiCode(request, response, ApiCode.CHANNEL_NOT_FOUND_ERROR);
|
|
|
return;
|
|
|
}
|