1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- package com.charging.chargingparking.modules.mobileController;
- import java.util.Map;
- import javax.validation.constraints.NotBlank;
- import javax.validation.constraints.NotNull;
- import javax.validation.constraints.Pattern;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.validation.annotation.Validated;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RestController;
- import com.charging.chargingparking.dto.MessageResult;
- import com.charging.chargingparking.modules.mobileservice.MobileAuthService;
- import com.charging.chargingparking.utils.RespVO;
- import com.charging.chargingparking.utils.RespVOBuilder;
- import com.charging.chargingparking.utils.SMSUtil;
- @RestController
- @Validated
- @RequestMapping("/mobileApi/auth")
- public class MobileAuthController {
-
-
-
- @Autowired
- private VerifyCoder verifyCoder;
-
- @Autowired
- private MobileAuthService service;
- /**
- * 获取验证码
- * @param phoneNum
- * @return
- */
- @RequestMapping("/getVerifyCode")
- public RespVO getVerifyCode(@NotNull(message = "手机号不能为空") @Pattern(regexp = "^1[3-9]\\d{9}", message = "手机号无效") String phoneNum) {
- Map<String,Object> us=service.getUserByPhone(phoneNum);
- if(us==null||us.size()==0) {
- return RespVOBuilder.error("非系统内的用户");
- }
- String newCode=verifyCoder.generate(phoneNum);
- MessageResult msgRst=SMSUtil.send(phoneNum, SMSUtil.REG_TEMPLATE_CODE, "{\"code\":\""+newCode+"\"}");
- if(msgRst.isResult()) {
- return RespVOBuilder.ok();
- }
- else {
- return RespVOBuilder.error(msgRst.getMessage());
- }
-
- }
-
- /**
- * 验证登录信息
- * @param phoneNum
- * @param verifyCode
- * @return
- */
- @RequestMapping("/checkLogin")
- public RespVO checkLogin(@NotNull(message = "手机号不能为空") @Pattern(regexp = "^1[3-9]\\d{9}", message = "手机号无效") String phoneNum,@NotBlank(message = "验证码不能为空") String verifyCode) {
- Map<String,Object> us=service.getUserByPhone(phoneNum);
- if(us==null||us.size()==0) {
- return RespVOBuilder.error("非系统内的用户");
- }
-
- String refVerifyCode=verifyCoder.getFromSession(phoneNum);
- if(refVerifyCode==null) {
- return RespVOBuilder.error("验证码无效,请重新获取");
- }
- if(!verifyCode.equals(refVerifyCode)) {
- return RespVOBuilder.error("验证码输入错误");
- }
- //验证通过后,清除验证码缓存 测试时屏蔽,发布时启用
- verifyCoder.clear(phoneNum);
- return RespVOBuilder.ok(us);
- }
-
- /**
- * 第三方登录验证(内部系统)
- * @param unionPhone
- * @param unionid
- * @return
- */
- @RequestMapping("/loginThird")
- public RespVO loginThird(@NotNull(message = "缺少手机号") @Pattern(regexp = "^1[3-9]\\d{9}", message = "手机号无效") String unionPhone,
- @NotBlank(message ="缺少微信登录标识") String unionid) {
- Map<String,Object> us=service.getUserByPhone(unionPhone);
- if(us==null||us.size()==0) {
- return RespVOBuilder.error("非系统内的用户");
- }
- return RespVOBuilder.ok(us);
- }
- }
|