|
@@ -19,6 +19,7 @@ import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.sql.Timestamp;
|
|
|
import java.util.*;
|
|
|
|
|
|
/**
|
|
@@ -90,6 +91,7 @@ public class DeviceController {
|
|
|
// System.out.println(res);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
@RequestMapping(value = "/token" ,method = RequestMethod.POST)
|
|
|
public Map Login(@RequestParam long id, @RequestParam String token){
|
|
|
Map map = new HashMap<>();
|
|
@@ -110,7 +112,7 @@ public class DeviceController {
|
|
|
}
|
|
|
|
|
|
@RequestMapping(value = "/register" ,method = RequestMethod.POST)
|
|
|
- public Map Register(HttpServletRequest request){
|
|
|
+ public Map Register(HttpServletRequest request, HttpServletResponse response){
|
|
|
Map map = new HashMap<>();
|
|
|
String idChannel = request.getParameter("idChannel");
|
|
|
String idDevice = request.getParameter("idDevice");
|
|
@@ -130,8 +132,32 @@ public class DeviceController {
|
|
|
map.put("msg", ApiCode.PARAMETER_ERROR.getMessage());
|
|
|
return map;
|
|
|
}
|
|
|
+ //向云平台注册设备
|
|
|
+ String ip = HttpUtil.getIpAddress(request);
|
|
|
+ System.out.println("start:"+ip);
|
|
|
+ String res = userHttp.Register(UUID.randomUUID().toString().substring(0, 31),
|
|
|
+ idChannel, ip, idDevice, idDevice);
|
|
|
+ System.out.println(res);
|
|
|
+ Map mapRes = JSONObject.parseObject(res);
|
|
|
+ System.out.println(mapRes.toString());
|
|
|
+ if(Integer.valueOf(mapRes.get("code").toString())!=200){
|
|
|
+ map.put("code", ApiCode.OPERATION_FAIL.getCode());
|
|
|
+ map.put("msg", ApiCode.OPERATION_FAIL.getMessage());
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+ mapRes = JSONObject.parseObject(mapRes.get("data").toString());
|
|
|
+
|
|
|
Device device = deviceService.Register(Long.valueOf(idChannel), Long.valueOf(idDevice));
|
|
|
if(device!=null){
|
|
|
+ //记录云平台的账号信息
|
|
|
+ device.setIaas_eid(mapRes.get("eid").toString());
|
|
|
+ device.setIaas_uid(mapRes.get("uid").toString());
|
|
|
+ device.setIaas_name(idDevice);
|
|
|
+ device.setIaas_pwd(idDevice);
|
|
|
+ device.setIaas_token(mapRes.get("token").toString());
|
|
|
+ device.setIaas_expiration(new Timestamp(Long.valueOf(mapRes.get("expiration").toString())));
|
|
|
+ device = deviceService.Update(device);
|
|
|
+
|
|
|
map.put("code", ApiCode.OK.getCode());
|
|
|
Map data = new HashMap<>();
|
|
|
data.put("id", device.getId());
|