Commit 1156ca14 by YG8999

短信发送

parent 6eadd203
...@@ -141,6 +141,12 @@ spring: ...@@ -141,6 +141,12 @@ spring:
defaultTopic: "ydlink/#" defaultTopic: "ydlink/#"
completion-timeout: 15000 completion-timeout: 15000
is-subscribe-topic: true is-subscribe-topic: true
sms:
url: "http://121.36.230.249:7862/smsv2"
username: "799243"
password: "RjaI8uA"
extno: "10690"
signature: "【凑角】"
# token配置 # token配置
token: token:
......
...@@ -31,7 +31,7 @@ public class SmsConts { ...@@ -31,7 +31,7 @@ public class SmsConts {
/** /**
* 短信一对一发送接口 * 短信一对一发送接口
*/ */
public final static String smsCodeTemp = "【消费保】您的验证码是:{0},有效期为{1}分钟。如非本人操作,可不予理会。"; public final static String smsCodeTemp = "您的验证码是:{0},有效期为{1}分钟。如非本人操作,可不予理会。";
} }
package share.common.utils; package share.common.utils;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.SecureUtil; import cn.hutool.crypto.SecureUtil;
import cn.hutool.json.JSONObject; import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil; import cn.hutool.json.JSONUtil;
...@@ -14,6 +15,8 @@ import share.common.constant.SmsConts; ...@@ -14,6 +15,8 @@ import share.common.constant.SmsConts;
import share.common.utils.http.RestTemplateUtil; import share.common.utils.http.RestTemplateUtil;
import share.common.exception.base.BaseException; import share.common.exception.base.BaseException;
import java.text.MessageFormat;
/** /**
* @author wuwenlong * @author wuwenlong
* @date 2022年10月13日 15:33 * @date 2022年10月13日 15:33
...@@ -54,20 +57,34 @@ public class SmsUtil { ...@@ -54,20 +57,34 @@ public class SmsUtil {
return SecureUtil.md5(SmsConts.USERNAME + timestamp + SecureUtil.md5(SmsConts.PASSWORD)); return SecureUtil.md5(SmsConts.USERNAME + timestamp + SecureUtil.md5(SmsConts.PASSWORD));
} }
/**
* 短信平台密码加密
* @param password
* @param extno
* @param mobile
* @param content
* @return
*/
public String md5Password(String password, String extno, String mobile, String content) {
return SecureUtil.md5(StrUtil.concat(true, password, extno, mobile, content));
}
public static void main(String[] args) { public static void main(String[] args) {
Integer code = BaseUtil.randomCount(111111, 999999); Integer code = BaseUtil.randomCount(111111, 999999);
String content = MessageFormat.format(SmsConts.smsCodeTemp, code.toString(), "5");
long timestamp = DateUtil.date().getTime(); // 发送内容添加短信签名
String smsContent = StrUtil.concat(true, "【凑角】", content);
String mobile = "18062577819";
JSONObject param = JSONUtil.createObj(); JSONObject param = JSONUtil.createObj();
param.put("userName", SmsConts.USERNAME); param.put("action", "send");
param.put("timestamp", timestamp); param.put("account", "799243");
param.put("sign", SecureUtil.md5(SmsConts.USERNAME + timestamp + SecureUtil.md5(SmsConts.PASSWORD))); param.put("password", SecureUtil.md5(StrUtil.concat(true, "RjaI8uA", "10690", mobile, smsContent)));
// JSONObject json = JSONUtil.createObj(); // param.put("password","RjaI8uA");
// json.put("phone", "18771045387"); param.put("mobile", mobile);
// json.put("content", MessageFormat.format(SmsConts.smsCodeTemp, code.toString(), 3)); // param.put("mobileEencryptionMode", "");
// JSONArray array = JSONUtil.createArray(); param.put("content", smsContent);
// array.add(json); param.put("extno", "10690");
// param.put("messageList",array); // param.put("atTime", "");
System.out.println(JSONUtil.toJsonStr(param)); System.out.println(JSONUtil.toJsonStr(param));
HttpHeaders headers = new HttpHeaders(); HttpHeaders headers = new HttpHeaders();
...@@ -78,7 +95,7 @@ public class SmsUtil { ...@@ -78,7 +95,7 @@ public class SmsUtil {
HttpEntity<JSONObject> requestEntity = new HttpEntity<>(param, headers); HttpEntity<JSONObject> requestEntity = new HttpEntity<>(param, headers);
RestTemplate restTemplate = new RestTemplate(); RestTemplate restTemplate = new RestTemplate();
cn.hutool.json.JSONObject body = restTemplate.postForEntity(SmsConts.BASE_URL + SmsConts.querySignature, requestEntity, cn.hutool.json.JSONObject.class).getBody(); cn.hutool.json.JSONObject body = restTemplate.postForEntity("http://121.36.230.249:7862/smsv2", requestEntity, cn.hutool.json.JSONObject.class).getBody();
System.out.println(JSONUtil.toJsonStr(body)); System.out.println(JSONUtil.toJsonStr(body));
} }
......
...@@ -143,6 +143,12 @@ spring: ...@@ -143,6 +143,12 @@ spring:
defaultTopic: "ydlink/#" defaultTopic: "ydlink/#"
completion-timeout: 15000 completion-timeout: 15000
is-subscribe-topic: false is-subscribe-topic: false
sms:
url: "http://121.36.230.249:7862/smsv2"
username: "799243"
password: "RjaI8uA"
extno: "10690"
signature: "【凑角】"
# token配置 # token配置
token: token:
......
package share.quartz.task;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import share.system.service.ISCleanRecordsService;
/**
* @className: share.quartz.task.CleanRecordsTask
* @description: 保洁记录定时任务
* @author: lwj
* @create: 2023-11-13 10:52
*/
@Component("cleanRecordsTask")
public class CleanRecordsTask {
@Autowired
private ISCleanRecordsService cleanRecordsService;
public void finishCleanRecords() {
cleanRecordsService.finishCleanRecords();
}
}
...@@ -65,4 +65,6 @@ public interface SCleanRecordsMapper extends BaseMapper<SCleanRecords> ...@@ -65,4 +65,6 @@ public interface SCleanRecordsMapper extends BaseMapper<SCleanRecords>
List<SCleanRecords> unCleanList(SCleanRecords sCleanRecords); List<SCleanRecords> unCleanList(SCleanRecords sCleanRecords);
List<SCleanRecords> myCleanList(SCleanRecords sCleanRecords); List<SCleanRecords> myCleanList(SCleanRecords sCleanRecords);
int updateBatch(List<SCleanRecords> list);
} }
...@@ -74,4 +74,10 @@ public interface ISCleanRecordsService ...@@ -74,4 +74,10 @@ public interface ISCleanRecordsService
SCleanRecords getByRoomId(Long roomId); SCleanRecords getByRoomId(Long roomId);
SCleanRecords getByCleanerId(); SCleanRecords getByCleanerId();
/**
* 超时未打扫房间自动结束打扫
* @return
*/
boolean finishCleanRecords();
} }
...@@ -2,6 +2,7 @@ package share.system.service.impl; ...@@ -2,6 +2,7 @@ package share.system.service.impl;
import java.util.List; import java.util.List;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import share.common.enums.CleaningStatusEnum; import share.common.enums.CleaningStatusEnum;
import share.common.enums.RoleTypeEnum; import share.common.enums.RoleTypeEnum;
...@@ -165,6 +166,21 @@ public class SCleanRecordsServiceImpl implements ISCleanRecordsService ...@@ -165,6 +166,21 @@ public class SCleanRecordsServiceImpl implements ISCleanRecordsService
return sCleanRecords; return sCleanRecords;
} }
@Override
public boolean finishCleanRecords() {
LambdaQueryWrapper<SCleanRecords> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(SCleanRecords::getStatus,0);
queryWrapper.ge(SCleanRecords::getCreateTime, DateUtil.offsetMinute(DateUtil.date(), -30));
List<SCleanRecords> list = sCleanRecordsMapper.selectList(queryWrapper);
for (SCleanRecords sCleanRecords : list) {
sCleanRecords.setStatus(2);
sCleanRecords.setStartDate(DateUtil.date());
sCleanRecords.setEndDate(DateUtil.date());
sCleanRecords.setUpdateTime(DateUtil.date());
}
return 0 < sCleanRecordsMapper.updateBatch(list);
}
private void sendSms(Long storeId) { private void sendSms(Long storeId) {
List<SConsumer> list = sConsumerMapper.selectListByStoreId(storeId); List<SConsumer> list = sConsumerMapper.selectListByStoreId(storeId);
for (SConsumer consumer : list) { for (SConsumer consumer : list) {
......
...@@ -8,6 +8,7 @@ import cn.hutool.json.JSONUtil; ...@@ -8,6 +8,7 @@ import cn.hutool.json.JSONUtil;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import share.common.constant.Constants; import share.common.constant.Constants;
import share.common.constant.SmsConstants; import share.common.constant.SmsConstants;
...@@ -19,6 +20,8 @@ import share.system.service.SConsumerService; ...@@ -19,6 +20,8 @@ import share.system.service.SConsumerService;
import share.system.service.SmsService; import share.system.service.SmsService;
import java.text.MessageFormat; import java.text.MessageFormat;
import java.util.List;
import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
...@@ -32,6 +35,21 @@ import java.util.concurrent.TimeUnit; ...@@ -32,6 +35,21 @@ import java.util.concurrent.TimeUnit;
public class SmsServiceImpl implements SmsService { public class SmsServiceImpl implements SmsService {
private static final Logger logger = LoggerFactory.getLogger(SmsServiceImpl.class); private static final Logger logger = LoggerFactory.getLogger(SmsServiceImpl.class);
@Value("${spring.sms.url}")
private String url;
@Value("${spring.sms.extno}")
private String extno;
@Value("${spring.sms.username}")
private String userName;
@Value("${spring.sms.password}")
private String passWord;
@Value("${spring.sms.signature}")
private String signature;
@Autowired @Autowired
private SmsUtil smsUtil; private SmsUtil smsUtil;
@Autowired @Autowired
...@@ -62,8 +80,7 @@ public class SmsServiceImpl implements SmsService { ...@@ -62,8 +80,7 @@ public class SmsServiceImpl implements SmsService {
try { try {
if (tag.equals(SmsConstants.SMS_CONFIG_TYPE_VERIFICATION_CODE)) { if (tag.equals(SmsConstants.SMS_CONFIG_TYPE_VERIFICATION_CODE)) {
//TODO 发送短信 //TODO 发送短信
JSONObject jsonObject = smsUtil.postFrom(SmsConts.BASE_URL + SmsConts.sendMessageOne, new JSONObject()); JSONObject jsonObject = sendOneSms(phone, getSmsContent(phone, tag));
Boolean isSendCode = Objects.nonNull(jsonObject);//TODO 发送成功判断?? Boolean isSendCode = Objects.nonNull(jsonObject);//TODO 发送成功判断??
if (isSendCode) { if (isSendCode) {
return isSendCode; return isSendCode;
...@@ -80,9 +97,8 @@ public class SmsServiceImpl implements SmsService { ...@@ -80,9 +97,8 @@ public class SmsServiceImpl implements SmsService {
@Override @Override
public boolean sendSmsCode(String phone) { public boolean sendSmsCode(String phone) {
redisUtil.set(sConsumerService.getValidateCodeRedisKey(phone), "123456", Long.valueOf(Constants.CONFIG_KEY_SMS_CODE_EXPIRE), TimeUnit.MINUTES); // redisUtil.set(sConsumerService.getValidateCodeRedisKey(phone), "123456", Long.valueOf(Constants.CONFIG_KEY_SMS_CODE_EXPIRE), TimeUnit.MINUTES);
return sendSms(phone, SmsConstants.SMS_CONFIG_TYPE_VERIFICATION_CODE);//TODO 手机验证吗待对接短信平台 sendSms(phone, SmsConstants.SMS_CONFIG_TYPE_VERIFICATION_CODE);
return true;//TODO 手机验证吗待对接短信平台 sendSms(phone, SmsConstants.SMS_CONFIG_TYPE_VERIFICATION_CODE);
} }
private String getSmsContent(String phone, Integer tag) { private String getSmsContent(String phone, Integer tag) {
...@@ -105,4 +121,75 @@ public class SmsServiceImpl implements SmsService { ...@@ -105,4 +121,75 @@ public class SmsServiceImpl implements SmsService {
} }
} }
/**
* 短信群发
* @param phoneList 手机号码集合
* @param content 发送内容
* @return
*/
private JSONObject sendGroupSms(List<String> phoneList, String content) {
// 发送内容添加短信签名
String smsContent = StrUtil.concat(true, signature, content);
String phoneStr = String.join(",", phoneList);
JSONObject param = JSONUtil.createObj();
param.put("action", "send");
param.put("account", userName);
param.put("password", smsUtil.md5Password(passWord, extno, phoneStr, smsContent));
param.put("mobile", phoneStr);
// param.put("mobileEencryptionMode", "");
param.put("content", smsContent);
param.put("extno", extno);
// param.put("atTime", "");
return smsUtil.postFrom(url, param);
}
/**
* 单独发送
* @param phone 手机号
* @param content 发送内容
* @return
*/
private JSONObject sendOneSms(String phone, String content) {
// 发送内容添加短信签名
String smsContent = StrUtil.concat(true, signature, content);
JSONObject param = JSONUtil.createObj();
param.put("action", "send");
param.put("account", userName);
param.put("password", smsUtil.md5Password(passWord, extno, phone, smsContent));
param.put("mobile", phone);
// param.put("mobileEencryptionMode", "");
param.put("content", smsContent);
param.put("extno", extno);
// param.put("atTime", "");
return smsUtil.postFrom(url, param);
}
/**
* 点对点发送
* @param map 手机号码:发送内容 {"15100000000":"【测试】test1","15100000001":"【测试】test2"}
* @return
*/
private JSONObject sendP2PSms(Map<String,String> map) {
String content = "";
if (map != null) {
for (Map.Entry<String,String> entry : map.entrySet()) {
// 发送内容添加短信签名
String smsContent = StrUtil.concat(true, signature, entry.getValue());
map.put(entry.getKey(), smsContent);
content = StrUtil.concat(true, content, entry.getKey(), entry.getValue());
}
}
JSONObject param = JSONUtil.createObj();
param.put("action", "p2p");
param.put("account", userName);
param.put("password", smsUtil.md5Password(passWord, extno, "", content));
param.put("mobileContentKvp", map);
// param.put("mobileEencryptionMode", "");
param.put("extno", extno);
// param.put("atTime", "");
return smsUtil.postFrom(url, param);
}
} }
...@@ -138,6 +138,58 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ...@@ -138,6 +138,58 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</trim> </trim>
where id = #{id} where id = #{id}
</update> </update>
<update id="updateBatch" parameterType="list">
update s_clean_records
<trim prefix="set" suffixOverrides=",">
<trim prefix=" start_date =case" suffix="end,">
<foreach collection="list" item="i" index="index">
<if test="i.startDate!=null">
when id=#{i.id} then #{i.startDate}
</if>
</foreach>
</trim>
<trim prefix=" end_date =case" suffix="end,">
<foreach collection="list" item="i" index="index">
<if test="i.endDate!=null">
when id=#{i.id} then #{i.endDate}
</if>
</foreach>
</trim>
<trim prefix=" status =case" suffix="end," >
<foreach collection="list" item="i" index="index">
<if test="i.status!=null">
when id=#{i.id} then #{i.status}
</if>
</foreach>
</trim>
<trim prefix=" update_time =case" suffix="end," >
<foreach collection="list" item="i" index="index">
<if test="i.updateTime!=null">
when id=#{i.id} then #{i.updateTime}
</if>
</foreach>
</trim>
<trim prefix=" start_image =case" suffix="end," >
<foreach collection="list" item="i" index="index">
<if test="i.startImage!=null">
when id=#{i.id} then #{i.startImage}
</if>
</foreach>
</trim>
<trim prefix=" end_image =case" suffix="end," >
<foreach collection="list" item="i" index="index">
<if test="i.endImage!=null">
when id=#{i.id} then #{i.endImage}
</if>
</foreach>
</trim>
</trim>
where
<foreach collection="list" separator="or" item="i" index="index" >
id=#{i.id}
</foreach>
</update>
<delete id="deleteSCleanRecordsById" parameterType="Long"> <delete id="deleteSCleanRecordsById" parameterType="Long">
delete from s_clean_records where id = #{id} delete from s_clean_records where id = #{id}
......
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 to comment