Commit d041bf87 by 李小龙

短信接口

parent d4a88a98
package com.makeit.utils.msg.config;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
@Data
@ConfigurationProperties("sms.send")
@Configuration
public class SmsConfig {
private String url;
private String uid;
private String pwd;
}
......@@ -33,11 +33,6 @@ public class MsgDTO {
this.param = param;
}
public String getSendContent() {
replaceParam();
return sendContent;
}
private void replaceParam(){
if(StringUtils.isNotBlank(sendContent)){
return;
......
package com.makeit.utils.msg.sender;
import com.makeit.utils.msg.dto.MsgDTO;
import com.makeit.utils.msg.dto.SendResult;
public interface IMsgSender {
......@@ -9,5 +8,5 @@ public interface IMsgSender {
* 发送消息
* @param msgData 消息数据
*/
SendResult send(MsgDTO MsgDTO);
void send(MsgDTO MsgDTO) throws Exception;
}
package com.makeit.utils.msg.sender;
import com.makeit.exception.BusinessException;
import com.makeit.utils.msg.dto.MsgDTO;
import com.makeit.utils.msg.dto.SendResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
......@@ -25,8 +25,7 @@ public class MailMsgSender implements IMsgSender {
@Override
public SendResult send(MsgDTO msgDTO) {
SendResult sendResult = new SendResult();
public void send(MsgDTO msgDTO) {
try {
MimeMessage message = mailSender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(message, true);
......@@ -36,12 +35,8 @@ public class MailMsgSender implements IMsgSender {
helper.setText(msgDTO.getOriContent(), false);
mailSender.send(message);
} catch (Exception e) {
sendResult.setSuccess(false);
sendResult.setInfo(e.getMessage());
throw new BusinessException(e.getMessage());
}
sendResult.setSuccess(true);
return sendResult;
}
}
package com.makeit.utils.msg.sender;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.makeit.exception.BusinessException;
import com.makeit.utils.msg.config.SmsConfig;
import com.makeit.utils.msg.dto.MsgDTO;
import com.makeit.utils.old.encode.CryptoUtil;
import com.makeit.utils.third.HttpClient;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.stereotype.Component;
import java.net.URLEncoder;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors;
@Component
public class SmsMsgSender implements IMsgSender{
@Autowired
private SmsConfig smsConfig;
/**
* 发送消息
*
* @param msgDTO
*/
@Override
public void send(MsgDTO msgDTO) throws Exception {
try {
Date now = new Date();
String time = String.valueOf(now.getTime());
List<String> receiverList = msgDTO.getReceiverList();
String receiverJoin = receiverList.stream().collect(Collectors.joining(","));
HashMap<String, String> paramMap = new HashMap<>();
paramMap.put("uid", smsConfig.getUid() + 1000);
//md5-32位( md5-16位(登录密码)+ time )
String md16 = CryptoUtil.md5_16(smsConfig.getPwd());
String md32 = CryptoUtil.md5(md16 + time);
paramMap.put("pwd", md32);
paramMap.put("time", time);
paramMap.put("mobile", receiverJoin);
paramMap.put("content", URLEncoder.encode(msgDTO.getOriContent(), "UTF-8"));
String resStr = HttpClient.sendJSONPostRequest(smsConfig.getUrl(), paramMap, new HttpHeaders(), String.class);
JSONObject jsonObject = JSON.parseObject(resStr);
String status = (String) jsonObject.get("status");
if (!StringUtils.equals(status, "0")) {
throw new BusinessException((String) jsonObject.get("status_code"));
}
}catch (Exception e){
throw new BusinessException(e.getMessage());
}
}
}
......@@ -301,7 +301,8 @@ public class CryptoUtil {
// 3 计算后获得字节数组,这就是那128位了
byte[] buff = md.digest(input);
// 4 把数组每一字节(一个字节占八位)换成16进制连成md5字符串
return bytesToHex(buff).substring(8, 24);
String bytesToHex = bytesToHex(buff);
return bytesToHex.substring(8, 24);
} catch (Exception e) {
throw ExceptionUtil.unchecked(e);
}
......@@ -330,6 +331,6 @@ public class CryptoUtil {
}
md5str.append(Integer.toHexString(digital));
}
return md5str.toString().toUpperCase();
return md5str.toString();
}
}
package com.makeit.utils.third.mail;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
@Data
@ConfigurationProperties(prefix = "spring.mail")
@Component
public class MailConfig {
private String username;
private String template;
private String title;
}
......@@ -14,7 +14,7 @@ import org.springframework.stereotype.Component;
@Component
@ConfigurationProperties(prefix = "sms.config")
@Data
public class SmsConfig {
public class SmsConfigOld {
private String templateCode;
private String signName;
private String keys;
......
......@@ -75,7 +75,7 @@ public class SmsSendUtil {
}
public static void sendSMS(String phone, SmsConfig smsConfig, String templateParam) throws Exception {
public static void sendSMS(String phone, SmsConfigOld smsConfig, String templateParam) throws Exception {
try {
sendSMS(phone, smsConfig.getSignName(), smsConfig.getTemplateCode(), templateParam);
} catch (Exception ex) {
......@@ -95,7 +95,7 @@ public class SmsSendUtil {
String token = IdGen.getUUID();
Map<String, Object> param = new HashMap<>(16);
param.put("code", code);
SmsSendUtil.sendSMS(phone, SpringContextHolder.getBean(SmsConfig.class), JsonUtil.toJson(param));
SmsSendUtil.sendSMS(phone, SpringContextHolder.getBean(SmsConfigOld.class), JsonUtil.toJson(param));
TokenUtil.setMobileCode(phone, token, code, 5);
return token;
}
......
......@@ -10,6 +10,7 @@ import com.makeit.dto.platform.alarm.PlatAlarmRecordQueryDTO;
import com.makeit.service.platform.alarm.PlatAlarmRecordService;
import com.makeit.utils.msg.dto.MsgDTO;
import com.makeit.utils.msg.sender.MailMsgSender;
import com.makeit.utils.msg.sender.SmsMsgSender;
import com.makeit.vo.platform.alarm.PlatAlarmRecordVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
......@@ -54,10 +55,12 @@ public class PlatAlarmRecordController {
@Autowired
private MailMsgSender mailMsgSender;
@Autowired
private SmsMsgSender smsMsgSender;
@ApiOperation("测试消息")
@PostMapping("testMsg")
public ApiResponseEntity<Void> testMsg(@RequestBody BaseIdDTO dto) {
@ApiOperation("测试邮箱")
@PostMapping("testMail")
public ApiResponseEntity<Void> testMail(@RequestBody BaseIdDTO dto) {
MsgDTO msgDTO = new MsgDTO();
msgDTO.setSubject("测试消息");
msgDTO.setReceiverList(Collections.singletonList("994997968@qq.com"));
......@@ -65,5 +68,15 @@ public class PlatAlarmRecordController {
mailMsgSender.send(msgDTO);
return ApiResponseUtils.success();
}
@ApiOperation("测试短信")
@PostMapping("testMsg")
public ApiResponseEntity<Void> testMsg(@RequestBody BaseIdDTO dto) throws Exception {
MsgDTO msgDTO = new MsgDTO();
msgDTO.setReceiverList(Collections.singletonList("18850503603"));
msgDTO.setOriContent("测试短信test");
smsMsgSender.send(msgDTO);
return ApiResponseUtils.success();
}
}
package com.makeit.entity.saas;
import com.baomidou.mybatisplus.annotation.FieldStrategy;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.makeit.common.entity.BaseEntity;
import lombok.Data;
......@@ -30,11 +32,13 @@ public class SaasMenu extends BaseEntity {
/**
* 图标
*/
@TableField(updateStrategy = FieldStrategy.IGNORED)
private String icon;
/**
* 排序
*/
@TableField
private Integer sort;
/**
......
......@@ -127,7 +127,8 @@ implements PlatAlarmRecordService{
.eq(PlatRoomBedDevice::getEquipmentId, deviceId).orderByDesc(BaseEntity::getUpdateDate);
PlatRoomBedDevice platRoomBedDevice = platRoomBedDeviceService.getOne(roomBedDeviceLambdaQueryWrapper, false);
//绑定房间的设备要通知 全部老人的家属
//绑定房间的设备要通知 全部长者的家属
//绑定床位的设备要通知对应的长者的家属
if(platRoomBedDevice == null){
throw new BusinessException(CodeMessageEnum.PLATFORM_ERROR_ALARM_NOT_FOUND_SPACE);
}
......
......@@ -127,4 +127,25 @@ wx:
secret: 2ebae648f45716e70c75b7d78d0660cc #微信小程序的Secret
token: #微信小程序消息服务器配置的token
aesKey: #微信小程序消息服务器配置的EncodingAESKey
msgDataFormat: JSON
\ No newline at end of file
msgDataFormat: JSON
sms:
send:
url: http://www.aozoneyun.com/message/message/send
uid: 357
pwd: xmks123456
rec:
url:
query:
url: http://www.aozoneyun.com/message/message/balance
voiceSms:
url: http://www.aozoneyun.com/Message/Message/video_send
uid: 362
pwd: xmksyy123456
......@@ -124,4 +124,20 @@ wx:
secret: 2ebae648f45716e70c75b7d78d0660cc #微信小程序的Secret
token: #微信小程序消息服务器配置的token
aesKey: #微信小程序消息服务器配置的EncodingAESKey
msgDataFormat: JSON
\ No newline at end of file
msgDataFormat: JSON
sms:
send:
url: http://www.aozoneyun.com/message/message/send
uid: 357
pwd: xmks123456
rec:
url:
query:
url: http://www.aozoneyun.com/message/message/balance
voiceSms:
url: http://www.aozoneyun.com/Message/Message/video_send
uid: 362
pwd: xmksyy123456
\ No newline at end of file
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