商家代理商登录注册优化

This commit is contained in:
Jack 2026-01-27 11:14:08 +08:00
parent a457667dbe
commit fa874887a3
2 changed files with 32 additions and 35 deletions

View File

@ -244,11 +244,11 @@ public class LoginController extends BaseControllerImpl {
String randKey = paramJSON.getStr("rand_key"); String randKey = paramJSON.getStr("rand_key");
String verifyCode = paramJSON.getStr("verify_code"); 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("缺少必要参数!"); return CommonResult.failed("缺少必要参数!");
} }
// 检查输入字符是不是包含 sql 注入特征如果包含不给以通过 // 检查输入字符是否包含 SQL 注入特征
if (!CommonService.isValidInput(userMobile, randKey, verifyCode)) { if (!CommonService.isValidInput(userMobile, randKey, verifyCode)) {
return CommonResult.failed(ResultCode.VALIDATE_INPUTS); return CommonResult.failed(ResultCode.VALIDATE_INPUTS);
} }
@ -256,12 +256,17 @@ public class LoginController extends BaseControllerImpl {
String cid = paramJSON.getStr("cid"); String cid = paramJSON.getStr("cid");
String osType = paramJSON.getStr("os_type"); String osType = paramJSON.getStr("os_type");
// 用户类型:0-普通买家; 1-管理员2-入驻商家3-代理商 // 用户类型: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", ""); String inviteCode = paramJSON.getStr("invite_code", "");
return accountUserBaseService.doMerchSmsRegisterAndLogin(userMobile, randKey, verifyCode, userType, cid, osType, inviteCode); return accountUserBaseService.doMerchSmsRegisterAndLogin(userMobile, randKey, verifyCode, userType, cid, osType, inviteCode);
} }
@ApiOperation(value = "微信用户一键登录与注册") @ApiOperation(value = "微信用户一键登录与注册")
@RequestMapping(value = "/doWxUserRegisterAndLogin", method = RequestMethod.POST) @RequestMapping(value = "/doWxUserRegisterAndLogin", method = RequestMethod.POST)
public CommonResult doWxUserRegisterAndLogin(@RequestBody WxUserInfoReq wxUserInfoReq) { public CommonResult doWxUserRegisterAndLogin(@RequestBody WxUserInfoReq wxUserInfoReq) {

View File

@ -2976,44 +2976,38 @@ public class AccountUserBaseServiceImpl extends BaseServiceImpl<AccountUserBaseM
* @return * @return
*/ */
@Override @Override
public CommonResult doMerchSmsRegisterAndLogin(String user_mobile, String rand_key, String verify_code, Integer userType, String cid, String osType, String inviteCode) { 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)) { if (StrUtil.hasBlank(user_mobile, rand_key, verify_code)) {
return CommonResult.failed(_("缺少必要参数!")); return CommonResult.failed(_("缺少必要参数!"));
} }
// 验证手机号格式
if (!PhoneNumberUtils.checkPhoneNumber(user_mobile)) { if (!PhoneNumberUtils.checkPhoneNumber(user_mobile)) {
return CommonResult.failed(_("请输入正确的手机号!")); return CommonResult.failed(_("请输入正确的手机号!"));
} }
if (StrUtil.isBlank(rand_key)) { // 验证防刷机制
return CommonResult.failed(_("程序非法请求, 检测验证码键值!")); if (!ObjectUtil.equal(user_mobile, rand_key)) {
}
if (StrUtil.isBlank(verify_code)) {
return CommonResult.failed(_("请输入验证码!"));
}
// rmk 为什么随机数和手机号一致
if (ObjectUtil.notEqual(user_mobile, rand_key)) {
return CommonResult.failed(_("非法数据,请刷新页面重新提交!")); return CommonResult.failed(_("非法数据,请刷新页面重新提交!"));
} }
String verifyMobile = PhoneNumberUtils.convZhPhoneNumber(user_mobile); String verifyMobile = PhoneNumberUtils.convZhPhoneNumber(user_mobile);
// TODO 短信验证码切换到正式平台,记得注释 9999
// 验证验证码 (TODO 短信验证码切换到正式平台,记得注释 9999)
if (!checkVerifyCode(verifyMobile, verify_code)) { if (!checkVerifyCode(verifyMobile, verify_code)) {
// 短信验证码
return CommonResult.failed(_("验证码错误!")); 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); return doMobileBindLogin(verifyMobile, userType, cid, osType, inviteCode);
} }
/** /**
* 微信小程序一键登录注册接口 * 微信小程序一键登录注册接口
* *
@ -3299,45 +3293,42 @@ public class AccountUserBaseServiceImpl extends BaseServiceImpl<AccountUserBaseM
return CommonResult.failed("缺少必要参数!"); return CommonResult.failed("缺少必要参数!");
} }
// 检查输入字符是不是包含 sql 注入特征如果包含不给以通过 // 检查输入字符是否包含 SQL 注入特征
if (!CommonService.isValidInput(user_mobile, cid, osType)) { if (!CommonService.isValidInput(user_mobile, cid, osType)) {
return CommonResult.failed(ResultCode.VALIDATE_INPUTS); return CommonResult.failed(ResultCode.VALIDATE_INPUTS);
} }
AccountUserBase accountUserBase;
// 查询绑定手机的商家账号 // 查询绑定手机的商家账号
AccountUserBindConnect bind_row = accountUserBindConnectService.getBindByBindId(user_mobile, BindCode.MOBILE, userType); AccountUserBindConnect bind_row = accountUserBindConnectService.getBindByBindId(user_mobile, BindCode.MOBILE, userType);
AccountUserBase accountUserBase;
if (bind_row != null) { if (bind_row != null) {
// 已绑定账号的情况
// 已经注册账号的绑定了手机的情况
Integer user_id = bind_row.getUser_id(); Integer user_id = bind_row.getUser_id();
accountUserBase = get(user_id); accountUserBase = get(user_id);
if (accountUserBase == null) { if (accountUserBase == null) {
return CommonResult.failed("获取不到用户信息!"); return CommonResult.failed("获取不到用户信息!");
} }
} else { } else {
// 手机号码未绑定的情况直接去注册一个账号 // 手机号码未绑定注册新账号
Map<String, Object> userInfo = new HashMap<>(); Map<String, Object> userInfo = new HashMap<>();
userInfo.put("user_account", user_mobile); userInfo.put("user_account", user_mobile);
userInfo.put("user_mobile", user_mobile); userInfo.put("user_mobile", user_mobile);
userInfo.put("user_is_admin", userType); // 商家或代理商入驻注册 userInfo.put("user_is_admin", userType); // 商家或代理商入驻注册
String user_password = regPwd;
if (StrUtil.isBlank(user_password)) { String user_password = StrUtil.isNotBlank(regPwd) ? regPwd :
// 随机数明文密码 com.suisung.mall.common.utils.StringUtils.random(6, com.suisung.mall.common.utils.StringUtils.RandomType.STRING);
user_password = com.suisung.mall.common.utils.StringUtils.random(6, com.suisung.mall.common.utils.StringUtils.RandomType.STRING);
}
userInfo.put("user_password", user_password); userInfo.put("user_password", user_password);
userInfo.put("is_admin", userType); // 商家入驻注册 userInfo.put("is_admin", userType); // 商家入驻注册
userInfo.put("invite_code", StrUtil.isNotBlank(inviteCode) ? inviteCode : ""); // 商家注册代理商的邀请码 userInfo.put("invite_code", StrUtil.isNotBlank(inviteCode) ? inviteCode : ""); // 商家注册代理商的邀请码
// 注册商家账号都是需要手机号绑定的
accountUserBase = register(userInfo); accountUserBase = register(userInfo);
if (accountUserBase == null) { if (accountUserBase == null) {
throw new ApiException(_("账号注册失败!")); throw new ApiException(_("账号注册失败!"));
} }
} }
// 构建登录参数
Map<String, String> params = new HashMap<>(); 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_id", CommonConstant.USER_TYPE_MCH.equals(userType) ? AuthConstant.MCH_CLIENT_ID : AuthConstant.MOBILE_CLIENT_ID);
params.put("client_secret", AuthConstant.AUTHORITY_MOBILE_SECRET); params.put("client_secret", AuthConstant.AUTHORITY_MOBILE_SECRET);
@ -3351,12 +3342,13 @@ public class AccountUserBaseServiceImpl extends BaseServiceImpl<AccountUserBaseM
if (StrUtil.isNotBlank(cid)) { if (StrUtil.isNotBlank(cid)) {
params.put("cid", cid); // 个推客户端Id params.put("cid", cid); // 个推客户端Id
params.put("os_type", osType);// 个推客系统类别 1-Android2-iOS;3-微信小程序 params.put("os_type", osType); // 个推客系统类别 1-Android2-iOS;3-微信小程序
} }
return login(params); return login(params);
} }
/** /**
* 商家内部注册服务之间调用 * 商家内部注册服务之间调用
* *