Przeglądaj źródła

新增验证码错误处理

刘韬 3 lat temu
rodzic
commit
2c81638f32

+ 6 - 1
PacsOnline_Wechat_Doctor/src/main/java/com/zskk/controller/WxaUserApiController.java

@@ -350,7 +350,12 @@ public class WxaUserApiController extends WxaController {
 		// 获取sessionKey
 		String openid = sessionResult.getString("openid");
 		SmsService sService = ServiceFactory.getService(SmsService.class);
-		LoginBean loginBean = sService.checkCode(phone, code, openid);
+		String content = sService.checkCodeStore(phone,code);
+		if (content == null) {
+			renderJson(ErrorConstant.ERROR_SMS_CODE_ERR);
+			return;
+		}
+		LoginBean loginBean = sService.checkCode(openid,phone);
 		if (loginBean != null) {
 			loginBean.setSessionId(sessionId);
 			renderJson(new ResultBean(loginBean));

+ 32 - 21
PacsOnline_Wechat_Doctor/src/main/java/com/zskk/service/SmsService.java

@@ -62,36 +62,47 @@ public class SmsService {
         return Boolean.FALSE;
 	}
 
-	public LoginBean checkCode(String phone,String code, String openid) {
+	/*
+	 * 检查code是否存在和正确
+	 */
+	public String checkCodeStore(String phone,String code) {
 		String cacheKey = "SMS_CODE_" + phone;
 		String content = Redis.use("weixin_doctor").get(cacheKey);
 		if (content != null && content.equals(code)) {
 			Redis.use().del(cacheKey);
-			Doctors doctors = Doctors.dao.findFirst("select * from doctors where phone=?", phone);
-			if (doctors == null) {
-				return null;
-			}
-			DoctorsWechat doctorsWechat = DoctorsWechat.dao.findFirst("select * from doctors_wechat where wxa_openid=?", openid);
-			doctorsWechat.setDoctorId(doctors.getId());
-			doctorsWechat.update();
-			LoginBean loginBean = new LoginBean();
-			doctors.setPassword("");
-			DoctorBean doctorBean = JSON.parseObject(doctors.toJson(), DoctorBean.class);
-			Institution institution = Institution.dao.findById(doctorBean.getInstitution_id());
-			doctorBean.setInstitution(institution.getName());
-			StringBuilder sb = new StringBuilder(doctorBean.getPhone());
-			sb.replace(3, 7, "****");
-			doctorBean.setPhone(sb.toString());
-			String tokenKey = "TOKEN_WXA_" + StrKit.getRandomUUID();
-			Redis.use("pc").setex("think" + tokenKey, 7200, doctors.toJson());
-			loginBean.setDoctorBean(doctorBean);
-			loginBean.setToken(tokenKey);
-			return loginBean;
+			return content;
 		}else {
 			return null;
 		}
 	}
 	
+	/*
+	 * 检查code正确性
+	 */
+	public LoginBean checkCode(String openid,String phone) {
+		Doctors doctors = Doctors.dao.findFirst("select * from doctors where phone=?", phone);
+		if (doctors == null) {
+			return null;
+		}
+		DoctorsWechat doctorsWechat = DoctorsWechat.dao.findFirst("select * from doctors_wechat where wxa_openid=?",
+				openid);
+		doctorsWechat.setDoctorId(doctors.getId());
+		doctorsWechat.update();
+		LoginBean loginBean = new LoginBean();
+		doctors.setPassword("");
+		DoctorBean doctorBean = JSON.parseObject(doctors.toJson(), DoctorBean.class);
+		Institution institution = Institution.dao.findById(doctorBean.getInstitution_id());
+		doctorBean.setInstitution(institution.getName());
+		StringBuilder sb = new StringBuilder(doctorBean.getPhone());
+		sb.replace(3, 7, "****");
+		doctorBean.setPhone(sb.toString());
+		String tokenKey = "TOKEN_WXA_" + StrKit.getRandomUUID();
+		Redis.use("pc").setex("think" + tokenKey, 7200, doctors.toJson());
+		loginBean.setDoctorBean(doctorBean);
+		loginBean.setToken(tokenKey);
+		return loginBean;
+	}
+	
 	/*
 	 * 生成四位验证码
 	 */

+ 2 - 0
PacsOnline_Wechat_Doctor/src/main/java/com/zskk/util/ErrorConstant.java

@@ -11,4 +11,6 @@ public class ErrorConstant {
 	public static final ResultBean ERROR_DOCTOR_NOT_FIND = new ResultBean(100, "用户手机号未找到");
 	public static final ResultBean ERROR_PHONE_BLANK = new ResultBean(101, "用户未绑定手机号");
 	public static final ResultBean ERROR_SMS_SEND = new ResultBean(102, "验证码发送失败");	
+	public static final ResultBean ERROR_SMS_CODE_ERR = new ResultBean(103, "验证码错误");	
+
 }