From 29a8c526f810dd371ce709eaa0a06a211a7e898c Mon Sep 17 00:00:00 2001 From: "DESKTOP-G8BCEP0\\HP" <2037158277@qq.com> Date: Wed, 15 Sep 2021 09:40:32 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=86=E7=BB=91=E5=AE=9A?= =?UTF-8?q?=E7=BD=91=E7=AB=99=E8=B4=A6=E5=8F=B7=E7=9A=84=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=EF=BC=8C=E6=B7=BB=E5=8A=A0=E9=87=8D=E5=A4=8D=E7=BB=91=E5=AE=9A?= =?UTF-8?q?=E7=9A=84=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/xkrs/controller/SysUserController.java | 9 +++++++-- src/main/java/com/xkrs/dao/SysUserDao.java | 8 ++++++++ .../java/com/xkrs/service/impl/SysUserServiceImpl.java | 5 ++--- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/xkrs/controller/SysUserController.java b/src/main/java/com/xkrs/controller/SysUserController.java index a735a39..bc306c5 100644 --- a/src/main/java/com/xkrs/controller/SysUserController.java +++ b/src/main/java/com/xkrs/controller/SysUserController.java @@ -17,6 +17,7 @@ import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; +import javax.servlet.http.HttpServletResponse; import java.util.HashMap; import java.util.List; import java.util.Locale; @@ -247,9 +248,9 @@ public class SysUserController { * @return */ @PostMapping("/findUserByOpenId") - public String findUserByOpenId(@RequestBody Map map){ + public String findUserByOpenId(@RequestBody Map map, HttpServletResponse response){ String openId = (String) map.get("openId"); - return sysUserService.findUserByOpenId(openId); + return sysUserService.findUserByOpenId(openId,response); } /** @@ -267,6 +268,10 @@ public class SysUserController { if(byUserName == null){ return outputEncapsulationObject(PromptMessageEnum.DATA_NONE,"输入错误或未注册,请检查注册!",locale); } + SysUserEntity byOpenId = sysUserDao.findByOpenId(openId); + if(byOpenId != null){ + return outputEncapsulationObject(PromptMessageEnum.PROCESS_FAIL,"您已绑定网站账号,请勿重复绑定!",locale); + } sysUserDao.updateOpenIdByPhone(phone,openId); return outputEncapsulationObject(PromptMessageEnum.SUCCESS,"绑定成功!",locale); } diff --git a/src/main/java/com/xkrs/dao/SysUserDao.java b/src/main/java/com/xkrs/dao/SysUserDao.java index 43e83d3..7e46f37 100644 --- a/src/main/java/com/xkrs/dao/SysUserDao.java +++ b/src/main/java/com/xkrs/dao/SysUserDao.java @@ -144,4 +144,12 @@ public interface SysUserDao extends JpaRepository { @Query(value = "update sys_user set open_id = ?2 where user_name = ?1",nativeQuery = true) @Modifying(clearAutomatically=true) void updateOpenIdByPhone(String userName,String openId); + + /** + * 根据openId和手机号查询信息 + * @param openId + * @param userName + * @return + */ + SysUserEntity findByOpenIdAndUserName(String openId,String userName); } diff --git a/src/main/java/com/xkrs/service/impl/SysUserServiceImpl.java b/src/main/java/com/xkrs/service/impl/SysUserServiceImpl.java index da50b52..88bbb0c 100644 --- a/src/main/java/com/xkrs/service/impl/SysUserServiceImpl.java +++ b/src/main/java/com/xkrs/service/impl/SysUserServiceImpl.java @@ -246,13 +246,13 @@ public class SysUserServiceImpl implements SysUserService { * @return */ @Override - public String findUserByOpenId(String openId) { + public String findUserByOpenId(String openId,HttpServletResponse response) { Locale locale = LocaleContextHolder.getLocale(); Map map = new HashMap(3); SysUserEntity byOpenId = sysUserDao.findByOpenId(openId); if(byOpenId == null){ map.put("type","0"); - return outputEncapsulationObject(PromptMessageEnum.PROCESS_FAIL,map,locale); + return outputEncapsulationObject(PromptMessageEnum.DATA_NONE,map,locale); }else { // 设置权限列表 ArrayList permissions = new ArrayList<>(); @@ -263,7 +263,6 @@ public class SysUserServiceImpl implements SysUserService { } // 生成令牌 Authentication authToken = new UsernamePasswordAuthenticationToken(byOpenId.getUserName(), byOpenId.getPassword(), permissions); - HttpServletResponse response = null; response.setHeader("Access-Control-Allow-Origin", "*"); response.setHeader("Access-Control-Allow-Credentials", "false"); response.setContentType("application/json");