WANG 6 жил өмнө
parent
commit
96ea89a266

+ 45 - 0
examcloud-core-basic-api-provider/src/main/java/cn/com/qmth/examcloud/core/basic/api/controller/AuthController.java

@@ -22,6 +22,7 @@ import cn.com.qmth.examcloud.core.basic.base.constants.PropKeys;
 import cn.com.qmth.examcloud.core.basic.dao.StudentRepo;
 import cn.com.qmth.examcloud.core.basic.dao.entity.StudentEntity;
 import cn.com.qmth.examcloud.core.basic.service.AuthService;
+import cn.com.qmth.examcloud.core.basic.service.StudentService;
 import cn.com.qmth.examcloud.core.basic.service.bean.LoginInfo;
 import cn.com.qmth.examcloud.exchange.inner.api.SendSmsCloudService;
 import cn.com.qmth.examcloud.exchange.inner.api.request.CheckSmsCodeReq;
@@ -50,6 +51,9 @@ public class AuthController extends ControllerSupport {
 	@Autowired
 	StudentRepo studentRepo;
 
+	@Autowired
+	StudentService studentService;
+
 	@ApiOperation(value = "登入", notes = "")
 	@PostMapping("login")
 	public Object login(@RequestBody LoginInfo loginInfo, HttpServletRequest request) {
@@ -113,6 +117,47 @@ public class AuthController extends ControllerSupport {
 		return authService.thirdPartyAccess(orgId, loginName, appId, timestamp, token, realIp);
 	}
 
+	@ApiOperation(value = "发送验证码", notes = "")
+	@PostMapping("sendVerificationCode4Student")
+	public void sendVerificationCode4Student(@RequestParam(required = true) Long rootOrgId,
+			@RequestParam(required = true) String phone,
+			@RequestParam(required = true) Boolean bound) {
+
+		Boolean hasBeBound = studentService.hasBeBound(rootOrgId, phone);
+		if (bound && !hasBeBound.equals(bound)) {
+			throw new StatusException("B-002050", "手机号未被关联");
+		} else if ((!bound) && hasBeBound.equals(bound)) {
+			throw new StatusException("B-002050", "手机号已被关联");
+		}
+
+		SendSmsReq req = new SendSmsReq();
+		req.setPhone(phone);
+		int code = 1000 + RandomUtils.nextInt(1, 9999);
+		req.setCode(String.valueOf(code));
+
+		int smsEffectivetime = PropertiesUtil.getInt(PropKeys.SEND_VERIFICATION_CODE_EFFECTIVE_TIME,
+				120);
+		int smsIntervalSeconds = PropertiesUtil
+				.getInt(PropKeys.SEND_VERIFICATION_CODE_INTERVAL_SECONDS, 60);
+
+		String smsSign = PropertiesUtil.getString(PropKeys.SEND_VERIFICATION_CODE_SIGN);
+		String smsTemplatecode = PropertiesUtil
+				.getString(PropKeys.SEND_VERIFICATION_CODE_TEMPLATE_CODE);
+
+		if (StringUtils.isBlank(smsSign)) {
+			throw new StatusException("B-001060", "签名未配置");
+		}
+		if (StringUtils.isBlank(smsTemplatecode)) {
+			throw new StatusException("B-001061", "模板未配置");
+		}
+
+		req.setEffectiveTime(smsEffectivetime);
+		req.setIntervalSeconds(smsIntervalSeconds);
+		req.setSign(smsSign);
+		req.setTemplateCode(smsTemplatecode);
+		sendSmsCloudService.sendIdentifyingCode(req);
+	}
+
 	@ApiOperation(value = "发送验证码", notes = "")
 	@PostMapping("/sendVerificationCode")
 	public void sendVerificationCode(@RequestParam String phone) {

+ 12 - 2
examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/core/basic/service/StudentService.java

@@ -34,8 +34,8 @@ public interface StudentService {
 	 * @param securityPhone
 	 * @return
 	 */
-	StudentInfo getStudentInfo(Long rootOrgId, Long studentId, String identityNumber, String studentCode,
-			String securityPhone);
+	StudentInfo getStudentInfo(Long rootOrgId, Long studentId, String identityNumber,
+			String studentCode, String securityPhone);
 
 	/**
 	 * 解绑学号
@@ -46,4 +46,14 @@ public interface StudentService {
 	 */
 	List<Long> unbindStudentCode(Long rootOrgId, String studentCode, String identityNumber);
 
+	/**
+	 * 手机号码是否被绑定
+	 *
+	 * @author WANGWEI
+	 * @param rootOrgId
+	 * @param securityPhone
+	 * @return
+	 */
+	Boolean hasBeBound(Long rootOrgId, String securityPhone);
+
 }

+ 9 - 0
examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/core/basic/service/impl/StudentServiceImpl.java

@@ -331,4 +331,13 @@ public class StudentServiceImpl implements StudentService {
 		return studentIdList;
 	}
 
+	@Override
+	public Boolean hasBeBound(Long rootOrgId, String securityPhone) {
+		if (null == rootOrgId) {
+			throw new StatusException("B-120001", "rootOrgId is null");
+		}
+		StudentEntity s = studentRepo.findBySecurityPhoneAndRootOrgId(securityPhone, rootOrgId);
+		return null != s;
+	}
+
 }

+ 1 - 0
examcloud-core-basic-starter/src/main/resources/security-exclusions.conf

@@ -15,3 +15,4 @@ regexp:.*webjars.*
 [${$rmp.ctr.basic}/org][propertyNoSession/{key}][GET]
 
 
+