商家代理商登录注册优化
This commit is contained in:
parent
a457667dbe
commit
fa874887a3
@ -244,11 +244,11 @@ public class LoginController extends BaseControllerImpl {
|
||||
String randKey = paramJSON.getStr("rand_key");
|
||||
String verifyCode = paramJSON.getStr("verify_code");
|
||||
|
||||
if (StrUtil.isBlank(userMobile) || StrUtil.isBlank(randKey) || StrUtil.isBlank(verifyCode)) {
|
||||
if (StrUtil.hasBlank(userMobile, randKey, verifyCode)) {
|
||||
return CommonResult.failed("缺少必要参数!");
|
||||
}
|
||||
|
||||
// 检查输入字符是不是包含 sql 注入特征,如果包含不给以通过
|
||||
// 检查输入字符是否包含 SQL 注入特征
|
||||
if (!CommonService.isValidInput(userMobile, randKey, verifyCode)) {
|
||||
return CommonResult.failed(ResultCode.VALIDATE_INPUTS);
|
||||
}
|
||||
@ -256,12 +256,17 @@ public class LoginController extends BaseControllerImpl {
|
||||
String cid = paramJSON.getStr("cid");
|
||||
String osType = paramJSON.getStr("os_type");
|
||||
// 用户类型:0-普通买家; 1-管理员;2-入驻商家;3-代理商;
|
||||
Integer userType = paramJSON.getInt("user_type");
|
||||
Integer userType = paramJSON.getInt("user_type", CommonConstant.USER_TYPE_MCH);
|
||||
// 修正逻辑:当用户类型既不是商家也不是代理商时,设置为默认商家类型
|
||||
if (!CommonConstant.USER_TYPE_MCH.equals(userType) && !CommonConstant.USER_TYPE_AGENT.equals(userType)) {
|
||||
userType = CommonConstant.USER_TYPE_MCH;
|
||||
}
|
||||
String inviteCode = paramJSON.getStr("invite_code", "");
|
||||
|
||||
return accountUserBaseService.doMerchSmsRegisterAndLogin(userMobile, randKey, verifyCode, userType, cid, osType, inviteCode);
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation(value = "微信用户一键登录与注册")
|
||||
@RequestMapping(value = "/doWxUserRegisterAndLogin", method = RequestMethod.POST)
|
||||
public CommonResult doWxUserRegisterAndLogin(@RequestBody WxUserInfoReq wxUserInfoReq) {
|
||||
|
||||
@ -2976,44 +2976,38 @@ public class AccountUserBaseServiceImpl extends BaseServiceImpl<AccountUserBaseM
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public CommonResult doMerchSmsRegisterAndLogin(String user_mobile, String rand_key, String verify_code, Integer userType, String cid, String osType, String inviteCode) {
|
||||
// 流程:通过手机号检查是否有绑定关系?没有就直接注册,有就直接登录,返回登录后的所有信息,附加是否已经申请入驻标记?
|
||||
// 商家入驻账号,都是需要手机号绑定的。账号组成:1000000+(数字加法)自增ID,密码随机6位数
|
||||
if (StrUtil.isBlank(user_mobile) || StrUtil.isBlank(verify_code)) {
|
||||
public CommonResult doMerchSmsRegisterAndLogin(String user_mobile, String rand_key, String verify_code,
|
||||
Integer userType, String cid, String osType, String inviteCode) {
|
||||
// 参数验证
|
||||
if (StrUtil.hasBlank(user_mobile, rand_key, verify_code)) {
|
||||
return CommonResult.failed(_("缺少必要参数!"));
|
||||
}
|
||||
|
||||
// 验证手机号格式
|
||||
if (!PhoneNumberUtils.checkPhoneNumber(user_mobile)) {
|
||||
return CommonResult.failed(_("请输入正确的手机号!"));
|
||||
}
|
||||
|
||||
if (StrUtil.isBlank(rand_key)) {
|
||||
return CommonResult.failed(_("程序非法请求, 检测验证码键值!"));
|
||||
}
|
||||
|
||||
if (StrUtil.isBlank(verify_code)) {
|
||||
return CommonResult.failed(_("请输入验证码!"));
|
||||
}
|
||||
|
||||
// rmk 为什么随机数和手机号一致?
|
||||
if (ObjectUtil.notEqual(user_mobile, rand_key)) {
|
||||
// 验证防刷机制
|
||||
if (!ObjectUtil.equal(user_mobile, rand_key)) {
|
||||
return CommonResult.failed(_("非法数据,请刷新页面重新提交!"));
|
||||
}
|
||||
|
||||
String verifyMobile = PhoneNumberUtils.convZhPhoneNumber(user_mobile);
|
||||
// TODO 短信验证码切换到正式平台,记得注释 9999
|
||||
|
||||
// 验证验证码 (TODO 短信验证码切换到正式平台,记得注释 9999)
|
||||
if (!checkVerifyCode(verifyMobile, verify_code)) {
|
||||
// 短信验证码
|
||||
return CommonResult.failed(_("验证码错误!"));
|
||||
}
|
||||
|
||||
userType = CheckUtil.isEmpty(userType) ? CommonConstant.USER_TYPE_MCH : userType;
|
||||
// 设置默认用户类型
|
||||
userType = ObjectUtil.defaultIfNull(userType, CommonConstant.USER_TYPE_MCH);
|
||||
|
||||
// 找出手机对应的绑定用户
|
||||
// 是否为手机号注册,密码6位随机数
|
||||
// 找出手机对应的绑定用户,进行绑定登录
|
||||
return doMobileBindLogin(verifyMobile, userType, cid, osType, inviteCode);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 微信小程序一键登录注册接口
|
||||
*
|
||||
@ -3299,45 +3293,42 @@ public class AccountUserBaseServiceImpl extends BaseServiceImpl<AccountUserBaseM
|
||||
return CommonResult.failed("缺少必要参数!");
|
||||
}
|
||||
|
||||
// 检查输入字符是不是包含 sql 注入特征,如果包含不给以通过
|
||||
// 检查输入字符是否包含 SQL 注入特征
|
||||
if (!CommonService.isValidInput(user_mobile, cid, osType)) {
|
||||
return CommonResult.failed(ResultCode.VALIDATE_INPUTS);
|
||||
}
|
||||
|
||||
AccountUserBase accountUserBase;
|
||||
// 查询绑定手机的商家账号
|
||||
AccountUserBindConnect bind_row = accountUserBindConnectService.getBindByBindId(user_mobile, BindCode.MOBILE, userType);
|
||||
AccountUserBase accountUserBase;
|
||||
if (bind_row != null) {
|
||||
|
||||
// 已经注册账号的,绑定了手机的情况,
|
||||
// 已绑定账号的情况
|
||||
Integer user_id = bind_row.getUser_id();
|
||||
accountUserBase = get(user_id);
|
||||
if (accountUserBase == null) {
|
||||
return CommonResult.failed("获取不到用户信息!");
|
||||
}
|
||||
|
||||
} else {
|
||||
// 手机号码未绑定的情况,直接去注册一个账号
|
||||
// 手机号码未绑定,注册新账号
|
||||
Map<String, Object> userInfo = new HashMap<>();
|
||||
userInfo.put("user_account", user_mobile);
|
||||
userInfo.put("user_mobile", user_mobile);
|
||||
userInfo.put("user_is_admin", userType); // 商家或代理商入驻注册
|
||||
String user_password = regPwd;
|
||||
if (StrUtil.isBlank(user_password)) {
|
||||
// 随机数明文密码
|
||||
user_password = com.suisung.mall.common.utils.StringUtils.random(6, com.suisung.mall.common.utils.StringUtils.RandomType.STRING);
|
||||
}
|
||||
|
||||
String user_password = StrUtil.isNotBlank(regPwd) ? regPwd :
|
||||
com.suisung.mall.common.utils.StringUtils.random(6, com.suisung.mall.common.utils.StringUtils.RandomType.STRING);
|
||||
|
||||
userInfo.put("user_password", user_password);
|
||||
userInfo.put("is_admin", userType); // 商家入驻注册
|
||||
userInfo.put("invite_code", StrUtil.isNotBlank(inviteCode) ? inviteCode : ""); // 商家注册代理商的邀请码
|
||||
|
||||
// 注:注册商家账号,都是需要手机号绑定的。
|
||||
accountUserBase = register(userInfo);
|
||||
if (accountUserBase == null) {
|
||||
throw new ApiException(_("账号注册失败!"));
|
||||
}
|
||||
}
|
||||
|
||||
// 构建登录参数
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put("client_id", CommonConstant.USER_TYPE_MCH.equals(userType) ? AuthConstant.MCH_CLIENT_ID : AuthConstant.MOBILE_CLIENT_ID);
|
||||
params.put("client_secret", AuthConstant.AUTHORITY_MOBILE_SECRET);
|
||||
@ -3351,12 +3342,13 @@ public class AccountUserBaseServiceImpl extends BaseServiceImpl<AccountUserBaseM
|
||||
|
||||
if (StrUtil.isNotBlank(cid)) {
|
||||
params.put("cid", cid); // 个推客户端Id
|
||||
params.put("os_type", osType);// 个推客系统类别 1-Android;2-iOS;3-微信小程序;
|
||||
params.put("os_type", osType); // 个推客系统类别 1-Android;2-iOS;3-微信小程序;
|
||||
}
|
||||
|
||||
return login(params);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 商家内部注册(服务之间调用)
|
||||
*
|
||||
|
||||
Loading…
Reference in New Issue
Block a user