|
@@ -7,10 +7,7 @@ import com.caimei365.user.components.RedisService;
|
|
|
import com.caimei365.user.components.WeChatService;
|
|
|
import com.caimei365.user.mapper.*;
|
|
|
import com.caimei365.user.model.ResponseJson;
|
|
|
-import com.caimei365.user.model.dto.AuthBindDto;
|
|
|
-import com.caimei365.user.model.dto.LoginPasswordDto;
|
|
|
-import com.caimei365.user.model.dto.ScanBindDto;
|
|
|
-import com.caimei365.user.model.dto.SuperVipDto;
|
|
|
+import com.caimei365.user.model.dto.*;
|
|
|
import com.caimei365.user.model.po.OperationPo;
|
|
|
import com.caimei365.user.model.po.SuperVipPo;
|
|
|
import com.caimei365.user.model.vo.*;
|
|
@@ -19,6 +16,7 @@ import com.caimei365.user.service.RemoteCallService;
|
|
|
import com.caimei365.user.utils.JwtUtil;
|
|
|
import com.caimei365.user.utils.MathUtil;
|
|
|
import com.caimei365.user.utils.Md5Util;
|
|
|
+import com.caimei365.user.utils.ValidateUtil;
|
|
|
import com.github.pagehelper.PageHelper;
|
|
|
import com.github.pagehelper.PageInfo;
|
|
|
import lombok.SneakyThrows;
|
|
@@ -28,6 +26,7 @@ import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.http.HttpHeaders;
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.util.ObjectUtils;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.text.ParseException;
|
|
@@ -150,6 +149,61 @@ public class LoginServiceImpl implements LoginService {
|
|
|
return ResponseJson.error("账户名与密码不匹配,请重新输入", null);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @param loginCodeDto {
|
|
|
+ * mobile 手机号
|
|
|
+ * code 短信验证码
|
|
|
+ * }
|
|
|
+ * @return
|
|
|
+ * @throws ParseException
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ResponseJson<UserLoginVo> codeLogin(LoginCodeDto loginCodeDto) throws ParseException {
|
|
|
+ if (ObjectUtils.isEmpty(loginCodeDto.getMobile())) {
|
|
|
+ return ResponseJson.error("请填写手机号",null);
|
|
|
+ }
|
|
|
+ if (ObjectUtils.isEmpty(loginCodeDto.getCode())) {
|
|
|
+ return ResponseJson.error("请输入短信验证码",null);
|
|
|
+ }
|
|
|
+ String mobile = loginCodeDto.getMobile();
|
|
|
+ String code = loginCodeDto.getCode();
|
|
|
+ String result = ValidateUtil.validateMobile(mobile);
|
|
|
+ if (result != null) {
|
|
|
+ return ResponseJson.error(result);
|
|
|
+ }
|
|
|
+ // 判断redis中是否存在
|
|
|
+ boolean exists = redisService.exists("code:" + mobile);
|
|
|
+ if (exists) {
|
|
|
+ // 查看验证码是否过期
|
|
|
+ long expireTime = redisService.getExpireTime("code:" + mobile);
|
|
|
+ if (expireTime < 0) {
|
|
|
+ return ResponseJson.error("验证码已过期,请重新获取验证码");
|
|
|
+ }
|
|
|
+ // 获取redis手机短信验证码
|
|
|
+ Object randomCode = redisService.get("code:"+mobile);
|
|
|
+
|
|
|
+ if (!ObjectUtils.isEmpty(randomCode)) {
|
|
|
+ if (code.equals(randomCode.toString())) {
|
|
|
+ // 根据手机号获取用户信息
|
|
|
+ UserLoginVo baseUser = loginMapper.getLoginUserByMobileOrEmail(mobile);
|
|
|
+ if (baseUser.getUserIdentity() == 1) {
|
|
|
+ // 协销登录
|
|
|
+ return ResponseJson.success(baseUser);
|
|
|
+ } else {
|
|
|
+ // 返回登录校验结果
|
|
|
+ return logonVerify(baseUser);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ return ResponseJson.error("验证码不匹配,请重新输入");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ return ResponseJson.error("验证码为空,请重新获取");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ return ResponseJson.error("手机验证码不存在,请重新获取");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 微信授权登录(小程序)
|
|
|
*
|
|
@@ -982,6 +1036,53 @@ public class LoginServiceImpl implements LoginService {
|
|
|
return ResponseJson.success("绑定微信成功", user);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 绑定运营人员短信验证
|
|
|
+ *
|
|
|
+ * @param loginCodeDto {
|
|
|
+ * mobile 手机号
|
|
|
+ * code 短信验证码
|
|
|
+ * }
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ResponseJson<String> operateVerification(LoginCodeDto loginCodeDto) {
|
|
|
+ if (ObjectUtils.isEmpty(loginCodeDto.getMobile())) {
|
|
|
+ return ResponseJson.error("请输入手机号",null);
|
|
|
+ }
|
|
|
+ if (ObjectUtils.isEmpty(loginCodeDto.getCode())) {
|
|
|
+ return ResponseJson.error("请输入验证码",null);
|
|
|
+ }
|
|
|
+ String mobile = loginCodeDto.getMobile();
|
|
|
+ String code = loginCodeDto.getCode();
|
|
|
+ String result = ValidateUtil.validateMobile(mobile);
|
|
|
+ if (result != null) {
|
|
|
+ return ResponseJson.error(result);
|
|
|
+ }
|
|
|
+ // 判断redis中是否存在
|
|
|
+ boolean exists = redisService.exists("code:" + mobile);
|
|
|
+ if (exists) {
|
|
|
+ // 校验验证码是否过期
|
|
|
+ long expireTime = redisService.getExpireTime("code:" + mobile);
|
|
|
+ if (expireTime < 0) {
|
|
|
+ return ResponseJson.error("验证码已失效,请重新获取");
|
|
|
+ }
|
|
|
+ // 获取redis缓存验证码
|
|
|
+ Object randomCode = redisService.get("code:" + mobile);
|
|
|
+ if (!ObjectUtils.isEmpty(randomCode)) {
|
|
|
+ if (code.equals(randomCode.toString())) {
|
|
|
+ return ResponseJson.success("验证码匹配成功");
|
|
|
+ } else {
|
|
|
+ return ResponseJson.error("验证码不匹配,请重新输入");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ return ResponseJson.error("验证码为空,请重新获取");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ return ResponseJson.error("验证码不存在,请重新获取");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 根据userId查是否过期,返回dto对象,flag=0未买过,-1过期,1有效,endTime过期时间
|
|
|
*/
|