first
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
package com.njcn.roma.controller;
|
||||
|
||||
import cn.hutool.crypto.digest.DigestUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.njcn.roma.pojo.CommandDTO;
|
||||
import com.njcn.roma.pojo.UpSendPojo;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* roma
|
||||
*
|
||||
* @author cdf
|
||||
* @date 2024/6/25
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("send")
|
||||
@RequiredArgsConstructor
|
||||
public class SendCommandController {
|
||||
|
||||
@Value("${roma.acceptIp}")
|
||||
private String acceptIp;
|
||||
|
||||
@Value("${roma.sendIp}")
|
||||
private String sendIp;
|
||||
|
||||
@Value("${roma.appId}")
|
||||
private String appId;
|
||||
|
||||
@Value("${roma.appKey}")
|
||||
private String appKey;
|
||||
|
||||
private final RestTemplate restTemplate;
|
||||
|
||||
/**
|
||||
* 测试下发程序
|
||||
* @author cdf
|
||||
* @date 2024/6/25
|
||||
*/
|
||||
@GetMapping("up")
|
||||
public String sendToDev(){
|
||||
String time = String.valueOf(new Date().getTime());
|
||||
String sha = DigestUtil.sha256Hex(appId+appKey+time);
|
||||
System.out.println("加密秘钥"+sha);
|
||||
|
||||
// 请求头信息
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setContentType(MediaType.valueOf("application/json;charset=UTF-8"));
|
||||
headers.add("timestamp",time);
|
||||
headers.add("Authorization",sha);
|
||||
|
||||
// 请求体内容
|
||||
UpSendPojo param = new UpSendPojo();
|
||||
param.setDeviceId("666666");
|
||||
|
||||
CommandDTO commandDTO = new CommandDTO();
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("","");
|
||||
commandDTO.setJsonObject(jsonObject);
|
||||
commandDTO.setServiceId("123");
|
||||
commandDTO.setMethod("aaa");
|
||||
param.setCommandDTO(commandDTO);
|
||||
|
||||
// 组装请求信息
|
||||
HttpEntity<UpSendPojo> httpEntity=new HttpEntity<>(param,headers);
|
||||
|
||||
System.out.println(httpEntity.getHeaders());
|
||||
System.out.println(httpEntity.getBody());
|
||||
|
||||
|
||||
ResponseEntity responseEntity = restTemplate.postForEntity(sendIp,httpEntity,String.class);
|
||||
System.out.println("返回状态:"+ responseEntity.getStatusCode());
|
||||
return Objects.requireNonNull(responseEntity.getBody()).toString();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@GetMapping("test")
|
||||
public String test(){
|
||||
return "6666";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user