手机号授权:检验手机号是否授权接口调整

This commit is contained in:
lzm
2022-11-28 17:42:57 +08:00
committed by yeungchihang
parent 424bc3fbda
commit a3732cb4b5
3 changed files with 38 additions and 6 deletions

View File

@@ -21,4 +21,6 @@ public interface PhoneAuthApplyRecordService extends IService<PhoneAuthApplyReco
Boolean isBoundPhoneAuthCode(String phone, String phoneAreaCode);
void isVaild(String phone, String phoneAreaCode);
Boolean isBoundPhoneAuthCode(Long uid);
}

View File

@@ -21,6 +21,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang.RandomStringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.ColumnMapRowMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -203,6 +204,37 @@ public class PhoneAuthApplyRecordServiceImpl extends ServiceImpl<PhoneAuthApplyR
}
}
@Override
public Boolean isBoundPhoneAuthCode(Long uid) {
Account account = accountService.getAccountByUid(uid);
if (account == null) {
throw new ServiceException(BusiStatus.USERNOTEXISTS);
}
String phoneAreaCode = account.getPhoneAreaCode();
String phone = account.getPhone();
if (!CommonUtil.checkPhoneFormat(phoneAreaCode,phone)) {
return false;
}
// 非86手机直接放行
if (!phone.startsWith(Constant.CHINA_MAINLAND_PHONE_AREA_CODE)) {
return true;
}
QueryWrapper<PhoneAuthApplyRecord> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(PhoneAuthApplyRecord::getPhone, phone);
PhoneAuthApplyRecord record = this.getOne(queryWrapper, false);
if (record == null) {
throw new ServiceException("該地區暫不開放使用");
}
// 还未填过
if (Constant.GlobalStatus.in_valid.equals(record.getHasUsed())) {
return false;
}
return true;
}
private PhoneAuthRecord buildPhoneAuthRecord(Long uid, String phone, Long authId, String phoneAreaCode, String deviceId) {
PhoneAuthRecord record = new PhoneAuthRecord();
record.setAuthId(authId);

View File

@@ -58,14 +58,12 @@ public class PhoneAuthApplyRecordController extends BaseController {
return new BusiResult(BusiStatus.SUCCESS);
}
@Authorization
@ApiOperation("用戶綁定的手機號是否 輸入過對應的授權碼")
@ApiImplicitParams({
@ApiImplicitParam(name = "phoneAreaCode", value = "区号", required = true, dataType = "String"),
@ApiImplicitParam(name = "phone", value = "手机号 如: 178xxxxxxxx", required = true, dataType = "String"),
})
@GetMapping("/isBoundPhoneAuthCode")
public BusiResult isBoundPhoneAuthCode(String phone,String phoneAreaCode) {
Boolean flag = phoneAuthApplyRecordService.isBoundPhoneAuthCode(phone,phoneAreaCode);
public BusiResult isBoundPhoneAuthCode(HttpServletRequest request) {
Long uid = getUid(request);
Boolean flag = phoneAuthApplyRecordService.isBoundPhoneAuthCode(uid);
return new BusiResult(BusiStatus.SUCCESS,flag);
}
}