手机号授权:增加发送验证码校验授权逻辑
This commit is contained in:
@@ -23,4 +23,6 @@ public interface PhoneAuthApplyRecordService extends IService<PhoneAuthApplyReco
|
||||
void isVaild(String phone, String phoneAreaCode);
|
||||
|
||||
Boolean isBoundPhoneAuthCode(Long uid);
|
||||
|
||||
PhoneAuthApplyRecord getAuthApplyRecord(String phone, String phoneAreaCode);
|
||||
}
|
@@ -94,7 +94,7 @@ public class PhoneAuthApplyRecordServiceImpl extends ServiceImpl<PhoneAuthApplyR
|
||||
}
|
||||
}
|
||||
|
||||
private PhoneAuthApplyRecord getAuthApplyRecord(String phone, String phoneAreaCode) {
|
||||
public PhoneAuthApplyRecord getAuthApplyRecord(String phone, String phoneAreaCode) {
|
||||
QueryWrapper<PhoneAuthApplyRecord> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.lambda().eq(PhoneAuthApplyRecord::getPhone,phone).eq(PhoneAuthApplyRecord::getAuthCode,phoneAreaCode);
|
||||
return this.getOne(queryWrapper,false);
|
||||
@@ -172,12 +172,10 @@ public class PhoneAuthApplyRecordServiceImpl extends ServiceImpl<PhoneAuthApplyR
|
||||
}
|
||||
|
||||
// 更新使用邀請碼狀態
|
||||
if (!Constant.GlobalStatus.valid.equals(applyRecord.getHasUsed())) {
|
||||
applyRecord.setHasUsed(Constant.GlobalStatus.valid);
|
||||
this.saveOrUpdate(applyRecord);
|
||||
}
|
||||
applyRecord.setHasUsed(Constant.GlobalStatus.valid);
|
||||
this.saveOrUpdate(applyRecord);
|
||||
// 保存用戶綁定記錄
|
||||
PhoneAuthRecord record = buildPhoneAuthRecord(uid,realPhone,applyRecord.getId(),account.getPhoneAreaCode(),deviceInfo.getDeviceId());
|
||||
PhoneAuthRecord record = buildPhoneAuthRecord(uid,realPhone,applyRecord.getId(),applyRecord.getAuthCode(),deviceInfo.getDeviceId());
|
||||
phoneAuthRecordService.saveOrUpdate(record);
|
||||
} finally {
|
||||
jedisLockService.unlock(lockeKey,lockVal);
|
||||
@@ -262,10 +260,10 @@ public class PhoneAuthApplyRecordServiceImpl extends ServiceImpl<PhoneAuthApplyR
|
||||
return true;
|
||||
}
|
||||
|
||||
private PhoneAuthRecord buildPhoneAuthRecord(Long uid, String phone, Long authId, String phoneAreaCode, String deviceId) {
|
||||
private PhoneAuthRecord buildPhoneAuthRecord(Long uid, String phone, Long authId, String authCode, String deviceId) {
|
||||
PhoneAuthRecord record = new PhoneAuthRecord();
|
||||
record.setAuthId(authId);
|
||||
record.setAuthCode(phoneAreaCode);
|
||||
record.setAuthCode(authCode);
|
||||
record.setStatus(Constant.GlobalStatus.valid);
|
||||
record.setCreateTime(new Date());
|
||||
record.setUpdateTime(new Date());
|
||||
|
@@ -1,6 +1,7 @@
|
||||
package com.accompany.business.controller;
|
||||
|
||||
import com.accompany.business.common.BaseController;
|
||||
import com.accompany.common.constant.Constant;
|
||||
import com.accompany.common.constant.SmsTypeEnum;
|
||||
import com.accompany.common.device.DeviceInfo;
|
||||
import com.accompany.common.result.BusiResult;
|
||||
@@ -9,6 +10,8 @@ import com.accompany.common.utils.CommonUtil;
|
||||
import com.accompany.common.utils.IPUitls;
|
||||
import com.accompany.core.exception.ServiceException;
|
||||
import com.accompany.core.model.Users;
|
||||
import com.accompany.core.model.phone.PhoneAuthApplyRecord;
|
||||
import com.accompany.core.service.phone.PhoneAuthApplyRecordService;
|
||||
import com.accompany.core.service.user.PhoneBlackService;
|
||||
import com.accompany.core.service.user.UsersBaseService;
|
||||
import com.accompany.sms.service.SmsService;
|
||||
@@ -45,6 +48,8 @@ public class SmsController extends BaseController {
|
||||
private UsersBaseService usersBaseService;
|
||||
@Autowired
|
||||
private PhoneBlackService phoneBlackService;
|
||||
@Autowired
|
||||
private PhoneAuthApplyRecordService phoneAuthApplyRecordService;
|
||||
|
||||
private final static List<Integer> USE_PHONE_IN_PARAM_TYPES = Arrays.asList(SmsTypeEnum.REGISTER.value, SmsTypeEnum.LOGIN.value, SmsTypeEnum.SUPER_ADMIN_LOGIN.value,
|
||||
SmsTypeEnum.RESET_PASSWORD_FOR_NO_LOGIN.value, SmsTypeEnum.BINDING_PHONE.value);
|
||||
@@ -62,10 +67,14 @@ public class SmsController extends BaseController {
|
||||
log.info("需要通过uid获取用户已绑定的手机号");
|
||||
Users users = usersBaseService.getUsersByUid(uid);
|
||||
String userMobile = users == null ? mobile : users.getPhone();
|
||||
String userAreaCode = users == null ? phoneAreaCode : users.getPhoneAreaCode();
|
||||
// 如果headers里面有pub_uid,查询用户的手机号发送验证码
|
||||
mobile = userMobile != null && userMobile.length() == 11 ? userMobile : mobile;
|
||||
if (CommonUtil.checkPhoneFormat(userAreaCode,userMobile)) {
|
||||
mobile = userMobile;
|
||||
phoneAreaCode = userAreaCode;
|
||||
}
|
||||
}
|
||||
logger.info("sendSmsCode2, mobile:{}, type:{}, uid:{}", mobile, type, uid);
|
||||
logger.info("sendSmsCode2, mobile:{}, type:{}, uid:{}, phoneAreaCode:{} ", mobile, type, uid,phoneAreaCode);
|
||||
if (phoneBlackService.checkIsNeedInterceptWithPhoneAreaCode(phoneAreaCode,mobile)) {
|
||||
throw new ServiceException(BusiStatus.PHONE_BE_INTERCEPTED);
|
||||
}
|
||||
@@ -73,6 +82,13 @@ public class SmsController extends BaseController {
|
||||
return SmsTypeEnum.REGISTER.getValue() == type ? new BusiResult(BusiStatus.SMS_SEND_SUCCESS) :
|
||||
new BusiResult(BusiStatus.PHONE_INVALID);
|
||||
}
|
||||
// 对86手机进行授权码校验处理
|
||||
if (Constant.CHINA_MAINLAND_PHONE_AREA_CODE.equals(phoneAreaCode) && SmsTypeEnum.PHONE_AUTH_APPLY_CODE.value != type) {
|
||||
PhoneAuthApplyRecord applyRecord = phoneAuthApplyRecordService.getAuthApplyRecord(phoneAreaCode, mobile);
|
||||
if (applyRecord == null || !Constant.PhoneAuthApplyStatus.pass.equals(applyRecord.getStatus())) {
|
||||
throw new ServiceException("該地區暫不開放使用");
|
||||
}
|
||||
}
|
||||
return smsService.sendSmsCode(mobile, type, deviceInfo, ip, null);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user