diff --git a/mall-account/src/main/java/com/suisung/mall/account/controller/LoginController.java b/mall-account/src/main/java/com/suisung/mall/account/controller/LoginController.java index c81ab6e3..389ad0ac 100644 --- a/mall-account/src/main/java/com/suisung/mall/account/controller/LoginController.java +++ b/mall-account/src/main/java/com/suisung/mall/account/controller/LoginController.java @@ -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) { diff --git a/mall-account/src/main/java/com/suisung/mall/account/service/impl/AccountUserBaseServiceImpl.java b/mall-account/src/main/java/com/suisung/mall/account/service/impl/AccountUserBaseServiceImpl.java index 8c2a1082..3be6fe85 100644 --- a/mall-account/src/main/java/com/suisung/mall/account/service/impl/AccountUserBaseServiceImpl.java +++ b/mall-account/src/main/java/com/suisung/mall/account/service/impl/AccountUserBaseServiceImpl.java @@ -2976,44 +2976,38 @@ public class AccountUserBaseServiceImpl extends BaseServiceImpl 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 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