增加绑定手机号接口
This commit is contained in:
parent
1cde7463fe
commit
5a0043fcd2
|
|
@ -0,0 +1,43 @@
|
|||
package com.mdd.common.enums;
|
||||
|
||||
/**
|
||||
* 通知枚举类
|
||||
*/
|
||||
public enum NoticeEnum {
|
||||
|
||||
SMS_LOGIN_CODE(101, "登录验证码"),
|
||||
SMS_BIND_MOBILE_CODE(102, "绑定手机验证码"),
|
||||
SMS_CHANGE_MOBILE_CODE(103, "变更手机验证码"),
|
||||
SMS_FORGOT_PASSWORD_CODE(104, "找回登录密码验证码");
|
||||
|
||||
/**
|
||||
* 构造方法
|
||||
*/
|
||||
private final int code;
|
||||
private final String msg;
|
||||
NoticeEnum(int code, String msg) {
|
||||
this.code = code;
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取状态码
|
||||
*
|
||||
* @author fzr
|
||||
* @return Long
|
||||
*/
|
||||
public int getCode() {
|
||||
return this.code;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取提示
|
||||
*
|
||||
* @author fzr
|
||||
* @return String
|
||||
*/
|
||||
public String getMsg() {
|
||||
return this.msg;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -66,7 +66,11 @@ public class UserController {
|
|||
* @return Object
|
||||
*/
|
||||
@PostMapping("/bindMobile")
|
||||
public Object bindMobile() {
|
||||
public Object bindMobile(@RequestBody Map<String, String> params) {
|
||||
Assert.notNull(params.get("mobile"), "mobile参数缺失");
|
||||
Assert.notNull(params.get("code"), "code参数缺失");
|
||||
Integer userId = LikeFrontThreadLocal.getUserId();
|
||||
iUserService.bindMobile(params, userId);
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -37,6 +37,15 @@ public interface IUserService {
|
|||
*/
|
||||
void edit(Map<String, String> params, Integer userId);
|
||||
|
||||
/**
|
||||
* 绑定手机
|
||||
*
|
||||
* @author fzr
|
||||
* @param params 参数
|
||||
* @param userId 用户ID
|
||||
*/
|
||||
void bindMobile(Map<String, String> params, Integer userId);
|
||||
|
||||
/**
|
||||
* 微信手机
|
||||
*
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import com.mdd.common.config.GlobalConfig;
|
|||
import com.mdd.common.entity.user.User;
|
||||
import com.mdd.common.entity.user.UserAuth;
|
||||
import com.mdd.common.enums.ClientEnum;
|
||||
import com.mdd.common.enums.NoticeEnum;
|
||||
import com.mdd.common.exception.OperateException;
|
||||
import com.mdd.common.mapper.user.UserAuthMapper;
|
||||
import com.mdd.common.mapper.user.UserMapper;
|
||||
|
|
@ -189,7 +190,8 @@ public class LoginServiceImpl implements ILoginService {
|
|||
String code = params.get("code").toLowerCase();
|
||||
|
||||
// 校验验证码
|
||||
Object smsCode = RedisUtil.get(GlobalConfig.redisSmsCode+"101:"+mobile);
|
||||
int typeCode = NoticeEnum.SMS_LOGIN_CODE.getCode();
|
||||
Object smsCode = RedisUtil.get(GlobalConfig.redisSmsCode+typeCode+":"+mobile);
|
||||
if (StringUtil.isNull(smsCode) || !smsCode.toString().equals(code)) {
|
||||
throw new OperateException("验证码错误!");
|
||||
}
|
||||
|
|
@ -266,7 +268,8 @@ public class LoginServiceImpl implements ILoginService {
|
|||
String password = params.get("password");
|
||||
|
||||
// 校验验证码
|
||||
Object smsCode = RedisUtil.get(GlobalConfig.redisSmsCode+"104:"+mobile);
|
||||
int typeCode = NoticeEnum.SMS_FORGOT_PASSWORD_CODE.getCode();
|
||||
Object smsCode = RedisUtil.get(GlobalConfig.redisSmsCode+typeCode+":"+mobile);
|
||||
if (StringUtil.isNull(smsCode) || !smsCode.toString().equals(code)) {
|
||||
throw new OperateException("验证码错误!");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,18 +6,17 @@ import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
|
|||
import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.mdd.common.config.GlobalConfig;
|
||||
import com.mdd.common.entity.server.Sys;
|
||||
import com.mdd.common.entity.system.SystemConfig;
|
||||
import com.mdd.common.entity.user.User;
|
||||
import com.mdd.common.entity.user.UserAuth;
|
||||
import com.mdd.common.enums.ClientEnum;
|
||||
import com.mdd.common.enums.NoticeEnum;
|
||||
import com.mdd.common.exception.OperateException;
|
||||
import com.mdd.common.mapper.system.SystemConfigMapper;
|
||||
import com.mdd.common.mapper.user.UserAuthMapper;
|
||||
import com.mdd.common.mapper.user.UserMapper;
|
||||
import com.mdd.common.utils.ConfigUtil;
|
||||
import com.mdd.common.utils.StringUtil;
|
||||
import com.mdd.common.utils.TimeUtil;
|
||||
import com.mdd.common.utils.UrlUtil;
|
||||
import com.mdd.common.utils.*;
|
||||
import com.mdd.front.service.IUserService;
|
||||
import com.mdd.front.vo.user.UserCenterVo;
|
||||
import com.mdd.front.vo.user.UserInfoVo;
|
||||
|
|
@ -164,6 +163,40 @@ public class UserServiceImpl implements IUserService {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 绑定手机
|
||||
*
|
||||
* @author fzr
|
||||
* @param params 参数
|
||||
* @param userId 用户ID
|
||||
*/
|
||||
@Override
|
||||
public void bindMobile(Map<String, String> params, Integer userId) {
|
||||
String mobile = params.getOrDefault("mobile", "");
|
||||
String code = params.getOrDefault("code", "").toLowerCase();
|
||||
|
||||
// 校验验证码
|
||||
int typeCode = NoticeEnum.SMS_BIND_MOBILE_CODE.getCode();
|
||||
Object smsCode = RedisUtil.get(GlobalConfig.redisSmsCode+typeCode+":"+mobile);
|
||||
if (StringUtil.isNull(smsCode) || !smsCode.toString().equals(code)) {
|
||||
throw new OperateException("验证码错误!");
|
||||
}
|
||||
|
||||
User user = userMapper.selectOne(new QueryWrapper<User>()
|
||||
.select("id,username,mobile")
|
||||
.eq("mobile", mobile)
|
||||
.eq("is_delete", 0)
|
||||
.last("limit 1"));
|
||||
|
||||
if (StringUtil.isNotNull(user) && user.getId().equals(userId)) {
|
||||
throw new OperateException("手机号已被其它账号绑定!");
|
||||
}
|
||||
|
||||
user.setMobile(mobile);
|
||||
user.setUpdateTime(System.currentTimeMillis() / 1000);
|
||||
userMapper.updateById(user);
|
||||
}
|
||||
|
||||
/**
|
||||
* 微信手机号
|
||||
*
|
||||
|
|
|
|||
Loading…
Reference in New Issue