wangwei 6 vuotta sitten
vanhempi
commit
2611de74bd

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

@@ -1,7 +1,9 @@
 package cn.com.qmth.examcloud.core.basic.api.controller;
 
+import org.apache.commons.lang3.RandomUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
@@ -11,8 +13,14 @@ import org.springframework.web.bind.annotation.RestController;
 import cn.com.qmth.examcloud.commons.base.exception.StatusException;
 import cn.com.qmth.examcloud.commons.web.security.bean.User;
 import cn.com.qmth.examcloud.commons.web.support.ControllerSupport;
+import cn.com.qmth.examcloud.core.basic.dao.StudentRepo;
+import cn.com.qmth.examcloud.core.basic.dao.entity.Student;
 import cn.com.qmth.examcloud.core.basic.service.AuthService;
 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;
+import cn.com.qmth.examcloud.exchange.inner.api.request.SendSmsReq;
+import cn.com.qmth.examcloud.exchange.inner.api.response.CheckIdentifyingCodeResp;
 import io.swagger.annotations.ApiOperation;
 
 /**
@@ -29,6 +37,30 @@ public class AuthController extends ControllerSupport {
 	@Autowired
 	AuthService authService;
 
+	@Autowired
+	SendSmsCloudService sendSmsCloudService;
+
+	@Autowired
+	StudentRepo studentRepo;
+
+	@Value("${$sendVerificationCode.sign}")
+	private String smsSign;
+
+	@Value("${$sendVerificationCode.templatecode}")
+	private String smsTemplatecode;
+
+	/**
+	 * 短信验证码有效期/秒
+	 */
+	@Value("${$sendVerificationCode.effectivetime}")
+	private Integer smsEffectivetime;
+
+	/**
+	 * 短信验证码 发送间隔时间/秒
+	 */
+	@Value("${$sendVerificationCode.intervalseconds}")
+	private Integer smsIntervalSeconds;
+
 	@ApiOperation(value = "登入", notes = "")
 	@PostMapping("login")
 	public User login(@RequestBody LoginInfo loginInfo) {
@@ -68,4 +100,41 @@ public class AuthController extends ControllerSupport {
 		return authService.thirdPartyAccess(orgId, loginName, appId, timestamp, token);
 	}
 
+	@ApiOperation(value = "发送验证码", notes = "")
+	@PostMapping("/bindSecurityPhone")
+	public void sendVerificationCode(@RequestParam String phone) {
+		SendSmsReq req = new SendSmsReq();
+		req.setPhone(phone);
+		int code = 1000 + RandomUtils.nextInt(1, 9999);
+		req.setCode(String.valueOf(code));
+		req.setEffectiveTime(smsEffectivetime);
+		req.setIntervalSeconds(smsIntervalSeconds);
+		req.setSign(smsSign);
+		req.setTemplateCode(smsTemplatecode);
+		sendSmsCloudService.sendIdentifyingCode(req);
+	}
+
+	@ApiOperation(value = "绑定手机号", notes = "")
+	@PostMapping("/bindSecurityPhone")
+	public void bindSecurityPhone(@RequestParam String phone,
+			@RequestParam String verificationCode) {
+		CheckSmsCodeReq req = new CheckSmsCodeReq();
+		req.setCode(verificationCode);
+		req.setPhone(phone);
+		CheckIdentifyingCodeResp resp = sendSmsCloudService.checkIdentifyingCode(req);
+		if (!resp.getSuccess()) {
+			throw new StatusException("B-001050", "验证码错误");
+		}
+
+		User accessUser = getAccessUser();
+		Long studentId = accessUser.getStudentId();
+
+		if (null != studentId) {
+			Student s = studentRepo.findOne(studentId);
+			s.setSecurityPhone(phone);
+		} else {
+			throw new StatusException("B-001051", "绑定失败");
+		}
+	}
+
 }

+ 7 - 0
examcloud-core-basic-service/pom.xml

@@ -20,6 +20,13 @@
 			<artifactId>data-sync-rabbit</artifactId>
 			<version>1.0-SNAPSHOT</version>
 		</dependency>
+
+		<dependency>
+			<groupId>cn.com.qmth.examcloud.exchange</groupId>
+			<artifactId>examcloud-exchange-inner-api-client</artifactId>
+			<version>${examcloud.version}</version>
+		</dependency>
+
 	</dependencies>
 
 </project>

+ 5 - 0
examcloud-core-basic-starter/src/main/resources/application.properties

@@ -22,3 +22,8 @@ spring.jackson.time-zone=GMT+8
 
 $rmp.ctr.basic=/api/ecs_core
 $rmp.cloud.basic=/api/core/basic/
+
+$sendVerificationCode.sign=\u8003\u8BD5\u4E91\u5E73\u53F0
+$sendVerificationCode.templatecode=SMS_138073780
+$sendVerificationCode.effectivetime=120
+$sendVerificationCode.intervalseconds=90