Commit 0917b70f authored by Java—红包—徐 然's avatar Java—红包—徐 然

Merge branch 'feature/apollo' of http://git.quantgroup.cn/head_group/xyqb-user2 into feature/apollo

# Conflicts:
#	src/main/java/cn/quantgroup/xyqb/service/sms/impl/SmsServiceImpl.java
parents ea79011a 5f0f7ec6
......@@ -5,6 +5,9 @@ import cn.quantgroup.sms.SmsSender;
import cn.quantgroup.xyqb.Constants;
import cn.quantgroup.xyqb.service.sms.ISmsService;
import lombok.Synchronized;
import java.util.Collections;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -14,19 +17,19 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import java.util.Collections;
/**
* @author mengfan.feng
* @time 2015-07-25 18:47
*/
@Service
@Slf4j
public class SmsServiceImpl implements ISmsService {
private static final Logger LOGGER = LoggerFactory.getLogger(SmsServiceImpl.class);
private static final Logger LOGGER = LoggerFactory.getLogger(SmsServiceImpl.class);
private static final int SMS_VERIFICATION_MAXLEN = 4;
private static final String SMS_VERIFY_PREFIX = "sms:verify:";
private static final int SMS_VERIFICATION_MAXLEN = 4;
private static final String SMS_VERIFY_PREFIX = "sms:verify:";
private static SmsSender smsSender =null;
@Value("${sms.is.debug}")
private Boolean isDebug;
......@@ -43,87 +46,83 @@ public class SmsServiceImpl implements ISmsService {
return smsSender;
}
@Override
public void sendAfterRegister(String phoneNo) {
try {
MsgParams msgParams = new MsgParams(Collections.singletonList(2), phoneNo, "1", "24", Collections.emptyList());
smsSender.sendMsg(msgParams);
//smsSender.sendAndForget(new SendAndForgetMsg(Collections.emptyList(), "24", "1", phoneNo));
LOGGER.info("注册完成,发送短信, phoneNo:{}", phoneNo);
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void sendAfterRegister(String phoneNo, String contentId) {
try {
if (StringUtils.isBlank(contentId)) {
contentId = "24";
}
MsgParams msgParams = new MsgParams(Collections.singletonList(2), phoneNo, "1", contentId, Collections.emptyList());
smsSender.sendMsg(msgParams);
LOGGER.info("注册完成,发送短信, phoneNo:{}", phoneNo);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 检查验证码是否正确
*
* @param phoneNo
* @param smsVerificationCode
* @return
*/
@Override
public boolean validRegisterOrResetPasswdVerificationCode(String phoneNo, String smsVerificationCode) {
//if (StringUtils.isEmpty(smsVerificationCode) || smsVerificationCode.length() != SMS_VERIFICATION_MAXLEN) {
// return false;
//}
String key = Constants.REDIS_PREFIX_VERIFICATION_CODE + phoneNo;
String randomCode = stringRedisTemplate.opsForValue().get(key);
if (StringUtils.isEmpty(randomCode)) {
return false;
}
String[] arr = randomCode.split(":");
String unqiueId = arr[0];
String code = arr[1];
return confirmSms(smsVerificationCode, unqiueId, code);
@Override
public void sendAfterRegister(String phoneNo) {
try {
MsgParams msgParams =
new MsgParams(Collections.singletonList(2), phoneNo, "1", "24", Collections.emptyList());
smsSender.sendMsg(msgParams);
//smsSender.sendAndForget(new SendAndForgetMsg(Collections.emptyList(), "24", "1", phoneNo));
log.info("注册完成,发送短信, phoneNo:{}", phoneNo);
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public boolean validateFastLoginVerificationCode(String phoneNo, String verificationCode) {
String key = Constants.REDIS_PREFIX_VERIFICATION_CODE + phoneNo;
String randomCode = stringRedisTemplate.opsForValue().get(key);
if (StringUtils.isBlank(randomCode)) {
return false;
}
String[] arr = randomCode.split(":");
if (arr.length != 2) {
return false;
}
String uniqueId = arr[0];
String code = arr[1];
return confirmSms(verificationCode, uniqueId, code);
@Override
public void sendAfterRegister(String phoneNo, String contentId) {
try {
if (StringUtils.isBlank(contentId)) {
contentId = "24";
}
MsgParams msgParams = new MsgParams(Collections.singletonList(2), phoneNo, "1", contentId,
Collections.emptyList());
smsSender.sendMsg(msgParams);
log.info("注册完成,发送短信, phoneNo:{}", phoneNo);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 检查验证码是否正确
*/
@Override
public boolean validRegisterOrResetPasswdVerificationCode(String phoneNo,
String smsVerificationCode) {
//if (StringUtils.isEmpty(smsVerificationCode) || smsVerificationCode.length() != SMS_VERIFICATION_MAXLEN) {
// return false;
//}
String key = Constants.REDIS_PREFIX_VERIFICATION_CODE + phoneNo;
String randomCode = stringRedisTemplate.opsForValue().get(key);
if (StringUtils.isEmpty(randomCode)) {
return false;
}
String[] arr = randomCode.split(":");
String uniqueId = arr[0];
String code = arr[1];
return confirmSms(smsVerificationCode, uniqueId, code);
}
private boolean confirmSms(String smsVerificationCode, String unqiueId, String code) {
try {
MsgParams message = new MsgParams(Collections.singletonList(2), unqiueId);
//MsgParams messageVoice = new MsgParams(Collections.singletonList(4), unqiueId);
getSmsSender().confirmMsg(message);
//getSmsSender().confirmMsg(messageVoice);
//smsSender.confirmSmsResult("1", unqiueId);
LOGGER.info("confirmMsg send success, uniqueId={}", unqiueId);
} catch (Exception e) {
LOGGER.info("短信验证向短信中心确认失效");
}
if (StringUtils.equals(code, smsVerificationCode)) {
return true;
}
return false;
@Override
public boolean validateFastLoginVerificationCode(String phoneNo, String verificationCode) {
String key = Constants.REDIS_PREFIX_VERIFICATION_CODE + phoneNo;
String randomCode = stringRedisTemplate.opsForValue().get(key);
if (StringUtils.isBlank(randomCode)) {
return false;
}
String[] arr = randomCode.split(":");
if (arr.length != 2) {
return false;
}
String uniqueId = arr[0];
String code = arr[1];
return confirmSms(verificationCode, uniqueId, code);
}
private boolean confirmSms(String smsVerificationCode, String unqiueId, String code) {
try {
MsgParams message = new MsgParams(Collections.singletonList(2), unqiueId);
//MsgParams messageVoice = new MsgParams(Collections.singletonList(4), unqiueId);
getSmsSender().confirmMsg(message);
//getSmsSender().confirmMsg(messageVoice);
//smsSender.confirmSmsResult("1", unqiueId);
log.info("confirmMsg send success, uniqueId={}", unqiueId);
} catch (Exception e) {
log.info("短信验证向短信中心确认失效");
}
return StringUtils.equals(code, smsVerificationCode);
}
}
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