From 9fd569d446b9f1a74c4b28147a3572ee8a076825 Mon Sep 17 00:00:00 2001 From: hu177768073 <177768073@qq.com> Date: Wed, 30 Oct 2024 14:15:28 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/hfkj/controller/ClientController.java | 7 +++---- .../java/com/hfkj/controller/UserController.java | 7 +++++-- .../service/user/impl/BsUserServiceImpl.java | 16 ++++++++-------- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/cweb/src/main/java/com/hfkj/controller/ClientController.java b/cweb/src/main/java/com/hfkj/controller/ClientController.java index fbf3b6a..eb41c3a 100644 --- a/cweb/src/main/java/com/hfkj/controller/ClientController.java +++ b/cweb/src/main/java/com/hfkj/controller/ClientController.java @@ -93,8 +93,8 @@ public class ClientController { Long inviteUseId = body.getLong("inviteUseId"); Map params = new HashMap<>(); - params.put("appid", "wxa075e8509802f826"); - params.put("secret", "0e606fc1378d35e359fcf3f15570b2c5"); + params.put("appid", "wxadc7c8cd025639c6"); + params.put("secret", "3b11012a83de870c2a81fb52d6427fce"); params.put("code", body.getString("code")); params.put("grant_type", "authorization_code"); JSONObject accessToken = HttpsUtils.doGet("https://api.weixin.qq.com/sns/oauth2/access_token", params); @@ -114,9 +114,8 @@ public class ClientController { user.setName(userinfo.getString("nickname")); user.setWechatOpenId(userinfo.getString("openid")); user.setWechatUnionid(userinfo.getString("unionid")); - userService.weChatAuth(user, new HashMap<>(), inviteUseId); + return ResponseMsgUtil.success(userService.weChatAuth(user, new HashMap<>(), inviteUseId)); - return ResponseMsgUtil.success(userinfo); } catch (Exception e) { return ResponseMsgUtil.exception(e); } diff --git a/cweb/src/main/java/com/hfkj/controller/UserController.java b/cweb/src/main/java/com/hfkj/controller/UserController.java index 540047f..5556a84 100644 --- a/cweb/src/main/java/com/hfkj/controller/UserController.java +++ b/cweb/src/main/java/com/hfkj/controller/UserController.java @@ -342,8 +342,8 @@ public class UserController { throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "已绑定过微信"); } Map params = new HashMap<>(); - params.put("appid", "wxa075e8509802f826"); - params.put("secret", "0e606fc1378d35e359fcf3f15570b2c5"); + params.put("appid", "wxadc7c8cd025639c6"); + params.put("secret", "3b11012a83de870c2a81fb52d6427fce"); params.put("code", body.getString("code")); params.put("grant_type", "authorization_code"); JSONObject accessToken = HttpsUtils.doGet("https://api.weixin.qq.com/sns/oauth2/access_token", params); @@ -358,6 +358,9 @@ public class UserController { if (userinfo == null || StringUtils.isBlank(userinfo.getString("openid"))) { throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "获取用户信息失败"); } + if (userService.getUserByWechatOpenId(userinfo.getString("openid")) != null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "微信已被绑定,无法重复绑定"); + } BsUser user = userSession.getUser(); user.setWechatOpenId(userinfo.getString("openid")); user.setWechatUnionid(userinfo.getString("unionid")); diff --git a/service/src/main/java/com/hfkj/service/user/impl/BsUserServiceImpl.java b/service/src/main/java/com/hfkj/service/user/impl/BsUserServiceImpl.java index f4f02f0..539f5e6 100644 --- a/service/src/main/java/com/hfkj/service/user/impl/BsUserServiceImpl.java +++ b/service/src/main/java/com/hfkj/service/user/impl/BsUserServiceImpl.java @@ -295,24 +295,24 @@ public class BsUserServiceImpl implements BsUserService { bsUser.setWechatUnionid(user.getWechatUnionid()); bsUser.setGrade(UserGradeEnum.grade1.getCode()); bsUser.setStatus(UserStatusEnum.status1.getCode()); - editData(user); + editData(bsUser); // 创建账户余额 - userAccountService.create(user.getId()); + userAccountService.create(bsUser.getId()); } else { bsUser.setHeadImg(user.getHeadImg()); bsUser.setName(user.getName()); - user.setInviteUserId(inviteUseId); - user.setInviteTime(new Date()); - updateInfo(user); + bsUser.setInviteUserId(inviteUseId); + bsUser.setInviteTime(new Date()); + updateInfo(bsUser); } // 缓存 UserSessionObject session = new UserSessionObject(); - session.setUser(user); - SessionObject sessionObject = new SessionObject(userToken(user.getId()), session); + session.setUser(bsUser); + SessionObject sessionObject = new SessionObject(userToken(bsUser.getId()), session); userCenter.save(sessionObject); // 异步记录登录信息 - userLoginLogService.asyncCreateLog(UserLoginType.WECHAT_AUTH, user, (HttpServletRequest) RequestContextHolder.getRequestAttributes().resolveReference(RequestAttributes.REFERENCE_REQUEST)); + userLoginLogService.asyncCreateLog(UserLoginType.WECHAT_AUTH, bsUser, (HttpServletRequest) RequestContextHolder.getRequestAttributes().resolveReference(RequestAttributes.REFERENCE_REQUEST)); return sessionObject; }