|
|
@ -1,11 +1,20 @@
|
|
|
|
package com.mashibing.api.service.sendCheck.impl;
|
|
|
|
package com.mashibing.api.service.sendCheck.impl;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.mashibing.api.feignClient.CacheClient;
|
|
|
|
import com.mashibing.api.pojo.SingleSendRequest;
|
|
|
|
import com.mashibing.api.pojo.SingleSendRequest;
|
|
|
|
import com.mashibing.api.service.sendCheck.SendCheckService;
|
|
|
|
import com.mashibing.api.service.sendCheck.SendCheckService;
|
|
|
|
|
|
|
|
import com.mashibing.common.constant.CacheConstant;
|
|
|
|
|
|
|
|
import com.mashibing.common.constant.SMSConstant;
|
|
|
|
|
|
|
|
import com.mashibing.common.enums.ExceptionEnums;
|
|
|
|
|
|
|
|
import com.mashibing.common.exception.ApiException;
|
|
|
|
import com.mashibing.common.pojo.StandardSubmit;
|
|
|
|
import com.mashibing.common.pojo.StandardSubmit;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @author heqijun
|
|
|
|
* @author heqijun
|
|
|
|
* @ClassName: TemplateSendCheckServiceImpl
|
|
|
|
* @ClassName: TemplateSendCheckServiceImpl
|
|
|
@ -16,8 +25,55 @@ import org.springframework.stereotype.Service;
|
|
|
|
@Slf4j
|
|
|
|
@Slf4j
|
|
|
|
@Service("TemplateSendCheck")
|
|
|
|
@Service("TemplateSendCheck")
|
|
|
|
public class TemplateSendCheckServiceImpl implements SendCheckService {
|
|
|
|
public class TemplateSendCheckServiceImpl implements SendCheckService {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
CacheClient cacheClient;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final String TEMPLATE_TEXT = "templateText";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final String TEMPLATE_PLACEHOLDER = "#";
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void check(StandardSubmit standardSubmit) {
|
|
|
|
public void check(StandardSubmit standardSubmit) {
|
|
|
|
log.info("Check TemplateSendCheckServiceImpl");
|
|
|
|
log.info("【接口模块-校验模板】 校验ing…………");
|
|
|
|
|
|
|
|
// 1、从submit中获取到短信内容,签名信息,签名id
|
|
|
|
|
|
|
|
String text = standardSubmit.getText();
|
|
|
|
|
|
|
|
String sign = standardSubmit.getSign();
|
|
|
|
|
|
|
|
String signId = standardSubmit.getSignId();
|
|
|
|
|
|
|
|
// 2、将短信内容中的签名直接去掉,获取短信具体内容
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
text = text.replace(SMSConstant.SIGN_PREFIX + sign + SMSConstant.SIGN_SUFFIX, "");
|
|
|
|
|
|
|
|
// 3、从缓存中获取到签名id绑定的所有模板
|
|
|
|
|
|
|
|
Set<Map> templates = cacheClient.smember(CacheConstant.CLIENT_TEMPLATE + signId);
|
|
|
|
|
|
|
|
// 4、在tempaltes不为null时,遍历签名绑定的所有模板信息
|
|
|
|
|
|
|
|
if (templates != null && !templates.isEmpty()) {
|
|
|
|
|
|
|
|
for (Map template : templates) {
|
|
|
|
|
|
|
|
// 4.1 将模板内容和短信具体内容做匹配-true-匹配成功
|
|
|
|
|
|
|
|
String templateText = (String) template.get(TEMPLATE_TEXT);
|
|
|
|
|
|
|
|
if (text.equals(templateText)) {
|
|
|
|
|
|
|
|
// 短信具体内容和模板是匹配的。
|
|
|
|
|
|
|
|
log.info("【接口模块-校验模板】 校验模板通过 templateText = {}", templateText);
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// 4.2 判断模板中是否只包含一个变量,如果是,直接让具体短信内容匹配前缀和后缀
|
|
|
|
|
|
|
|
// 例子:您的验证码是123434。如非本人操作,请忽略本短信
|
|
|
|
|
|
|
|
// 例子:您的验证码是#code#。如非本人操作,请忽略本短信
|
|
|
|
|
|
|
|
if (templateText != null && templateText.contains(TEMPLATE_PLACEHOLDER) && templateText.length() - templateText.replaceAll(TEMPLATE_PLACEHOLDER, "").length() == 2) {
|
|
|
|
|
|
|
|
// 可以确认模板不为空,并且包含#符号,而且#符号有2个,代表是一个占位符(变量)。
|
|
|
|
|
|
|
|
// 获取模板撇去占位符之后的前缀和后缀
|
|
|
|
|
|
|
|
String templateTextPrefix = templateText.substring(0, templateText.indexOf(TEMPLATE_PLACEHOLDER));
|
|
|
|
|
|
|
|
String templateTextSuffix = templateText.substring(templateText.lastIndexOf(TEMPLATE_PLACEHOLDER) + 1);
|
|
|
|
|
|
|
|
// 判断短信的具体内容是否匹配前缀和后缀
|
|
|
|
|
|
|
|
if (text.startsWith(templateTextPrefix) && text.endsWith(templateTextSuffix)) {
|
|
|
|
|
|
|
|
// 当前的短信内容匹配短信模板
|
|
|
|
|
|
|
|
log.info("【接口模块-校验模板】 校验模板通过 templateText = {}", templateText);
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// 5、 模板校验失败
|
|
|
|
|
|
|
|
log.info("【接口模块-校验模板】 无可用模板 text = {}", text);
|
|
|
|
|
|
|
|
throw new ApiException(ExceptionEnums.ERROR_TEMPLATE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|