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");