| | |
| | | package com.xiaopeng.automaticPilot.util; |
| | | |
| | | import cn.hutool.core.lang.Snowflake; |
| | | import cn.hutool.core.util.IdUtil; |
| | | import cn.hutool.http.HttpRequest; |
| | | import cn.hutool.http.HttpResponse; |
| | | import cn.hutool.http.HttpUtil; |
| | |
| | | header.setMsg_id(UUID.randomUUID().toString()); |
| | | header.setTimestamp(System.currentTimeMillis()); |
| | | header.setCmd(RTCmdType.CLOUD_ORDER_OPERATION); |
| | | header.setSequence(1L); |
| | | header.setType(MessageType.MESSAGE_TYPE_RESPONSE); |
| | | Snowflake snowflake = IdUtil.getSnowflake(0, 0); |
| | | header.setSequence(snowflake.nextId()); |
| | | header.setType(MessageType.MESSAGE_TYPE_REQUEST); |
| | | msgContent.setHeader(header); |
| | | // 消息内容 |
| | | JSONObject jsonObject = new JSONObject(); |
| | |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | | * 响应消息 |
| | | * |
| | | * @param responseMessage |
| | | * @return |
| | | */ |
| | | public ResponseMessage responseMessage(ResponseMessage responseMessage) { |
| | | MsgContent msgContent = new MsgContent(); |
| | | // 消息头 |
| | | RtMsgHeader header = new RtMsgHeader(); |
| | | header.setMsg_id(UUID.randomUUID().toString()); |
| | | header.setTimestamp(System.currentTimeMillis()); |
| | | header.setCmd(RTCmdType.CLOUD_TASK_CONTROL); |
| | | Snowflake snowflake = IdUtil.getSnowflake(0, 0); |
| | | header.setSequence(snowflake.nextId()); |
| | | header.setType(MessageType.MESSAGE_TYPE_RESPONSE); |
| | | msgContent.setHeader(header); |
| | | // 消息内容 |
| | | JSONObject jsonObject = new JSONObject(); |
| | | jsonObject.put("resposne", responseMessage); |
| | | msgContent.setContent_detail(jsonObject); |
| | | log.info("云端-->XPU 响应消息:{}", msgContent); |
| | | HttpRequest post = HttpUtil.createPost(""); |
| | | post.body(JSON.toJSONString(msgContent)); |
| | | HttpResponse execute = post.execute(); |
| | | int status = execute.getStatus(); |
| | | if (200 != status) { |
| | | throw new RuntimeException("XPU 接口异常:" + execute.getStatus()); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | } |