## 去掉旧短信相关内容;
This commit is contained in:
parent
52c30b6c64
commit
746cb5c5f0
|
@ -2,12 +2,9 @@ package com.hzs.third.sms;
|
|||
|
||||
import com.hzs.common.core.domain.R;
|
||||
import com.hzs.common.core.enums.EAliSmsTemplate;
|
||||
import com.hzs.third.sms.dto.SmsServiceDTO;
|
||||
|
||||
/**
|
||||
* 短信服务接口
|
||||
*
|
||||
* @author hzs
|
||||
*/
|
||||
public interface ISmsServiceApi {
|
||||
|
||||
|
|
|
@ -1,57 +0,0 @@
|
|||
package com.hzs.third.sms.dto;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 短信服务参数DTO
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
@Data
|
||||
public class SmsServiceDTO implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 9096130356166559652L;
|
||||
|
||||
/**
|
||||
* 短信模板编号 -- 必传
|
||||
*/
|
||||
private String templateCode;
|
||||
|
||||
/**
|
||||
* 发送会员ID
|
||||
*/
|
||||
private Long pkMember;
|
||||
|
||||
/**
|
||||
* 发送手机号 -- 必传
|
||||
*/
|
||||
private String phone;
|
||||
|
||||
/**
|
||||
* 参数列表 -- 根据模板实际参数确定
|
||||
*/
|
||||
private List<String> paramList;
|
||||
|
||||
/**
|
||||
* 操作人
|
||||
*/
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 操作人所属国家 -- 必传
|
||||
*/
|
||||
private Integer pkCountry;
|
||||
|
||||
/**
|
||||
* 是否记录发送日志(默认为记录,false=不记录日志)
|
||||
*/
|
||||
private Boolean saveFlag;
|
||||
|
||||
}
|
|
@ -3,11 +3,7 @@ package com.hzs.system.sms.service;
|
|||
import com.hzs.common.core.enums.EAliSmsTemplate;
|
||||
|
||||
/**
|
||||
* @Description: 短信服务
|
||||
* @Author: jiang chao
|
||||
* @Time: 2024/8/5 14:34
|
||||
* @Classname: ISmsService
|
||||
* @PackageName: com.hzs.system.sms.service
|
||||
* 短信服务
|
||||
*/
|
||||
public interface ISmsService {
|
||||
|
||||
|
|
|
@ -16,11 +16,7 @@ import org.springframework.stereotype.Service;
|
|||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* @Description: 短信服务
|
||||
* @author: jiang chao
|
||||
* @Time: 2024/8/5 14:34
|
||||
* @Classname: SmsServiceImpl
|
||||
* @PackageName: com.hzs.system.sms.service.impl
|
||||
* 短信服务
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
|
|
|
@ -1,45 +1,41 @@
|
|||
package com.hzs.common.core.constant.msg;
|
||||
|
||||
/**
|
||||
* @Description: 公用类提示
|
||||
* @Author: jiang chao
|
||||
* @Time: 2023/4/11 11:31
|
||||
* @Classname: CommonMsgConstants
|
||||
* @PackageName: com.hzs.common.core.constant.msg
|
||||
* 公用类提示
|
||||
*/
|
||||
public class CommonMsgConstants {
|
||||
|
||||
/**
|
||||
* 前后台数据传入中少了部分数据参数 -- 缺少参数
|
||||
*/
|
||||
public static final String MISSING_PARAM = "缺少参数";
|
||||
public static final String MISSING_PARAM = "缺少参数";
|
||||
|
||||
/**
|
||||
* 接口数据处理因代码原因未成功 -- 操作失败
|
||||
*/
|
||||
public static final String OPERATION_FAILED = "操作失败";
|
||||
public static final String OPERATION_FAILED = "操作失败";
|
||||
|
||||
/**
|
||||
* 一般用于三方对接,处理失败,用户刷新后可以重新进行操作提示 -- 操作失败,请刷新后重试
|
||||
*/
|
||||
public static final String OPERATION_FAILED_FLUSH = "操作失败,请刷新后重试";
|
||||
public static final String OPERATION_FAILED_FLUSH = "操作失败,请刷新后重试";
|
||||
|
||||
/**
|
||||
* 用户已转结算国,不能进行处理相关操作 -- 用户已转结算国,不能进行操作
|
||||
*/
|
||||
public static final String SETTLEMENT_COUNTRY_NOT_OPERATE = "用户已转结算国,不能进行操作";
|
||||
public static final String SETTLEMENT_COUNTRY_NOT_OPERATE = "用户已转结算国,不能进行操作";
|
||||
|
||||
/**
|
||||
* 签呈处理失败 -- 签呈处理失败
|
||||
*/
|
||||
public static final String APPROVAL_ERROR = "签呈处理失败";
|
||||
public static final String APPROVAL_ERROR = "签呈处理失败";
|
||||
/**
|
||||
* 签呈审批时,签呈数据不存在或者被删除 -- 签呈处理失败:签呈不存在
|
||||
*/
|
||||
public static final String APPROVAL_NOT_EXIST = "签呈处理失败:签呈不存在";
|
||||
public static final String APPROVAL_NOT_EXIST = "签呈处理失败:签呈不存在";
|
||||
/**
|
||||
* 签呈审批时,签呈已经被审批 -- 签呈处理失败:签呈已处理
|
||||
*/
|
||||
public static final String APPROVAL_PROCESSED = "签呈处理失败:签呈已处理";
|
||||
public static final String APPROVAL_PROCESSED = "签呈处理失败:签呈已处理";
|
||||
|
||||
}
|
||||
|
|
|
@ -61,50 +61,6 @@ public enum ESmsTemplate {
|
|||
*/
|
||||
BALANCE_CHECK(SmsConstants.SMS_CODE_PREFIX + "17", "", false),
|
||||
|
||||
|
||||
//////////////////// 上面的短信不能进行手动发送 ////////////////////
|
||||
|
||||
/**
|
||||
* 售后收货
|
||||
*/
|
||||
SMS21(SmsConstants.SMS_CODE_PREFIX + "21", "", true),
|
||||
/**
|
||||
* 售后换新
|
||||
*/
|
||||
SMS22(SmsConstants.SMS_CODE_PREFIX + "22", "", true),
|
||||
/**
|
||||
* 售后原件
|
||||
*/
|
||||
SMS23(SmsConstants.SMS_CODE_PREFIX + "23", "", true),
|
||||
/**
|
||||
* 售后换件
|
||||
*/
|
||||
SMS24(SmsConstants.SMS_CODE_PREFIX + "24", "", true),
|
||||
/**
|
||||
* 产品补发
|
||||
*/
|
||||
SMS25(SmsConstants.SMS_CODE_PREFIX + "25", "", true),
|
||||
/**
|
||||
* 售后受理
|
||||
*/
|
||||
SMS26(SmsConstants.SMS_CODE_PREFIX + "26", "", true),
|
||||
/**
|
||||
* 疫情延迟补发
|
||||
*/
|
||||
SMS27(SmsConstants.SMS_CODE_PREFIX + "27", "", true),
|
||||
/**
|
||||
* 疫情延迟发货
|
||||
*/
|
||||
SMS28(SmsConstants.SMS_CODE_PREFIX + "28", "", true),
|
||||
/**
|
||||
* 售后快速处理
|
||||
*/
|
||||
SMS29(SmsConstants.SMS_CODE_PREFIX + "29", "", true),
|
||||
/**
|
||||
* 支付订单退款
|
||||
*/
|
||||
SMS30(SmsConstants.SMS_CODE_PREFIX + "30", "", true),
|
||||
|
||||
;
|
||||
|
||||
/**
|
||||
|
@ -120,19 +76,5 @@ public enum ESmsTemplate {
|
|||
*/
|
||||
private final boolean create;
|
||||
|
||||
/**
|
||||
* 根据编号获取枚举
|
||||
*
|
||||
* @param code
|
||||
* @return
|
||||
*/
|
||||
public static ESmsTemplate getEnumsByCode(String code) {
|
||||
for (ESmsTemplate value : ESmsTemplate.values()) {
|
||||
if (value.getCode().equals(code)) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -6,44 +6,17 @@ import org.springframework.stereotype.Component;
|
|||
|
||||
/**
|
||||
* 短信配置
|
||||
* @author hzs
|
||||
*/
|
||||
@Data
|
||||
@Component
|
||||
@ConfigurationProperties(prefix = "sms")
|
||||
public class SmsConfig {
|
||||
|
||||
/**
|
||||
* 企业ID
|
||||
*/
|
||||
private String corpId;
|
||||
/**
|
||||
* 密码
|
||||
*/
|
||||
private String pwd;
|
||||
/**
|
||||
* 短信请求URL
|
||||
*/
|
||||
private String url;
|
||||
|
||||
/**
|
||||
* 是否发送短信(true发送,false不发送)
|
||||
*/
|
||||
private boolean enable;
|
||||
|
||||
/**
|
||||
* 企业ID(国际)
|
||||
*/
|
||||
private String corpIdInter;
|
||||
/**
|
||||
* 密码(国际)
|
||||
*/
|
||||
private String pwdInter;
|
||||
/**
|
||||
* 短信请求URL(国际)
|
||||
*/
|
||||
private String urlInter;
|
||||
|
||||
/**
|
||||
* 阿里短信accessKeyId
|
||||
*/
|
||||
|
|
|
@ -1,16 +1,12 @@
|
|||
package com.hzs.third.sms.controller.manage;
|
||||
|
||||
import com.hzs.common.core.annotation.Log;
|
||||
import com.hzs.common.core.constant.msg.CommonMsgConstants;
|
||||
import com.hzs.common.core.enums.*;
|
||||
import com.hzs.common.core.utils.poi.ExcelUtil;
|
||||
import com.hzs.common.core.web.controller.BaseController;
|
||||
import com.hzs.common.core.web.domain.AjaxResult;
|
||||
import com.hzs.common.core.web.page.TableDataInfo;
|
||||
import com.hzs.common.domain.third.sms.ext.TSmsRecordExt;
|
||||
import com.hzs.common.security.utils.SecurityUtils;
|
||||
import com.hzs.common.util.TransactionUtils;
|
||||
import com.hzs.third.sms.param.SmsCreateParam;
|
||||
import com.hzs.third.sms.param.SmsRecordQueryParam;
|
||||
import com.hzs.third.sms.service.ITSmsRecordService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -68,28 +64,4 @@ public class SmsRecordController extends BaseController {
|
|||
util.exportExcel(response, list, "短信记录导出");
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建短信
|
||||
*
|
||||
* @param param
|
||||
* @return
|
||||
*/
|
||||
@Log(module = EOperationModule.SMS_CONFIG, business = EOperationBusiness.SMS_CREATE, method = EOperationMethod.INSERT)
|
||||
@PostMapping("/create")
|
||||
public AjaxResult create(@RequestBody SmsCreateParam param) {
|
||||
if (null == param.getTemplateId() || null == param.getSendScope() || null == param.getSendType()) {
|
||||
return AjaxResult.error(TransactionUtils.getContent(CommonMsgConstants.MISSING_PARAM));
|
||||
}
|
||||
if (ESmsSendType.SCHEDULED.getValue() == param.getSendType() && null == param.getSendTime()) {
|
||||
// 定时发送,需要有发送时间
|
||||
return AjaxResult.error(TransactionUtils.getContent(CommonMsgConstants.MISSING_PARAM));
|
||||
}
|
||||
|
||||
String str = itSmsRecordService.pageSms(param, SecurityUtils.getUserId(), SecurityUtils.getPkCountry());
|
||||
if (null == str) {
|
||||
return AjaxResult.success();
|
||||
}
|
||||
return AjaxResult.error(str);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,59 +0,0 @@
|
|||
package com.hzs.third.sms.param;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Description: 创建短信入参
|
||||
* @Author: jiang chao
|
||||
* @Time: 2023/3/9 18:12
|
||||
* @Classname: SmsCreateParam
|
||||
* @PackageName: com.hzs.third.sms.param
|
||||
*/
|
||||
@Data
|
||||
public class SmsCreateParam {
|
||||
|
||||
/**
|
||||
* 短信模板ID
|
||||
*/
|
||||
private Integer templateId;
|
||||
|
||||
/**
|
||||
* 发送范围 -- ESmsSendScope
|
||||
*/
|
||||
private Integer sendScope;
|
||||
|
||||
/**
|
||||
* 会员ID列表
|
||||
*/
|
||||
private List<Long> memberList;
|
||||
|
||||
/**
|
||||
* 订单ID列表
|
||||
*/
|
||||
private List<Long> orderList;
|
||||
|
||||
/**
|
||||
* 指定手机号串
|
||||
*/
|
||||
private String phones;
|
||||
|
||||
/**v
|
||||
* 参数列表
|
||||
*/
|
||||
private List<String> paramList;
|
||||
|
||||
/**
|
||||
* 发送方式 -- ESmsSendType
|
||||
*/
|
||||
private Integer sendType;
|
||||
/**
|
||||
* 发送时间
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date sendTime;
|
||||
|
||||
}
|
|
@ -5,11 +5,7 @@ import lombok.Data;
|
|||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @Description: 短信发送记录查询入参
|
||||
* @Author: jiang chao
|
||||
* @Time: 2023/3/8 10:45
|
||||
* @Classname: SmsTemplateParam
|
||||
* @PackageName: com.hzs.third.sms.param
|
||||
* 短信发送记录查询入参
|
||||
*/
|
||||
@Data
|
||||
public class SmsRecordQueryParam {
|
||||
|
|
|
@ -5,11 +5,7 @@ import lombok.Data;
|
|||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @Description: 短信模板查询入参
|
||||
* @Author: jiang chao
|
||||
* @Time: 2023/3/8 10:45
|
||||
* @Classname: SmsTemplateParam
|
||||
* @PackageName: com.hzs.third.sms.param
|
||||
* 短信模板查询入参
|
||||
*/
|
||||
@Data
|
||||
public class SmsTemplateQueryParam {
|
||||
|
|
|
@ -9,8 +9,6 @@ import org.apache.dubbo.config.annotation.DubboService;
|
|||
|
||||
/**
|
||||
* 短信服务提供类
|
||||
*
|
||||
* @author hzs
|
||||
*/
|
||||
@Slf4j
|
||||
@DubboService
|
||||
|
|
|
@ -1,22 +0,0 @@
|
|||
package com.hzs.third.sms.service;
|
||||
|
||||
import com.hzs.third.sms.dto.SmsServiceDTO;
|
||||
|
||||
/**
|
||||
* @Description: 短信服务
|
||||
* @Author: jiang chao
|
||||
* @Time: 2023/3/8 14:18
|
||||
* @Classname: ISmsService
|
||||
* @PackageName: com.hzs.third.sms.service
|
||||
*/
|
||||
public interface ISmsService {
|
||||
|
||||
/**
|
||||
* 实时发送短信
|
||||
*
|
||||
* @param param
|
||||
* @return
|
||||
*/
|
||||
String sendSms(SmsServiceDTO param);
|
||||
|
||||
}
|
|
@ -3,7 +3,6 @@ package com.hzs.third.sms.service;
|
|||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.hzs.common.domain.third.sms.TSmsRecord;
|
||||
import com.hzs.common.domain.third.sms.ext.TSmsRecordExt;
|
||||
import com.hzs.third.sms.param.SmsCreateParam;
|
||||
import com.hzs.third.sms.param.SmsRecordQueryParam;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -22,14 +21,4 @@ public interface ITSmsRecordService extends IService<TSmsRecord> {
|
|||
*/
|
||||
List<TSmsRecordExt> queryList(SmsRecordQueryParam param, Integer pkCountry);
|
||||
|
||||
/**
|
||||
* 页面添加短信
|
||||
*
|
||||
* @param param
|
||||
* @param userId
|
||||
* @param pkCountry
|
||||
* @return
|
||||
*/
|
||||
String pageSms(SmsCreateParam param, Long userId, Integer pkCountry);
|
||||
|
||||
}
|
||||
|
|
|
@ -5,9 +5,6 @@ import com.hzs.common.domain.third.sms.TSmsTemplate;
|
|||
|
||||
/**
|
||||
* 短信模板 服务类
|
||||
*
|
||||
* @author hzs
|
||||
* @since 2022-08-22
|
||||
*/
|
||||
public interface ITSmsTemplateService extends IService<TSmsTemplate> {
|
||||
|
||||
|
|
|
@ -1,99 +0,0 @@
|
|||
package com.hzs.third.sms.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.hzs.common.core.constant.MagicNumberConstants;
|
||||
import com.hzs.common.core.enums.*;
|
||||
import com.hzs.common.domain.third.sms.TSmsRecord;
|
||||
import com.hzs.common.domain.third.sms.TSmsTemplate;
|
||||
import com.hzs.third.sms.dto.SmsServiceDTO;
|
||||
import com.hzs.third.sms.service.ISmsService;
|
||||
import com.hzs.third.sms.service.ITSmsRecordService;
|
||||
import com.hzs.third.sms.service.ITSmsTemplateService;
|
||||
import com.hzs.third.sms.util.SmsUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Description: 短信服务
|
||||
* @Author: jiang chao
|
||||
* @Time: 2023/3/8 14:18
|
||||
* @Classname: SmsServiceImpl
|
||||
* @PackageName: com.hzs.third.sms.service.impl
|
||||
*/
|
||||
@Service
|
||||
public class SmsServiceImpl implements ISmsService {
|
||||
|
||||
@Autowired
|
||||
private ITSmsTemplateService itSmsTemplateService;
|
||||
@Autowired
|
||||
private ITSmsRecordService itSmsRecordService;
|
||||
|
||||
@Override
|
||||
public String sendSms(SmsServiceDTO param) {
|
||||
LambdaQueryWrapper<TSmsTemplate> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(TSmsTemplate::getTemplateCode, param.getTemplateCode());
|
||||
queryWrapper.eq(TSmsTemplate::getPkCountry, param.getPkCountry());
|
||||
TSmsTemplate smsTemplate = itSmsTemplateService.getOne(queryWrapper);
|
||||
if (null == smsTemplate) {
|
||||
return "短信模板不存在";
|
||||
}
|
||||
if (EYesNo.NO.getIntValue() == smsTemplate.getEnable()) {
|
||||
return "短信模板禁止使用";
|
||||
}
|
||||
|
||||
// 手机号
|
||||
String phone = param.getPhone();
|
||||
// 发送内容
|
||||
String content = smsTemplate.getTemplateContent();
|
||||
// 参数列表
|
||||
List<String> paramList = param.getParamList();
|
||||
|
||||
if (smsTemplate.getParamNum() != 0) {
|
||||
if (smsTemplate.getParamNum() != paramList.size()) {
|
||||
return "缺少短信参数";
|
||||
}
|
||||
content = String.format(content, paramList.toArray());
|
||||
}
|
||||
|
||||
Date nowDate = new Date();
|
||||
|
||||
// 短信发送记录
|
||||
TSmsRecord smsRecord = new TSmsRecord();
|
||||
|
||||
// 发送短信
|
||||
String smsStr = SmsUtil.sendSms(phone, content);
|
||||
if (null == smsStr) {
|
||||
// 发送成功
|
||||
smsRecord.setSendResult(ESmsSendResult.SUCCESS.getValue());
|
||||
} else {
|
||||
// 发送失败
|
||||
smsRecord.setSendResult(ESmsSendResult.FAIL.getValue());
|
||||
}
|
||||
|
||||
if (null == param.getSaveFlag() || param.getSaveFlag()) {
|
||||
// 保存短信发送记录
|
||||
smsRecord.setPkSmsTemplate(smsTemplate.getPkId());
|
||||
smsRecord.setPkMember(param.getPkMember());
|
||||
smsRecord.setPhone(phone);
|
||||
smsRecord.setContent(content);
|
||||
smsRecord.setSendScope(ESmsSendScope.MEMBER.getValue());
|
||||
smsRecord.setSendType(ESmsSendType.IMMEDIATELY.getValue());
|
||||
smsRecord.setSendStatus(ESmsSendStatus.SEND.getValue());
|
||||
smsRecord.setSendTime(nowDate);
|
||||
if (null != param.getUserId()) {
|
||||
smsRecord.setPkCreator(param.getUserId());
|
||||
} else {
|
||||
smsRecord.setPkCreator(MagicNumberConstants.PK_ADMIN);
|
||||
}
|
||||
smsRecord.setCreationTime(nowDate);
|
||||
smsRecord.setModifiedTime(nowDate);
|
||||
smsRecord.setPkCountry(param.getPkCountry());
|
||||
itSmsRecordService.save(smsRecord);
|
||||
}
|
||||
return smsStr;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,26 +1,12 @@
|
|||
package com.hzs.third.sms.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.hzs.common.core.enums.*;
|
||||
import com.hzs.common.core.utils.StringUtils;
|
||||
import com.hzs.common.domain.member.ext.CuMemberExt;
|
||||
import com.hzs.common.domain.sale.ext.SaOrderItemsExt;
|
||||
import com.hzs.common.domain.third.sms.TSmsRecord;
|
||||
import com.hzs.common.domain.third.sms.TSmsTemplate;
|
||||
import com.hzs.common.domain.third.sms.ext.TSmsRecordExt;
|
||||
import com.hzs.member.base.IMemberServiceApi;
|
||||
import com.hzs.sale.order.ISaOrderServiceApi;
|
||||
import com.hzs.third.sms.mapper.TSmsRecordMapper;
|
||||
import com.hzs.third.sms.param.SmsCreateParam;
|
||||
import com.hzs.third.sms.param.SmsRecordQueryParam;
|
||||
import com.hzs.third.sms.service.ITSmsRecordService;
|
||||
import com.hzs.third.sms.service.ITSmsTemplateService;
|
||||
import com.hzs.third.sms.util.SmsUtil;
|
||||
import org.apache.dubbo.config.annotation.DubboReference;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
@ -30,217 +16,9 @@ import java.util.*;
|
|||
@Service
|
||||
public class TSmsRecordServiceImpl extends ServiceImpl<TSmsRecordMapper, TSmsRecord> implements ITSmsRecordService {
|
||||
|
||||
@Autowired
|
||||
private ITSmsTemplateService itSmsTemplateService;
|
||||
|
||||
@DubboReference
|
||||
IMemberServiceApi iMemberServiceApi;
|
||||
@DubboReference
|
||||
ISaOrderServiceApi iSaOrderServiceApi;
|
||||
|
||||
@Override
|
||||
public List<TSmsRecordExt> queryList(SmsRecordQueryParam param, Integer pkCountry) {
|
||||
return baseMapper.queryList(param, pkCountry);
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public String pageSms(SmsCreateParam param, Long userId, Integer pkCountry) {
|
||||
TSmsTemplate smsTemplate = itSmsTemplateService.getById(param.getTemplateId());
|
||||
if (null == smsTemplate) {
|
||||
return "短信模板不存在";
|
||||
}
|
||||
if (EYesNo.NO.getIntValue() == smsTemplate.getEnable()) {
|
||||
return "短信模板禁止使用";
|
||||
}
|
||||
// 模板编号
|
||||
String templateCode = smsTemplate.getTemplateCode();
|
||||
// 发送内容
|
||||
String templateContent = smsTemplate.getTemplateContent();
|
||||
|
||||
ESmsTemplate eSmsTemplate = ESmsTemplate.getEnumsByCode(templateCode);
|
||||
if (null != eSmsTemplate) {
|
||||
// 短信枚举存在
|
||||
if (!eSmsTemplate.isCreate()) {
|
||||
return "该短信模板不能手动发送";
|
||||
}
|
||||
}
|
||||
|
||||
// 需要入库的短信记录列表
|
||||
List<TSmsRecord> smsRecordList = new ArrayList<>();
|
||||
|
||||
// 发送范围
|
||||
Integer sendScope = param.getSendScope();
|
||||
// 发送方式
|
||||
Integer sendType = param.getSendType();
|
||||
// 发送时间
|
||||
Date sendTime = param.getSendTime();
|
||||
// 参数列表
|
||||
List<String> paramList = param.getParamList();
|
||||
|
||||
// 短信枚举存在,则需要判断使用哪种方式
|
||||
if (ESmsSendScope.MEMBER.getValue() == sendScope) {
|
||||
// 指定会员
|
||||
List<Long> pkMemberList = param.getMemberList();
|
||||
if (CollectionUtil.isNotEmpty(pkMemberList)) {
|
||||
// 根据传入的会员ID查询会员信息
|
||||
List<CuMemberExt> cuMemberList = iMemberServiceApi.findMemberByMemberId(pkMemberList, pkCountry).getData();
|
||||
|
||||
// 预置会员短信模板,参数使用固定值进行填
|
||||
if (SmsUtil.getMemberTemplateList().contains(smsTemplate.getTemplateCode())) {
|
||||
// 预置模板,可以进行处理
|
||||
// 目前会员短信没有预置模板
|
||||
} else {
|
||||
// 非预置模板
|
||||
for (CuMemberExt cuMember : cuMemberList) {
|
||||
// 发送内容
|
||||
String content;
|
||||
if (CollectionUtil.isNotEmpty(paramList)) {
|
||||
// 传入参数列表
|
||||
content = String.format(templateContent, paramList.toArray());
|
||||
} else {
|
||||
// 非传入参数列表,默认使用会员编号做为填充参数
|
||||
content = String.format(templateContent, cuMember.getMemberCode());
|
||||
}
|
||||
|
||||
smsRecordList.add(this.createRecord(
|
||||
smsTemplate.getPkId(), cuMember.getPkId(), cuMember.getPhone(),
|
||||
content, sendScope, sendType, sendTime, userId, pkCountry
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (ESmsSendScope.ORDER.getValue() == sendScope) {
|
||||
// 指定订单
|
||||
List<Long> orderIdList = param.getOrderList();
|
||||
if (CollectionUtil.isNotEmpty(orderIdList)) {
|
||||
// 根据传入的订单ID查询订单信息
|
||||
List<SaOrderItemsExt> saOrderList = iSaOrderServiceApi.queryOrderItemsListByOrderId(orderIdList, pkCountry).getData();
|
||||
|
||||
// 预置订单短信模板,参数使用固定值进行填
|
||||
if (SmsUtil.getOrderTemplateList().contains(smsTemplate.getTemplateCode())) {
|
||||
// 预置模板,可以进行处理
|
||||
for (SaOrderItemsExt saOrder : saOrderList) {
|
||||
// 发送内容
|
||||
String content = templateContent;
|
||||
if (CollectionUtil.isNotEmpty(paramList)) {
|
||||
// 传入参数列表
|
||||
content = String.format(templateContent, paramList.toArray());
|
||||
} else {
|
||||
// 非传入参数列表,默认使用快递单号做为填充参数
|
||||
if (smsTemplate.getParamNum() == 1) {
|
||||
content = String.format(templateContent, saOrder.getLogisticsCode());
|
||||
}
|
||||
}
|
||||
|
||||
smsRecordList.add(this.createRecord(
|
||||
smsTemplate.getPkId(), saOrder.getPkMember(), saOrder.getRecPhone(),
|
||||
content, sendScope, sendType, sendTime, userId, pkCountry
|
||||
));
|
||||
}
|
||||
} else {
|
||||
// 非预置模板
|
||||
for (SaOrderItemsExt saOrder : saOrderList) {
|
||||
// 发送内容
|
||||
String content = templateContent;
|
||||
if (CollectionUtil.isNotEmpty(paramList)) {
|
||||
// 传入参数列表
|
||||
content = String.format(templateContent, paramList.toArray());
|
||||
} else {
|
||||
// 非传入参数列表,默认使用快递单号做为填充参数
|
||||
if (smsTemplate.getParamNum() == 1) {
|
||||
content = String.format(templateContent, saOrder.getLogisticsCode());
|
||||
} else if (smsTemplate.getParamNum() == 2) {
|
||||
content = String.format(templateContent, saOrder.getOrderCode(), saOrder.getLogisticsCode());
|
||||
}
|
||||
}
|
||||
|
||||
smsRecordList.add(this.createRecord(
|
||||
smsTemplate.getPkId(), saOrder.getPkMember(), saOrder.getRecPhone(),
|
||||
content, sendScope, sendType, sendTime, userId, pkCountry
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 自定义手机号
|
||||
String phones = param.getPhones();
|
||||
if (StringUtils.isNotEmpty(phones)) {
|
||||
// 处理传入手机号
|
||||
String[] phoneArr = phones.replaceAll(";", ";").split(";");
|
||||
|
||||
// 自定义手机号,不区分短信模板
|
||||
for (String phone : phoneArr) {
|
||||
// 发送内容
|
||||
String content = templateContent;
|
||||
if (CollectionUtil.isNotEmpty(paramList)) {
|
||||
// 传入参数列表
|
||||
content = String.format(templateContent, paramList.toArray());
|
||||
}
|
||||
|
||||
smsRecordList.add(this.createRecord(
|
||||
smsTemplate.getPkId(), null, phone,
|
||||
content, sendScope, sendType, sendTime, userId, pkCountry
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (StringUtils.isNotEmpty(smsRecordList)) {
|
||||
// 有发送数据,则进行处理
|
||||
if (ESmsSendType.IMMEDIATELY.getValue() == sendType) {
|
||||
// 立即发送
|
||||
Date nowDate = new Date();
|
||||
|
||||
// 目前单现程推送,后续如果发送慢可以考虑多线程处理
|
||||
smsRecordList.forEach((tSmsRecord -> {
|
||||
// 已发送
|
||||
tSmsRecord.setSendStatus(ESmsSendStatus.SEND.getValue());
|
||||
tSmsRecord.setSendTime(nowDate);
|
||||
if (null == SmsUtil.sendSms(tSmsRecord.getPhone(), tSmsRecord.getContent())) {
|
||||
// 发送成功
|
||||
tSmsRecord.setSendResult(ESmsSendResult.SUCCESS.getValue());
|
||||
} else {
|
||||
// 发送失败
|
||||
tSmsRecord.setSendResult(ESmsSendResult.FAIL.getValue());
|
||||
}
|
||||
}));
|
||||
}
|
||||
baseMapper.insertBatch(smsRecordList);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建短信记录
|
||||
*
|
||||
* @param templateId 模板ID
|
||||
* @param pkMember 接收用户ID
|
||||
* @param phone 发送手机号
|
||||
* @param content 发送内容
|
||||
* @param sendScope 发送范围 -- ESmsSendScope
|
||||
* @param sendType 发送类型 -- ESmsSendType
|
||||
* @param sendTime 发送时间
|
||||
* @param userId 操作用户ID
|
||||
* @param pkCountry 所属国家
|
||||
* @return
|
||||
*/
|
||||
private TSmsRecord createRecord(Integer templateId, Long pkMember, String phone,
|
||||
String content, Integer sendScope, Integer sendType,
|
||||
Date sendTime, Long userId, Integer pkCountry) {
|
||||
TSmsRecord tSmsRecord = new TSmsRecord();
|
||||
tSmsRecord.setPkSmsTemplate(templateId);
|
||||
tSmsRecord.setPkMember(pkMember);
|
||||
tSmsRecord.setPhone(phone);
|
||||
tSmsRecord.setContent(content);
|
||||
tSmsRecord.setSendScope(sendScope);
|
||||
tSmsRecord.setSendType(sendType);
|
||||
tSmsRecord.setSendStatus(ESmsSendStatus.NOT_SEND.getValue());
|
||||
tSmsRecord.setSendResult(ESmsSendResult.NOT_SEND.getValue());
|
||||
tSmsRecord.setSendTime(sendTime);
|
||||
tSmsRecord.setPkCreator(userId);
|
||||
tSmsRecord.setPkCountry(pkCountry);
|
||||
return tSmsRecord;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,8 +4,6 @@ import cn.hutool.json.JSONUtil;
|
|||
import com.aliyun.dysmsapi20170525.Client;
|
||||
import com.hzs.common.core.constant.Constants;
|
||||
import com.hzs.common.core.enums.EAliSmsTemplate;
|
||||
import com.hzs.common.core.enums.ESmsTemplate;
|
||||
import com.hzs.common.core.utils.HttpClientUtil;
|
||||
import com.hzs.common.core.utils.SpringUtils;
|
||||
import com.hzs.third.sms.config.SmsConfig;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
@ -16,18 +14,11 @@ import org.springframework.stereotype.Component;
|
|||
import com.aliyun.dysmsapi20170525.models.*;
|
||||
import com.aliyun.teaopenapi.models.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Description: 发送短信工具类
|
||||
*
|
||||
* @author: jiang chao
|
||||
* Time: 2022/9/24 9:58
|
||||
* Classname: SmsUtil
|
||||
* PackageName: com.hzs.common.utils
|
||||
* 发送短信工具类
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
|
@ -35,64 +26,6 @@ public class SmsUtil implements InitializingBean {
|
|||
|
||||
private static SmsConfig smsConfig;
|
||||
|
||||
// 会员预置短信模板
|
||||
private static List<String> memberTemplateList;
|
||||
|
||||
// 订单预置短信模板
|
||||
private static List<String> orderTemplateList;
|
||||
|
||||
/**
|
||||
* 发送短信
|
||||
*
|
||||
* @param phone 手机号
|
||||
* @param content 发送内容
|
||||
* @return
|
||||
*/
|
||||
public static String sendSms(String phone, String content) {
|
||||
if (StringUtils.isAnyEmpty(phone, content)) {
|
||||
return "手机号或内容为空";
|
||||
}
|
||||
|
||||
if (smsConfig.isEnable()) {
|
||||
// 只有当开启发送短信才进行发送
|
||||
|
||||
String corpid = smsConfig.getCorpId();
|
||||
String pwd = smsConfig.getPwd();
|
||||
String url = smsConfig.getUrl();
|
||||
|
||||
if (phone.length() == 10 && phone.startsWith("09")) {
|
||||
// 台湾手机号码处理(10位长度,以09开头)
|
||||
corpid = smsConfig.getCorpIdInter();
|
||||
pwd = smsConfig.getPwdInter();
|
||||
url = smsConfig.getUrl();
|
||||
}
|
||||
|
||||
Map<String, String> paramMap = new HashMap<>();
|
||||
paramMap.put("corpid", corpid);
|
||||
paramMap.put("pwd", pwd);
|
||||
paramMap.put("mobile", phone);
|
||||
paramMap.put("content", content);
|
||||
|
||||
log.info("短信发送参数: {}", paramMap);
|
||||
|
||||
String result = HttpClientUtil.get(url, paramMap);
|
||||
|
||||
log.info("短信发送结果: {}", result);
|
||||
|
||||
if (StringUtils.isNotEmpty(result)) {
|
||||
if (Integer.parseInt(result) > 0) {
|
||||
return null;
|
||||
} else {
|
||||
log.error("短信发送失败, status: {}", result);
|
||||
}
|
||||
}
|
||||
return "发送失败";
|
||||
} else {
|
||||
log.info("短信发送手机:{}, 内容: {}", phone, content);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送阿里短信
|
||||
*
|
||||
|
@ -104,7 +37,7 @@ public class SmsUtil implements InitializingBean {
|
|||
if (StringUtils.isAnyEmpty(phone, code)) {
|
||||
return "手机号或验证码为空";
|
||||
}
|
||||
System.out.println("手机验证码:"+ code);
|
||||
System.out.println("手机验证码:" + code);
|
||||
if (smsConfig.isEnable()) {
|
||||
// 只有当开启发送短信才进行发送
|
||||
try {
|
||||
|
@ -144,32 +77,9 @@ public class SmsUtil implements InitializingBean {
|
|||
return null;
|
||||
}
|
||||
|
||||
public static List<String> getMemberTemplateList() {
|
||||
return memberTemplateList;
|
||||
}
|
||||
|
||||
public static List<String> getOrderTemplateList() {
|
||||
return orderTemplateList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() {
|
||||
smsConfig = SpringUtils.getBean(SmsConfig.class);
|
||||
|
||||
// 会员预置短信模板初始化
|
||||
memberTemplateList = new ArrayList<>();
|
||||
|
||||
// 订单预置短信模板初始化
|
||||
orderTemplateList = new ArrayList<>();
|
||||
orderTemplateList.add(ESmsTemplate.SMS21.getCode());
|
||||
orderTemplateList.add(ESmsTemplate.SMS22.getCode());
|
||||
orderTemplateList.add(ESmsTemplate.SMS23.getCode());
|
||||
orderTemplateList.add(ESmsTemplate.SMS24.getCode());
|
||||
orderTemplateList.add(ESmsTemplate.SMS25.getCode());
|
||||
orderTemplateList.add(ESmsTemplate.SMS26.getCode());
|
||||
orderTemplateList.add(ESmsTemplate.SMS27.getCode());
|
||||
orderTemplateList.add(ESmsTemplate.SMS28.getCode());
|
||||
orderTemplateList.add(ESmsTemplate.SMS29.getCode());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -92,24 +92,6 @@ huifu:
|
|||
## 小程序appSecret
|
||||
appletAppSecret: ebf41db190b6f4c469c13c67266859e8
|
||||
|
||||
## 短信配置
|
||||
sms:
|
||||
## 凌凯国内短信配置
|
||||
corpId: CQJT001019
|
||||
pwd: 3FDA8B
|
||||
url: https://sdk3.028lk.com:9988/BatchSend2.aspx
|
||||
## 是否发送短信(true发送,false不发送)
|
||||
enable: false
|
||||
## 凌凯国际短信配置
|
||||
corpIdInter: CQJT000992
|
||||
pwdInter: 1263BA
|
||||
urlInter: https://sdk3.028lk.com:9988/IntlSend.aspx
|
||||
## 阿里短信
|
||||
aliAccessKeyId: LTAI5tSjEQgSVXVrVvDEkcNh
|
||||
aliAccessKeySecret: do1zRINS8MZ78UG6Vsa3SglZ3jPcOS
|
||||
aliEndpoint: dysmsapi.aliyuncs.com
|
||||
aliSign: 青岛海之圣生物工程
|
||||
|
||||
# 日志配置
|
||||
logging:
|
||||
level:
|
||||
|
|
Loading…
Reference in New Issue