|
@@ -4,6 +4,7 @@ import nju.seec.helper.service.CodeService;
|
|
|
import nju.seec.helper.util.CacheUtils;
|
|
import nju.seec.helper.util.CacheUtils;
|
|
|
import nju.seec.helper.util.Consts;
|
|
import nju.seec.helper.util.Consts;
|
|
|
import nju.seec.helper.util.MailUtils;
|
|
import nju.seec.helper.util.MailUtils;
|
|
|
|
|
+import nju.seec.helper.util.SmsUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
import java.util.Random;
|
|
import java.util.Random;
|
|
@@ -15,19 +16,22 @@ import java.util.concurrent.TimeUnit;
|
|
|
@Service
|
|
@Service
|
|
|
public class CodeServiceImpl implements CodeService {
|
|
public class CodeServiceImpl implements CodeService {
|
|
|
private static final int MAIL_CODE_LIVING_MINUTES = 5;
|
|
private static final int MAIL_CODE_LIVING_MINUTES = 5;
|
|
|
|
|
+ private static final int PHONE_CODE_LIVING_MINUTES = 5;
|
|
|
|
|
|
|
|
private final MailUtils mailUtils;
|
|
private final MailUtils mailUtils;
|
|
|
|
|
+ private final SmsUtils smsUtils;
|
|
|
private final CacheUtils cacheUtils;
|
|
private final CacheUtils cacheUtils;
|
|
|
|
|
|
|
|
- public CodeServiceImpl(MailUtils mailUtils, CacheUtils cacheUtils) {
|
|
|
|
|
|
|
+ public CodeServiceImpl(MailUtils mailUtils, SmsUtils smsUtils, CacheUtils cacheUtils) {
|
|
|
this.mailUtils = mailUtils;
|
|
this.mailUtils = mailUtils;
|
|
|
|
|
+ this.smsUtils = smsUtils;
|
|
|
this.cacheUtils = cacheUtils;
|
|
this.cacheUtils = cacheUtils;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public void sendEmailCode(String email) {
|
|
public void sendEmailCode(String email) {
|
|
|
String code = getSixBitsCode();
|
|
String code = getSixBitsCode();
|
|
|
- mailUtils.sendSimpleMailMessage("【南京大学】", String.format("您的验证码:%s,该验证码%d分钟内有效,请勿泄漏于他人!", code, MAIL_CODE_LIVING_MINUTES), email);
|
|
|
|
|
|
|
+ mailUtils.sendSimpleMailMessage(String.format("您的验证码:%s,%d分钟内有效,请勿泄漏于他人!", code, MAIL_CODE_LIVING_MINUTES), email);
|
|
|
cacheUtils.set(Consts.EMAIL_CACHE_NAME, email, code, MAIL_CODE_LIVING_MINUTES, TimeUnit.MINUTES);
|
|
cacheUtils.set(Consts.EMAIL_CACHE_NAME, email, code, MAIL_CODE_LIVING_MINUTES, TimeUnit.MINUTES);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -37,6 +41,8 @@ public class CodeServiceImpl implements CodeService {
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public void sendPhoneCode(String phone) {
|
|
public void sendPhoneCode(String phone) {
|
|
|
-
|
|
|
|
|
|
|
+ String code = getSixBitsCode();
|
|
|
|
|
+ smsUtils.sendSmsCode(phone, code);
|
|
|
|
|
+ cacheUtils.set(Consts.PHONE_CACHE_NAME, phone, code, PHONE_CODE_LIVING_MINUTES, TimeUnit.MINUTES);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|