20260228:联通微信梳理
This commit is contained in:
parent
4e7d595893
commit
0ad130fcc2
@ -21,6 +21,10 @@ public class AlertPushParams {
|
|||||||
* 告警时间
|
* 告警时间
|
||||||
*/
|
*/
|
||||||
private String alertTime;
|
private String alertTime;
|
||||||
|
/**
|
||||||
|
* 设备ID
|
||||||
|
*/
|
||||||
|
private Long deviceId;
|
||||||
/**
|
/**
|
||||||
* 设备名称
|
* 设备名称
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -26,6 +26,9 @@ public class ThingsModelSimpleItem {
|
|||||||
*/
|
*/
|
||||||
private String value;
|
private String value;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 物模型名称
|
||||||
|
*/
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -14,12 +14,19 @@ public class ThingsModelValuesInput {
|
|||||||
**/
|
**/
|
||||||
private Long productId;
|
private Long productId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设备ID
|
||||||
|
**/
|
||||||
private Long deviceId;
|
private Long deviceId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设备ID
|
* 设备ID
|
||||||
**/
|
**/
|
||||||
private String deviceNumber;
|
private String deviceNumber;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设备类型
|
||||||
|
**/
|
||||||
private Integer deviceType;
|
private Integer deviceType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -27,11 +34,6 @@ public class ThingsModelValuesInput {
|
|||||||
**/
|
**/
|
||||||
private List<ThingsModelSimpleItem> thingsModelSimpleItem;
|
private List<ThingsModelSimpleItem> thingsModelSimpleItem;
|
||||||
|
|
||||||
/**
|
|
||||||
* 原始消息数据包(用于判断设备上电触发回包等)
|
|
||||||
**/
|
|
||||||
private Object sources;
|
|
||||||
|
|
||||||
public Long getDeviceId() {
|
public Long getDeviceId() {
|
||||||
return deviceId;
|
return deviceId;
|
||||||
}
|
}
|
||||||
@ -63,12 +65,4 @@ public class ThingsModelValuesInput {
|
|||||||
public void setThingsModelValueRemarkItem(List<ThingsModelSimpleItem> thingsModelSimpleItem) {
|
public void setThingsModelValueRemarkItem(List<ThingsModelSimpleItem> thingsModelSimpleItem) {
|
||||||
this.thingsModelSimpleItem = thingsModelSimpleItem;
|
this.thingsModelSimpleItem = thingsModelSimpleItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object getSources() {
|
|
||||||
return sources;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSources(Object sources) {
|
|
||||||
this.sources = sources;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -95,15 +95,12 @@ public class SceneContext {
|
|||||||
scene_logger.info("[{}]=====+>场景联动规则开始执行!", requestId);
|
scene_logger.info("[{}]=====+>场景联动规则开始执行!", requestId);
|
||||||
scene_logger.info("[{}]=====+>规则引擎脚本配置:{},规则引擎上下文:{}", requestId, scriptTemplate, this);
|
scene_logger.info("[{}]=====+>规则引擎脚本配置:{},规则引擎上下文:{}", requestId, scriptTemplate, this);
|
||||||
//MDC.put("id", scriptTemplate.getChainName());
|
//MDC.put("id", scriptTemplate.getChainName());
|
||||||
//触发器
|
// 触发器
|
||||||
if (scriptTemplate.getPurpose() == 2) {
|
if (scriptTemplate.getPurpose() == 2) {
|
||||||
// 触发器,检查静默时间
|
// 触发器,检查静默时间
|
||||||
if (!checkSilent(scriptTemplate.getSilent(), scriptTemplate.getSceneId(), requestId, this.deviceNum)) {
|
if (!checkSilent(scriptTemplate.getSilent(), scriptTemplate.getSceneId(), requestId, this.deviceNum)) {
|
||||||
// 触发条件为不满足时,返回true
|
// 触发条件为不满足时,返回true
|
||||||
if (scriptTemplate.getCond() == 3) {
|
return scriptTemplate.getCond() == 3;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
if (scriptTemplate.getSource() == 1) {
|
if (scriptTemplate.getSource() == 1) {
|
||||||
// 设备触发
|
// 设备触发
|
||||||
@ -112,7 +109,7 @@ public class SceneContext {
|
|||||||
// 产品触发
|
// 产品触发
|
||||||
return productTrigger(scriptTemplate);
|
return productTrigger(scriptTemplate);
|
||||||
}
|
}
|
||||||
//执行动作
|
// 执行动作
|
||||||
} else if (scriptTemplate.getPurpose() == 3) {
|
} else if (scriptTemplate.getPurpose() == 3) {
|
||||||
scene_logger.info("[{}]=====+>符合触发条件!", requestId);
|
scene_logger.info("[{}]=====+>符合触发条件!", requestId);
|
||||||
if (scriptTemplate.getCheckdelay() != 0) {
|
if (scriptTemplate.getCheckdelay() != 0) {
|
||||||
@ -122,9 +119,9 @@ public class SceneContext {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// 执行动作,延迟执行,线程休眠 delay x 1000毫秒
|
// 执行动作,延迟执行,线程休眠 delay x 1000毫秒
|
||||||
Thread.sleep(scriptTemplate.getDelay() * 1000);
|
Thread.sleep(scriptTemplate.getDelay() * 1000L);
|
||||||
if (scriptTemplate.getSource() == 4) {
|
if (scriptTemplate.getSource() == 4) {
|
||||||
//存在相同未处理告警只记录 不触发告警通知和动作
|
// 存在相同未处理告警只记录 不触发告警通知和动作
|
||||||
if (checkDeviceAlerting(scriptTemplate.getSceneId(), requestId, this.deviceNum)) {
|
if (checkDeviceAlerting(scriptTemplate.getSceneId(), requestId, this.deviceNum)) {
|
||||||
this.alert(scriptTemplate.getSceneId(), false);
|
this.alert(scriptTemplate.getSceneId(), false);
|
||||||
} else {
|
} else {
|
||||||
@ -151,7 +148,7 @@ public class SceneContext {
|
|||||||
private boolean deviceTrigger(ScriptTemplate scriptTemplate) {
|
private boolean deviceTrigger(ScriptTemplate scriptTemplate) {
|
||||||
String requestId = "scene/" + scriptTemplate.getChainName();
|
String requestId = "scene/" + scriptTemplate.getChainName();
|
||||||
// 判断定制触发(执行一次)或设备上报
|
// 判断定制触发(执行一次)或设备上报
|
||||||
boolean isDeviceReport = StringUtils.isEmpty(deviceNum) ? false : true;
|
boolean isDeviceReport = !StringUtils.isEmpty(deviceNum);
|
||||||
if (isDeviceReport) {
|
if (isDeviceReport) {
|
||||||
// 1. 匹配设备编号
|
// 1. 匹配设备编号
|
||||||
scene_logger.info("[{}]=====+>设备触发!", requestId);
|
scene_logger.info("[{}]=====+>设备触发!", requestId);
|
||||||
@ -176,10 +173,7 @@ public class SceneContext {
|
|||||||
scriptTemplate.getScriptId(), scriptTemplate.getSceneId(), scriptTemplate.getProductId(), deviceNum, matchItem.getRemark());
|
scriptTemplate.getScriptId(), scriptTemplate.getSceneId(), scriptTemplate.getProductId(), deviceNum, matchItem.getRemark());
|
||||||
sceneThingsModelItems.add(sceneItem);
|
sceneThingsModelItems.add(sceneItem);
|
||||||
// 3.设备上报值匹配
|
// 3.设备上报值匹配
|
||||||
boolean isMatch = matchValue(requestId, scriptTemplate.getOperator(), scriptTemplate.getValue(), matchItem.getValue());
|
return matchValue(requestId, scriptTemplate.getOperator(), scriptTemplate.getValue(), matchItem.getValue());
|
||||||
if (isMatch) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@ -208,7 +202,7 @@ public class SceneContext {
|
|||||||
// 定时触发/执行一次
|
// 定时触发/执行一次
|
||||||
int resultCount = 0;
|
int resultCount = 0;
|
||||||
// 3.查询设备最新上报值去匹配
|
// 3.查询设备最新上报值去匹配
|
||||||
for (String num : Arrays.asList(scriptTemplate.getDeviceNums().split(","))) {
|
for (String num : scriptTemplate.getDeviceNums().split(",")) {
|
||||||
// 数组类型,key去除前缀,值从逗号分隔的字符串获取
|
// 数组类型,key去除前缀,值从逗号分隔的字符串获取
|
||||||
String id = "";
|
String id = "";
|
||||||
String value = "";
|
String value = "";
|
||||||
@ -248,7 +242,7 @@ public class SceneContext {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 任意设备匹配成功返回true
|
// 任意设备匹配成功返回true
|
||||||
return resultCount > 0 ? true : false;
|
return resultCount > 0;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -286,10 +280,7 @@ public class SceneContext {
|
|||||||
scriptTemplate.getScriptId(), scriptTemplate.getSceneId(), scriptTemplate.getProductId(), deviceNum, matchItem.getRemark());
|
scriptTemplate.getScriptId(), scriptTemplate.getSceneId(), scriptTemplate.getProductId(), deviceNum, matchItem.getRemark());
|
||||||
sceneThingsModelItems.add(sceneItem);
|
sceneThingsModelItems.add(sceneItem);
|
||||||
// 设备上报值匹配
|
// 设备上报值匹配
|
||||||
boolean isMatch = matchValue(requestId, scriptTemplate.getOperator(), scriptTemplate.getValue(), matchItem.getValue());
|
return matchValue(requestId, scriptTemplate.getOperator(), scriptTemplate.getValue(), matchItem.getValue());
|
||||||
if (isMatch) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@ -359,7 +350,7 @@ public class SceneContext {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 任意设备匹配成功返回true
|
// 任意设备匹配成功返回true
|
||||||
return resultCount > 0 ? true : false;
|
return resultCount > 0;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -367,10 +358,10 @@ public class SceneContext {
|
|||||||
private void loadDelayTrigger(ScriptTemplate scriptTemplate) {
|
private void loadDelayTrigger(ScriptTemplate scriptTemplate) {
|
||||||
String requestId = "scene/" + scriptTemplate.getChainName();
|
String requestId = "scene/" + scriptTemplate.getChainName();
|
||||||
String key = "CHECK_" + scriptTemplate.getSceneId() + deviceNum;
|
String key = "CHECK_" + scriptTemplate.getSceneId() + deviceNum;
|
||||||
//默认上线执行告警恢复 在延迟匹配周期内不告警
|
// 默认上线执行告警恢复 在延迟匹配周期内不告警
|
||||||
ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
|
ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
|
||||||
executor.schedule(() -> {
|
executor.schedule(() -> {
|
||||||
//设备未上线,则执行告警任务
|
// 设备未上线,则执行告警任务
|
||||||
if (scriptTemplate.getSource() == 4) {
|
if (scriptTemplate.getSource() == 4) {
|
||||||
// 告警
|
// 告警
|
||||||
this.alert(scriptTemplate.getSceneId(), true);
|
this.alert(scriptTemplate.getSceneId(), true);
|
||||||
@ -449,7 +440,7 @@ public class SceneContext {
|
|||||||
*
|
*
|
||||||
* @param sceneId 场景ID
|
* @param sceneId 场景ID
|
||||||
*/
|
*/
|
||||||
private void alert(Long sceneId, boolean isNodify) {
|
private void alert(Long sceneId, boolean isNotify) {
|
||||||
Set<Long> sceneIdSet = sceneThingsModelItems.stream().map(SceneThingsModelItem::getSceneId).collect(Collectors.toSet());
|
Set<Long> sceneIdSet = sceneThingsModelItems.stream().map(SceneThingsModelItem::getSceneId).collect(Collectors.toSet());
|
||||||
List<SceneTerminalUserVO> sceneTerminalUserVOList = sceneService.selectTerminalUserBySceneIds(sceneIdSet);
|
List<SceneTerminalUserVO> sceneTerminalUserVOList = sceneService.selectTerminalUserBySceneIds(sceneIdSet);
|
||||||
Map<Long, SceneTerminalUserVO> sceneTerminalUserMap = sceneTerminalUserVOList.stream().collect(Collectors.toMap(SceneTerminalUserVO::getSceneId, Function.identity()));
|
Map<Long, SceneTerminalUserVO> sceneTerminalUserMap = sceneTerminalUserVOList.stream().collect(Collectors.toMap(SceneTerminalUserVO::getSceneId, Function.identity()));
|
||||||
@ -475,7 +466,7 @@ public class SceneContext {
|
|||||||
// 获取告警关联模版id
|
// 获取告警关联模版id
|
||||||
for (AlertSceneSendVO alertSceneSendVO : sceneSendVOList) {
|
for (AlertSceneSendVO alertSceneSendVO : sceneSendVOList) {
|
||||||
// 开启通知发送
|
// 开启通知发送
|
||||||
if (isNodify) {
|
if (isNotify) {
|
||||||
AlertPushParams alertPushParams = buildAlertPushParams(device, sceneThingsModelItem);
|
AlertPushParams alertPushParams = buildAlertPushParams(device, sceneThingsModelItem);
|
||||||
List<AlertNotifyTemplate> alertNotifyTemplateList = alertService.listAlertNotifyTemplate(alertSceneSendVO.getAlertId());
|
List<AlertNotifyTemplate> alertNotifyTemplateList = alertService.listAlertNotifyTemplate(alertSceneSendVO.getAlertId());
|
||||||
alertPushParams.setAlertName(alertSceneSendVO.getAlertName());
|
alertPushParams.setAlertName(alertSceneSendVO.getAlertName());
|
||||||
@ -497,6 +488,7 @@ public class SceneContext {
|
|||||||
private AlertPushParams buildAlertPushParams(Device device, SceneThingsModelItem sceneThingsModelItem) {
|
private AlertPushParams buildAlertPushParams(Device device, SceneThingsModelItem sceneThingsModelItem) {
|
||||||
// 获取告警推送参数
|
// 获取告警推送参数
|
||||||
AlertPushParams alertPushParams = new AlertPushParams();
|
AlertPushParams alertPushParams = new AlertPushParams();
|
||||||
|
alertPushParams.setDeviceId(device.getDeviceId());
|
||||||
alertPushParams.setDeviceName(device.getDeviceName());
|
alertPushParams.setDeviceName(device.getDeviceName());
|
||||||
alertPushParams.setSerialNumber(sceneThingsModelItem.getDeviceNumber());
|
alertPushParams.setSerialNumber(sceneThingsModelItem.getDeviceNumber());
|
||||||
// List<DeviceUser> deviceUserList = deviceUserService.getDeviceUserAndShare(device.getDeviceId());
|
// List<DeviceUser> deviceUserList = deviceUserService.getDeviceUserAndShare(device.getDeviceId());
|
||||||
@ -649,6 +641,7 @@ public class SceneContext {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// silent:scene_场景编号
|
// silent:scene_场景编号
|
||||||
|
scene_logger.info("[{}]=====+>检查静默时间!", requestId);
|
||||||
String key = "silent:" + "scene_" + sceneId + ":" + serialNumber;
|
String key = "silent:" + "scene_" + sceneId + ":" + serialNumber;
|
||||||
Calendar calendar = Calendar.getInstance();
|
Calendar calendar = Calendar.getInstance();
|
||||||
// 查询静默截止时间
|
// 查询静默截止时间
|
||||||
@ -657,16 +650,10 @@ public class SceneContext {
|
|||||||
// 添加场景静默时间
|
// 添加场景静默时间
|
||||||
calendar.add(Calendar.MINUTE, silent);
|
calendar.add(Calendar.MINUTE, silent);
|
||||||
redisCache.setCacheObject(key, calendar.getTimeInMillis());
|
redisCache.setCacheObject(key, calendar.getTimeInMillis());
|
||||||
scene_logger.info("[{}]=====+>检查静默时间!", requestId);
|
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
Long NowTimestamp = Calendar.getInstance().getTimeInMillis();
|
long NowTimestamp = Calendar.getInstance().getTimeInMillis();
|
||||||
if (NowTimestamp > expireTime) {
|
return NowTimestamp > expireTime;
|
||||||
scene_logger.info("[{}]=====+>检查静默时间!", requestId);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
scene_logger.info("[{}]=====+>检查静默时间!", requestId);
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -96,14 +96,12 @@ public class DataHandlerImpl implements IDataHandler {
|
|||||||
// 这里上报设备编号是转的大写,后面存缓存也是使用大写的,所以在查询物模型的值时添加把设备编号转大写后取值
|
// 这里上报设备编号是转的大写,后面存缓存也是使用大写的,所以在查询物模型的值时添加把设备编号转大写后取值
|
||||||
input.setDeviceNumber(bo.getSerialNumber().toUpperCase());
|
input.setDeviceNumber(bo.getSerialNumber().toUpperCase());
|
||||||
input.setThingsModelValueRemarkItem(thingsModelSimpleItems);
|
input.setThingsModelValueRemarkItem(thingsModelSimpleItems);
|
||||||
// 传递原始消息数据包,用于判断设备上电触发回包等
|
|
||||||
input.setSources(bo.getSources());
|
|
||||||
List<ThingsModelSimpleItem> result = deviceService.reportDeviceThingsModelValue(input, bo.getType(), bo.isShadow());
|
List<ThingsModelSimpleItem> result = deviceService.reportDeviceThingsModelValue(input, bo.getType(), bo.isShadow());
|
||||||
// 只有设备上报进入规则引擎流程
|
// todo 只有设备上报进入规则引擎流程
|
||||||
if (bo.isRuleEngine() && !bo.getSerialNumber().startsWith("server-")) {
|
if (bo.isRuleEngine() && !bo.getSerialNumber().startsWith("server-")) {
|
||||||
ruleEngine.ruleMatch(bo);
|
ruleEngine.ruleMatch(bo);
|
||||||
}
|
}
|
||||||
//发送至前端
|
// 发送至前端
|
||||||
PushMessageBo messageBo = new PushMessageBo();
|
PushMessageBo messageBo = new PushMessageBo();
|
||||||
messageBo.setTopic(topicsUtils.buildTopic(bo.getProductId(), bo.getSerialNumber(), TopicType.WS_SERVICE_INVOKE));
|
messageBo.setTopic(topicsUtils.buildTopic(bo.getProductId(), bo.getSerialNumber(), TopicType.WS_SERVICE_INVOKE));
|
||||||
JSONObject pushObj = new JSONObject();
|
JSONObject pushObj = new JSONObject();
|
||||||
|
|||||||
@ -299,7 +299,7 @@ public class DeviceReportMessageServiceImpl implements IDeviceReportMessageServi
|
|||||||
report.setDeviceName(message.getDeviceName());
|
report.setDeviceName(message.getDeviceName());
|
||||||
report.setSources(message.getSources());
|
report.setSources(message.getSources());
|
||||||
report.setGwDeviceBo(message.getGwDeviceBo());
|
report.setGwDeviceBo(message.getGwDeviceBo());
|
||||||
//属性上报执行规则引擎
|
// 属性上报执行规则引擎
|
||||||
report.setRuleEngine(true);
|
report.setRuleEngine(true);
|
||||||
dataHandler.reportData(report);
|
dataHandler.reportData(report);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -47,7 +47,7 @@ public class RuleEngineHandler implements IRuleEngine {
|
|||||||
// 场景联动处理
|
// 场景联动处理
|
||||||
this.sceneProcess(bo);
|
this.sceneProcess(bo);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("场景联动规则执行异常 message={}", e, e.getMessage());
|
log.error("场景联动规则执行异常 message={}", e.getMessage(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -140,6 +140,7 @@ public class NotifySendServiceImpl implements NotifySendService {
|
|||||||
NotifyChannel notifyChannel = notifyChannelService.selectNotifyChannelById(notifyTemplate.getChannelId());
|
NotifyChannel notifyChannel = notifyChannelService.selectNotifyChannelById(notifyTemplate.getChannelId());
|
||||||
NotifyChannelProviderEnum notifyChannelProviderEnum = NotifyChannelProviderEnum.getByChannelTypeAndProvider(notifyChannel.getChannelType(), notifyChannel.getProvider());
|
NotifyChannelProviderEnum notifyChannelProviderEnum = NotifyChannelProviderEnum.getByChannelTypeAndProvider(notifyChannel.getChannelType(), notifyChannel.getProvider());
|
||||||
NotifyVO notifyVO = new NotifyVO();
|
NotifyVO notifyVO = new NotifyVO();
|
||||||
|
notifyVO.setDeviceId(alertPushParams.getDeviceId());
|
||||||
notifyVO.setNotifyChannel(notifyChannel).setNotifyTemplate(notifyTemplate).setNotifyChannelProviderEnum(notifyChannelProviderEnum);
|
notifyVO.setNotifyChannel(notifyChannel).setNotifyTemplate(notifyTemplate).setNotifyChannelProviderEnum(notifyChannelProviderEnum);
|
||||||
// 获取模版参数
|
// 获取模版参数
|
||||||
JSONObject jsonMsgParams = JSONObject.parseObject(notifyVO.getNotifyTemplate().getMsgParams());
|
JSONObject jsonMsgParams = JSONObject.parseObject(notifyVO.getNotifyTemplate().getMsgParams());
|
||||||
|
|||||||
@ -120,7 +120,8 @@ public class WeChatPushServiceImpl implements WeChatPushService {
|
|||||||
weChatPublicAccountPushVO.setData(sendMap);
|
weChatPublicAccountPushVO.setData(sendMap);
|
||||||
weChatPublicAccountPushVO.setTemplateId(wechatMsgParams.getTemplateId());
|
weChatPublicAccountPushVO.setTemplateId(wechatMsgParams.getTemplateId());
|
||||||
if (StringUtils.isNotEmpty(wechatMsgParams.getRedirectUrl())) {
|
if (StringUtils.isNotEmpty(wechatMsgParams.getRedirectUrl())) {
|
||||||
weChatPublicAccountPushVO.setUrl(wechatMsgParams.getRedirectUrl());
|
String redirectUrl = wechatMsgParams.getRedirectUrl() + "pagesA/home/device/index?deviceId=" + notifyVO.getDeviceId();
|
||||||
|
weChatPublicAccountPushVO.setUrl(redirectUrl);
|
||||||
}
|
}
|
||||||
if (StringUtils.isNotEmpty(wechatMsgParams.getPagePath())) {
|
if (StringUtils.isNotEmpty(wechatMsgParams.getPagePath())) {
|
||||||
WeChatPublicAccountPushVO.MiniProgram miniProgram = new WeChatPublicAccountPushVO.MiniProgram();
|
WeChatPublicAccountPushVO.MiniProgram miniProgram = new WeChatPublicAccountPushVO.MiniProgram();
|
||||||
|
|||||||
@ -18,8 +18,14 @@ import java.util.LinkedHashMap;
|
|||||||
@Accessors(chain = true)
|
@Accessors(chain = true)
|
||||||
public class NotifyVO {
|
public class NotifyVO {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通知渠道
|
||||||
|
*/
|
||||||
private NotifyChannel notifyChannel;
|
private NotifyChannel notifyChannel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通知模版
|
||||||
|
*/
|
||||||
private NotifyTemplate notifyTemplate;
|
private NotifyTemplate notifyTemplate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -27,7 +33,18 @@ public class NotifyVO {
|
|||||||
*/
|
*/
|
||||||
private String sendAccount;
|
private String sendAccount;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 模板参数
|
||||||
|
*/
|
||||||
private LinkedHashMap<String, String> map;
|
private LinkedHashMap<String, String> map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设备ID(用于精准跳转到设备详情页面)
|
||||||
|
*/
|
||||||
|
private Long deviceId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通道类型枚举
|
||||||
|
*/
|
||||||
private NotifyChannelProviderEnum notifyChannelProviderEnum;
|
private NotifyChannelProviderEnum notifyChannelProviderEnum;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -151,7 +151,7 @@ public class WeChatController {
|
|||||||
// 随机字符串
|
// 随机字符串
|
||||||
String echostr = request.getParameter("echostr");
|
String echostr = request.getParameter("echostr");
|
||||||
// token
|
// token
|
||||||
String token = "fastbee";
|
String token = "yackfastbeeiot";
|
||||||
boolean check = SignUtils.checkSignature(token, signature, timestamp, nonce);
|
boolean check = SignUtils.checkSignature(token, signature, timestamp, nonce);
|
||||||
PrintWriter writer = response.getWriter();
|
PrintWriter writer = response.getWriter();
|
||||||
if (check) {
|
if (check) {
|
||||||
@ -175,7 +175,7 @@ public class WeChatController {
|
|||||||
response.setContentType("text/html;charset=utf-8");
|
response.setContentType("text/html;charset=utf-8");
|
||||||
response.getWriter().write(responseStr);
|
response.getWriter().write(responseStr);
|
||||||
} catch (final IOException e) {
|
} catch (final IOException e) {
|
||||||
log.error("微信回调回复信息回写失败:xmlStr:{},responseStr:{},e:{}", xmlStr, responseStr, e);
|
log.error("微信回调回复信息回写失败:xmlStr:{},responseStr:{},e:", xmlStr, responseStr, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -5,7 +5,7 @@ import cn.hutool.core.util.XmlUtil;
|
|||||||
import com.alibaba.fastjson2.JSON;
|
import com.alibaba.fastjson2.JSON;
|
||||||
import com.alibaba.fastjson2.JSONObject;
|
import com.alibaba.fastjson2.JSONObject;
|
||||||
import com.fastbee.common.enums.SocialPlatformType;
|
import com.fastbee.common.enums.SocialPlatformType;
|
||||||
import com.fastbee.common.utils.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import com.fastbee.common.utils.uuid.IdUtils;
|
import com.fastbee.common.utils.uuid.IdUtils;
|
||||||
import com.fastbee.common.utils.wechat.WechatUtils;
|
import com.fastbee.common.utils.wechat.WechatUtils;
|
||||||
import com.fastbee.common.wechat.WeChatAppResult;
|
import com.fastbee.common.wechat.WeChatAppResult;
|
||||||
@ -20,7 +20,6 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.Date;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -46,7 +45,7 @@ public class WeChatCallbackServiceImpl implements WeChatCallbackService {
|
|||||||
Map<String, Object> map = XmlUtil.xmlToMap(xmlStr);
|
Map<String, Object> map = XmlUtil.xmlToMap(xmlStr);
|
||||||
wxCallBackXmlBO = JSONObject.parseObject(JSON.toJSONString(map), WxCallBackXmlBO.class);
|
wxCallBackXmlBO = JSONObject.parseObject(JSON.toJSONString(map), WxCallBackXmlBO.class);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("微信回调传递的xml解析报错:{},{}", xmlStr, e);
|
log.error("微信回调传递的xml解析报错:{},e:", xmlStr, e);
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
if (ObjectUtil.isNull(wxCallBackXmlBO) || StringUtils.isEmpty(wxCallBackXmlBO.getMsgType())) {
|
if (ObjectUtil.isNull(wxCallBackXmlBO) || StringUtils.isEmpty(wxCallBackXmlBO.getMsgType())) {
|
||||||
@ -79,10 +78,10 @@ public class WeChatCallbackServiceImpl implements WeChatCallbackService {
|
|||||||
|
|
||||||
private String handleEvent(WxCallBackXmlBO wxCallBackXmlBo) {
|
private String handleEvent(WxCallBackXmlBO wxCallBackXmlBo) {
|
||||||
String resMsg = "";
|
String resMsg = "";
|
||||||
//事件类型
|
// 事件类型
|
||||||
String eventStr = wxCallBackXmlBo.getEvent();
|
String eventStr = wxCallBackXmlBo.getEvent();
|
||||||
if (org.apache.commons.lang3.StringUtils.isNotBlank(eventStr)) {
|
if (StringUtils.isNotBlank(eventStr)) {
|
||||||
switch (org.apache.commons.lang3.StringUtils.lowerCase(eventStr)) {
|
switch (StringUtils.lowerCase(eventStr)) {
|
||||||
// 关键词
|
// 关键词
|
||||||
case "click":
|
case "click":
|
||||||
break;
|
break;
|
||||||
@ -114,7 +113,7 @@ public class WeChatCallbackServiceImpl implements WeChatCallbackService {
|
|||||||
private String handleEventSubscribe(WxCallBackXmlBO wxCallBackXmlBo) {
|
private String handleEventSubscribe(WxCallBackXmlBO wxCallBackXmlBo) {
|
||||||
// 获取微信公众号appid和secret
|
// 获取微信公众号appid和secret
|
||||||
String sourceClient = SocialPlatformType.WECHAT_OPEN_PUBLIC_ACCOUNT.getSourceClient();
|
String sourceClient = SocialPlatformType.WECHAT_OPEN_PUBLIC_ACCOUNT.getSourceClient();
|
||||||
SocialPlatform socialPlatform = socialPlatformService.selectSocialPlatformByPlatform(SocialPlatformType.WECHAT_OPEN_PUBLIC_ACCOUNT.getSourceClient());
|
SocialPlatform socialPlatform = socialPlatformService.selectSocialPlatformByPlatform(sourceClient);
|
||||||
if (ObjectUtil.isNull(socialPlatform)) {
|
if (ObjectUtil.isNull(socialPlatform)) {
|
||||||
log.info("请先配置微信开放平台公众号!");
|
log.info("请先配置微信开放平台公众号!");
|
||||||
return "";
|
return "";
|
||||||
@ -137,10 +136,17 @@ public class WeChatCallbackServiceImpl implements WeChatCallbackService {
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
SocialUser socialUser = new SocialUser();
|
SocialUser socialUser = new SocialUser();
|
||||||
socialUser.setStatus("1").setSource(sourceClient).setSourceClient(sourceClient).setOpenId(openId)
|
socialUser.setStatus("1")
|
||||||
.setUnionId(weChatUserInfo.getUnionId()).setAccessToken(accessToken).setAvatar(weChatUserInfo.getHeadImgUrl())
|
.setSource(sourceClient)
|
||||||
.setNickname(weChatUserInfo.getNickname()).setUuid(IdUtils.randomUUID()).setCreateBy("System");
|
.setSourceClient(sourceClient)
|
||||||
socialUser.setCreateTime(new Date());
|
.setOpenId(openId)
|
||||||
|
.setUnionId(weChatUserInfo.getUnionId())
|
||||||
|
.setAccessToken(accessToken)
|
||||||
|
.setAvatar(weChatUserInfo.getHeadImgUrl())
|
||||||
|
.setNickname(weChatUserInfo.getNickname())
|
||||||
|
.setUuid(IdUtils.randomUUID())
|
||||||
|
.setCreateBy("System");
|
||||||
|
//socialUser.setCreateTime(new Date());
|
||||||
socialUserService.insertSocialUser(socialUser);
|
socialUserService.insertSocialUser(socialUser);
|
||||||
// 返回消息
|
// 返回消息
|
||||||
return WechatUtils.responseText(wxCallBackXmlBo, socialPlatform.getRemark());
|
return WechatUtils.responseText(wxCallBackXmlBo, socialPlatform.getRemark());
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user