|
|
@ -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: SignSendCheckServiceImpl
|
|
|
|
* @ClassName: SignSendCheckServiceImpl
|
|
|
@ -16,8 +25,43 @@ import org.springframework.stereotype.Service;
|
|
|
|
@Slf4j
|
|
|
|
@Slf4j
|
|
|
|
@Service("SignSendCheck")
|
|
|
|
@Service("SignSendCheck")
|
|
|
|
public class SignSendCheckServiceImpl implements SendCheckService {
|
|
|
|
public class SignSendCheckServiceImpl implements SendCheckService {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
CacheClient cacheClient;
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void check(StandardSubmit standardSubmit) {
|
|
|
|
public void check(StandardSubmit standardSubmit) {
|
|
|
|
log.info("Check SignSendCheck");
|
|
|
|
log.info("【接口模块】短信客户签名校验。。。");
|
|
|
|
|
|
|
|
String text = standardSubmit.getText();
|
|
|
|
|
|
|
|
//短信正确格式:【签名】短信内容。。。
|
|
|
|
|
|
|
|
//短信内容为空,显然不可能包含签名
|
|
|
|
|
|
|
|
if (text == null || text.isEmpty()) {
|
|
|
|
|
|
|
|
log.info("【接口模块-校验签名】短信无可用签名 text = {}", text);
|
|
|
|
|
|
|
|
throw new ApiException(ExceptionEnums.ERROR_SIGN);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//短信不以“【”开头或者不包含“】”,签名格式不正确
|
|
|
|
|
|
|
|
if (!text.startsWith(SMSConstant.SIGN_PREFIX) || !text.contains(SMSConstant.SIGN_PREFIX)) {
|
|
|
|
|
|
|
|
log.info("【接口模块-校验签名】短信无可用签名 text = {}", text);
|
|
|
|
|
|
|
|
throw new ApiException(ExceptionEnums.ERROR_SIGN);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//截取签名
|
|
|
|
|
|
|
|
String signInText = text.substring(1, text.indexOf(SMSConstant.SIGN_SUFFIX));
|
|
|
|
|
|
|
|
//查询缓存中的客户签名信息
|
|
|
|
|
|
|
|
Set<Map> clientSigns = cacheClient.smember(CacheConstant.CLIENT_SIGN + standardSubmit.getClientId());
|
|
|
|
|
|
|
|
if (clientSigns == null || clientSigns.isEmpty()) {
|
|
|
|
|
|
|
|
log.info("【接口模块-校验签名】客户无可用签名");
|
|
|
|
|
|
|
|
throw new ApiException(ExceptionEnums.ERROR_SIGN);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//取出签名
|
|
|
|
|
|
|
|
for (Map clientSign : clientSigns) {
|
|
|
|
|
|
|
|
String signInCache = (String) clientSign.get("signInfo");
|
|
|
|
|
|
|
|
if (signInCache.equals(signInText)) {
|
|
|
|
|
|
|
|
log.info("【接口模块】签名校验通过!text = {}", text);
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
log.info("【接口模块-校验签名】短信无可用签名 text = {}", text);
|
|
|
|
|
|
|
|
throw new ApiException(ExceptionEnums.ERROR_SIGN);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|