Commit 7206b73a by huangjy

Merge remote-tracking branch 'origin/dev' into dev

parents 948c25e5 13275c8e
......@@ -222,6 +222,13 @@
<version>${weixin-java.version}</version>
</dependency>
<dependency>
<groupId>com.github.binarywang</groupId>
<artifactId>weixin-java-mp</artifactId>
<version>${weixin-java.version}</version>
</dependency>
<!--工作流模块使用-->
<dependency>
<groupId>com.alibaba.fastjson2</groupId>
......
......@@ -173,6 +173,12 @@
<artifactId>weixin-java-miniapp</artifactId>
</dependency>
<!--微信公众号-->
<dependency>
<groupId>com.github.binarywang</groupId>
<artifactId>weixin-java-mp</artifactId>
</dependency>
</dependencies>
<profiles>
......
package com.makeit.utils.msg.config;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
import cn.binarywang.wx.miniapp.config.WxMaConfig;
import cn.binarywang.wx.miniapp.config.impl.WxMaRedissonConfigImpl;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
import me.chanjar.weixin.mp.config.WxMpConfigStorage;
import me.chanjar.weixin.mp.config.impl.WxMpRedissonConfigImpl;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class WxConfig {
@Value("${wx.miniapp.config.appid}")
private String appId;
@Value("${wx.miniapp.config.secret}")
private String appSecret;
@Value("${wx.mp.config.appid}")
private String mpAppId;
@Value("${wx.mp.config.secret}")
private String mpSecret;
@Autowired
private RedissonClient redissonClient;
@Bean
public WxMaService wxMaService(){
WxMaServiceImpl wxMaService = new WxMaServiceImpl();
wxMaService.setWxMaConfig(wxMaConfig());
return wxMaService;
}
public WxMaConfig wxMaConfig(){
WxMaRedissonConfigImpl wxMaRedissonConfig = new WxMaRedissonConfigImpl(redissonClient);
wxMaRedissonConfig.setAppid(appId);
wxMaRedissonConfig.setSecret(appSecret);
return wxMaRedissonConfig;
}
@Bean
public WxMpService wxMpService(){
WxMpServiceImpl wxMpService = new WxMpServiceImpl();
wxMpService.setWxMpConfigStorage(wxMpConfigStorage());
return wxMpService;
}
public WxMpConfigStorage wxMpConfigStorage(){
WxMpRedissonConfigImpl wxMpRedissonConfig = new WxMpRedissonConfigImpl(redissonClient);
wxMpRedissonConfig.setAppId(mpAppId);
wxMpRedissonConfig.setSecret(mpSecret);
return wxMpRedissonConfig;
}
}
package com.makeit.utils.msg.sender;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.hutool.core.date.DateUtil;
import com.makeit.utils.msg.SendTypeEnum;
import com.makeit.utils.msg.dto.MsgSendDTO;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.template.WxMpTemplateData;
import me.chanjar.weixin.mp.bean.template.WxMpTemplateMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
@Component
@Slf4j
public class WxSpSender implements IMsgSender{
@Autowired
private WxMaService wxMaService;
@Autowired
private WxMpService wxMpService;
/**
* 小程序公众号消息
* zn5fBS9cqjnN5UB78tAbm53M3dXufR2b5K1a8mkhXCY
*
* 告警对象{{thing2.DATA}}
* 告警时间{{time3.DATA}}
* 告警地点{{thing4.DATA}}
* 事件类型{{thing8.DATA}}
* 跳转文案点击查看详情
*
* @param msgDTO
*/
@Override
public void send(MsgSendDTO msgDTO) {
List<WxMpTemplateData> mpData = Arrays.asList(
new WxMpTemplateData("thing8", "报警内容"),
new WxMpTemplateData("thing4", "固定值"),
new WxMpTemplateData("thing2", "老人姓名"),
new WxMpTemplateData("time3", DateUtil.format(new Date(),"yyyy-MM-dd HH:mm:ss"))
);
try {
//oBmPb5o9T3q-EMsxfhPg_9OjO5k4 lixl公众号openid
//oM2OI67H11zTZL88X99PxL6rAS3Y
//WxMpUser wxMpUser = wxMpService.getUserService().userInfo("oM2OI6zZQBB-kL6_0kaMM6adVb1E");
//oM2OI6zZQBB-kL6_0kaMM6adVb1E 小程序openId
// WxMpUserList wxMpUserList = wxMpService.getUserService().userList();
//WxMpUser wxMpUser = wxMpService.getUserService().userInfo("oM2OI67H11zTZL88X99PxL6rAS3Y");
WxMpTemplateMessage wxMpTemplateMessage = WxMpTemplateMessage.builder().toUser("oM2OI67H11zTZL88X99PxL6rAS3Y")
.templateId("zn5fBS9cqjnN5UB78tAbm53M3dXufR2b5K1a8mkhXCY")
.data(mpData)
.build();
wxMpService.getTemplateMsgService().sendTemplateMsg(wxMpTemplateMessage);
log.info("发送小程序消息成功");
} catch (WxErrorException e) {
log.error("发送小程序消息失败:",e);
}
}
@Override
public boolean support(SendTypeEnum sendTypeEnum) {
return false;
}
}
package com.makeit.mqtt;
import com.makeit.common.dto.BaseIdDTO;
import com.makeit.common.response.ApiResponseEntity;
import com.makeit.common.response.ApiResponseUtils;
import com.makeit.global.annotation.AuthIgnore;
import com.makeit.utils.msg.dto.MsgSendDTO;
import com.makeit.utils.msg.sender.WxSpSender;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Collections;
@Api(tags = "告警记录2")
@RestController
@RequestMapping("/plat/test")
public class TestAlarmRecordController {
// @Autowired
// private MailMsgSender mailMsgSender;
// @Autowired
// private SmsMsgSender smsMsgSender;
// @Autowired
// private SmsVoiceSender smsVoiceSender;
//
// @ApiOperation("测试邮箱")
// @PostMapping("testMail")
// public ApiResponseEntity<Void> testMail(@RequestBody BaseIdDTO dto) {
// MsgSendDTO msgDTO = new MsgSendDTO();
// msgDTO.setSubject("测试消息");
// msgDTO.setReceiverList(Collections.singletonList("994997968@qq.com"));
// msgDTO.setOriContent("测试发送邮箱");
// mailMsgSender.send(msgDTO);
// return ApiResponseUtils.success();
// }
//
// @ApiOperation("测试短信")
// @PostMapping("testMsg")
// public ApiResponseEntity<Void> testMsg(@RequestBody BaseIdDTO dto) throws Exception {
// MsgSendDTO msgDTO = new MsgSendDTO();
// msgDTO.setReceiverList(Collections.singletonList("18850503603"));
// msgDTO.setOriContent("测试短信test");
// smsMsgSender.send(msgDTO);
// return ApiResponseUtils.success();
// }
//
// @ApiOperation("测试语音短信")
// @PostMapping("testVoice")
// @AuthIgnore
// public ApiResponseEntity<Void> testVoice(@RequestBody BaseIdDTO dto) throws Exception {
// MsgSendDTO msgDTO = new MsgSendDTO();
// msgDTO.setReceiverList(Collections.singletonList("18850503603"));
// msgDTO.setOriContent("测试短信test");
// smsVoiceSender.send(msgDTO);
// return ApiResponseUtils.success();
// }
@Autowired
private WxSpSender wxSpSender;
// @ApiOperation("测试公众号消息")
// @PostMapping("testSp")
// @AuthIgnore
// public ApiResponseEntity<Void> testVoice(@RequestBody BaseIdDTO dto) throws Exception {
// MsgSendDTO msgDTO = new MsgSendDTO();
// msgDTO.setReceiverList(Collections.singletonList("18850503603"));
// msgDTO.setOriContent("测试短信test");
// wxSpSender.send(msgDTO);
// return ApiResponseUtils.success();
// }
@ApiOperation("测试公众号消息")
@PostMapping("testSp")
@AuthIgnore
public ApiResponseEntity<Void> testSpVoice(@RequestBody BaseIdDTO dto) throws Exception {
MsgSendDTO msgDTO = new MsgSendDTO();
msgDTO.setReceiverList(Collections.singletonList("18850503603"));
msgDTO.setOriContent("测试短信test");
wxSpSender.send(msgDTO);
return ApiResponseUtils.success();
}
// @Autowired
// private PushCallback pushCallback;
//
// @ApiOperation("测试跌倒")
// @PostMapping("testFall")
// @AuthIgnore
// public ApiResponseEntity<Void> testVoice(@RequestBody DeviceInfo info) throws Exception {
//
// pushCallback.checkAlarm(info);
// return ApiResponseUtils.success();
// }
//
//
// @Autowired
// private PlatDayDurationRecordService platDayDurationRecordService;
//
// @ApiOperation("测试")
// @PostMapping("test")
// @AuthIgnore
// public ApiResponseEntity<List<PlatDayDurationRecord>> test(@RequestBody DeviceInfo info) throws Exception {
// PlatDayDurationRecord platDayDurationRecord = new PlatDayDurationRecord();
// platDayDurationRecord.setDay(new Date());
// LambdaQueryWrapper<PlatDayDurationRecord> platDayDurationRecordLambdaQueryWrapper = new LambdaQueryWrapper<>();
// platDayDurationRecordLambdaQueryWrapper.eq(PlatDayDurationRecord::getDay,platDayDurationRecord.getDay());
// List<PlatDayDurationRecord> list = platDayDurationRecordService.list();
// return ApiResponseUtils.success(list);
// }
}
......@@ -134,7 +134,10 @@ wx:
token: #微信小程序消息服务器配置的token
aesKey: #微信小程序消息服务器配置的EncodingAESKey
msgDataFormat: JSON
mp:
config:
appid: wx5c73cad7aeb788c6
secret: 7c3a0665bf2adbe67a58a4d6c8017243
sms:
send:
url: http://www.aozoneyun.com/message/message/send
......
......@@ -130,6 +130,10 @@ wx:
token: #微信小程序消息服务器配置的token
aesKey: #微信小程序消息服务器配置的EncodingAESKey
msgDataFormat: JSON
mp:
config:
appid: wx5c73cad7aeb788c6
secret: 7c3a0665bf2adbe67a58a4d6c8017243
sms:
send:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment