Commit 5f0f7ec6 authored by ycl's avatar ycl

format

parent 921b6f8d
...@@ -306,7 +306,7 @@ ...@@ -306,7 +306,7 @@
<dependency> <dependency>
<groupId>cn.quantgroup</groupId> <groupId>cn.quantgroup</groupId>
<artifactId>quantgroup-sms-sdk</artifactId> <artifactId>quantgroup-sms-sdk</artifactId>
<version>3.0</version> <version>3.1</version>
</dependency> </dependency>
</dependencies> </dependencies>
......
...@@ -4,34 +4,36 @@ import cn.quantgroup.sms.MsgParams; ...@@ -4,34 +4,36 @@ import cn.quantgroup.sms.MsgParams;
import cn.quantgroup.sms.SmsSender; import cn.quantgroup.sms.SmsSender;
import cn.quantgroup.xyqb.Constants; import cn.quantgroup.xyqb.Constants;
import cn.quantgroup.xyqb.service.sms.ISmsService; import cn.quantgroup.xyqb.service.sms.ISmsService;
import java.util.Collections;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.Collections;
/** /**
* @author mengfan.feng * @author mengfan.feng
* @time 2015-07-25 18:47 * @time 2015-07-25 18:47
*/ */
@Service @Service
@Slf4j
public class SmsServiceImpl implements ISmsService { public class SmsServiceImpl implements ISmsService {
private static final Logger LOGGER = LoggerFactory.getLogger(SmsServiceImpl.class);
private static final int SMS_VERIFICATION_MAXLEN = 4; private static final int SMS_VERIFICATION_MAXLEN = 4;
private static final String SMS_VERIFY_PREFIX = "sms:verify:"; private static final String SMS_VERIFY_PREFIX = "sms:verify:";
private static final SmsSender smsSender = new SmsSender(); private static SmsSender smsSender = new SmsSender();
@Value("${sms.is.debug}") @Value("${sms.is.debug}")
private Boolean isDebug; private Boolean isDebug;
private final RedisTemplate<String, String> stringRedisTemplate;
@Autowired @Autowired
@Qualifier("stringRedisTemplate") public SmsServiceImpl(
private RedisTemplate<String, String> stringRedisTemplate; @Qualifier("stringRedisTemplate") RedisTemplate<String, String> stringRedisTemplate) {
this.stringRedisTemplate = stringRedisTemplate;
}
@Override @Override
public SmsSender getSmsSender() { public SmsSender getSmsSender() {
...@@ -41,10 +43,11 @@ public class SmsServiceImpl implements ISmsService { ...@@ -41,10 +43,11 @@ public class SmsServiceImpl implements ISmsService {
@Override @Override
public void sendAfterRegister(String phoneNo) { public void sendAfterRegister(String phoneNo) {
try { try {
MsgParams msgParams = new MsgParams(Collections.singletonList(2), phoneNo, "1", "24", Collections.emptyList()); MsgParams msgParams =
new MsgParams(Collections.singletonList(2), phoneNo, "1", "24", Collections.emptyList());
smsSender.sendMsg(msgParams); smsSender.sendMsg(msgParams);
//smsSender.sendAndForget(new SendAndForgetMsg(Collections.emptyList(), "24", "1", phoneNo)); //smsSender.sendAndForget(new SendAndForgetMsg(Collections.emptyList(), "24", "1", phoneNo));
LOGGER.info("注册完成,发送短信, phoneNo:{}", phoneNo); log.info("注册完成,发送短信, phoneNo:{}", phoneNo);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
...@@ -56,9 +59,10 @@ public class SmsServiceImpl implements ISmsService { ...@@ -56,9 +59,10 @@ public class SmsServiceImpl implements ISmsService {
if (StringUtils.isBlank(contentId)) { if (StringUtils.isBlank(contentId)) {
contentId = "24"; contentId = "24";
} }
MsgParams msgParams = new MsgParams(Collections.singletonList(2), phoneNo, "1", contentId, Collections.emptyList()); MsgParams msgParams = new MsgParams(Collections.singletonList(2), phoneNo, "1", contentId,
Collections.emptyList());
smsSender.sendMsg(msgParams); smsSender.sendMsg(msgParams);
LOGGER.info("注册完成,发送短信, phoneNo:{}", phoneNo); log.info("注册完成,发送短信, phoneNo:{}", phoneNo);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
...@@ -66,13 +70,10 @@ public class SmsServiceImpl implements ISmsService { ...@@ -66,13 +70,10 @@ public class SmsServiceImpl implements ISmsService {
/** /**
* 检查验证码是否正确 * 检查验证码是否正确
*
* @param phoneNo
* @param smsVerificationCode
* @return
*/ */
@Override @Override
public boolean validRegisterOrResetPasswdVerificationCode(String phoneNo, String smsVerificationCode) { public boolean validRegisterOrResetPasswdVerificationCode(String phoneNo,
String smsVerificationCode) {
//if (StringUtils.isEmpty(smsVerificationCode) || smsVerificationCode.length() != SMS_VERIFICATION_MAXLEN) { //if (StringUtils.isEmpty(smsVerificationCode) || smsVerificationCode.length() != SMS_VERIFICATION_MAXLEN) {
// return false; // return false;
//} //}
...@@ -82,9 +83,9 @@ public class SmsServiceImpl implements ISmsService { ...@@ -82,9 +83,9 @@ public class SmsServiceImpl implements ISmsService {
return false; return false;
} }
String[] arr = randomCode.split(":"); String[] arr = randomCode.split(":");
String unqiueId = arr[0]; String uniqueId = arr[0];
String code = arr[1]; String code = arr[1];
return confirmSms(smsVerificationCode, unqiueId, code); return confirmSms(smsVerificationCode, uniqueId, code);
} }
@Override @Override
...@@ -103,7 +104,6 @@ public class SmsServiceImpl implements ISmsService { ...@@ -103,7 +104,6 @@ public class SmsServiceImpl implements ISmsService {
return confirmSms(verificationCode, uniqueId, code); return confirmSms(verificationCode, uniqueId, code);
} }
private boolean confirmSms(String smsVerificationCode, String unqiueId, String code) { private boolean confirmSms(String smsVerificationCode, String unqiueId, String code) {
try { try {
MsgParams message = new MsgParams(Collections.singletonList(2), unqiueId); MsgParams message = new MsgParams(Collections.singletonList(2), unqiueId);
...@@ -111,14 +111,10 @@ public class SmsServiceImpl implements ISmsService { ...@@ -111,14 +111,10 @@ public class SmsServiceImpl implements ISmsService {
getSmsSender().confirmMsg(message); getSmsSender().confirmMsg(message);
//getSmsSender().confirmMsg(messageVoice); //getSmsSender().confirmMsg(messageVoice);
//smsSender.confirmSmsResult("1", unqiueId); //smsSender.confirmSmsResult("1", unqiueId);
LOGGER.info("confirmMsg send success, uniqueId={}", unqiueId); log.info("confirmMsg send success, uniqueId={}", unqiueId);
} catch (Exception e) { } catch (Exception e) {
LOGGER.info("短信验证向短信中心确认失效"); log.info("短信验证向短信中心确认失效");
} }
if (StringUtils.equals(code, smsVerificationCode)) { return StringUtils.equals(code, smsVerificationCode);
return true;
} }
return false;
}
} }
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