增加萤石云信息推送接口
This commit is contained in:
parent
e949f4ea20
commit
9343e329ba
@ -0,0 +1,113 @@
|
|||||||
|
package com.fastbee.common.model.bto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
@Data
|
||||||
|
public class WebhookMessage implements Serializable {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 消息头
|
||||||
|
*/
|
||||||
|
private WebhookMessageHeader header;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 消息体
|
||||||
|
*/
|
||||||
|
private Object body;
|
||||||
|
|
||||||
|
public WebhookMessage(WebhookMessageHeader header, Object body) {
|
||||||
|
this.header = header;
|
||||||
|
this.body = body;
|
||||||
|
}
|
||||||
|
|
||||||
|
public WebhookMessage() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public WebhookMessageHeader getHeader() {
|
||||||
|
return header;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHeader(WebhookMessageHeader header) {
|
||||||
|
this.header = header;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object getBody() {
|
||||||
|
return body;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBody(Object body) {
|
||||||
|
this.body = body;
|
||||||
|
}
|
||||||
|
|
||||||
|
public class WebhookMessageHeader{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 消息id
|
||||||
|
*/
|
||||||
|
private String messageId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设备序列号
|
||||||
|
*/
|
||||||
|
private String deviceId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 消息类型,需向消息管道服务申请
|
||||||
|
*/
|
||||||
|
private String type;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通道号
|
||||||
|
*/
|
||||||
|
private Integer channelNo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 消息推送时间
|
||||||
|
*/
|
||||||
|
private Long messageTime;
|
||||||
|
|
||||||
|
public WebhookMessageHeader() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMessageId() {
|
||||||
|
return messageId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMessageId(String messageId) {
|
||||||
|
this.messageId = messageId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDeviceId() {
|
||||||
|
return deviceId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDeviceId(String deviceId) {
|
||||||
|
this.deviceId = deviceId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setType(String type) {
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getChannelNo() {
|
||||||
|
return channelNo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setChannelNo(Integer channelNo) {
|
||||||
|
this.channelNo = channelNo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getMessageTime() {
|
||||||
|
return messageTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMessageTime(Long messageTime) {
|
||||||
|
this.messageTime = messageTime;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -129,7 +129,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
|
|||||||
// dueros
|
// dueros
|
||||||
.antMatchers("/dueros").permitAll()
|
.antMatchers("/dueros").permitAll()
|
||||||
//安防小板
|
//安防小板
|
||||||
.antMatchers("/iot/photos","/iot/photos/**").permitAll()
|
.antMatchers("/iot/photos","/iot/photos/**","/yinghsiyun/webhook").permitAll()
|
||||||
|
|
||||||
// 除上面外的所有请求全部需要鉴权认证
|
// 除上面外的所有请求全部需要鉴权认证
|
||||||
.anyRequest().authenticated()
|
.anyRequest().authenticated()
|
||||||
|
@ -0,0 +1,47 @@
|
|||||||
|
package com.fastbee.data.controller.anfang.controller;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.fastbee.common.model.bto.WebhookMessage;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.http.HttpHeaders;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestHeader;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/yinghsiyun")
|
||||||
|
@Api(tags = "萤石云信息推送")
|
||||||
|
public class YingshiMsgRecController {
|
||||||
|
|
||||||
|
@RequestMapping(value = "/webhook")
|
||||||
|
public ResponseEntity<String> webhook(@RequestHeader HttpHeaders header, @RequestBody String body) {
|
||||||
|
final List<String> t = header.get("t");
|
||||||
|
WebhookMessage receiveMessage = null;
|
||||||
|
log.info("消息获取时间:{}, 请求头:{},请求体:{}",System.currentTimeMillis(), JSON.toJSONString(header),body);
|
||||||
|
System.out.println("收到的消息:"+body);
|
||||||
|
try {
|
||||||
|
receiveMessage = JSON.parseObject(body, WebhookMessage.class);
|
||||||
|
//todo:对收到的消息进行处理,最好发送到其他中间件,或者写到数据库中,不要影响回调地址的处理
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
//必须进行返回
|
||||||
|
Map<String, String> result = new HashMap<>(1);
|
||||||
|
assert receiveMessage != null;
|
||||||
|
String messageId = receiveMessage.getHeader().getMessageId();
|
||||||
|
result.put("messageId", messageId);
|
||||||
|
final ResponseEntity<String> resp = ResponseEntity.ok(JSON.toJSONString(result));
|
||||||
|
log.info("返回的信息:{}",JSON.toJSONString(result));
|
||||||
|
return resp;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user