From 9ce4c64d842f706148a18aed998759440e3f8b45 Mon Sep 17 00:00:00 2001 From: Stormeye Wu Date: Thu, 28 Feb 2019 10:05:29 +0800 Subject: [PATCH] =?UTF-8?q?[=E5=BE=AE=E4=BF=A1=E7=AC=AC=E4=B8=89=E6=96=B9?= =?UTF-8?q?=E7=99=BB=E5=BD=95][=E4=BF=AE=E6=94=B9]:=E5=BE=AE=E4=BF=A1?= =?UTF-8?q?=E7=AC=AC=E4=B8=89=E6=96=B9=E7=99=BB=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/iformall/config/ShiroConfig.java | 3 +- .../controller/WechatLoginController.java | 101 +++++++++--------- 2 files changed, 54 insertions(+), 50 deletions(-) diff --git a/mallinkAdmin/src/main/java/com/iformall/config/ShiroConfig.java b/mallinkAdmin/src/main/java/com/iformall/config/ShiroConfig.java index f9296893f..0014d2ed5 100644 --- a/mallinkAdmin/src/main/java/com/iformall/config/ShiroConfig.java +++ b/mallinkAdmin/src/main/java/com/iformall/config/ShiroConfig.java @@ -99,7 +99,8 @@ public class ShiroConfig { // login filterChainDefinitionMap.put("/doLogin/**", "anon"); filterChainDefinitionMap.put("/bHidLogin/**", "anon"); - filterChainDefinitionMap.put("/wechat/callback", "anon"); // 微信第三方登录 + filterChainDefinitionMap.put("/wechat/callback", "anon"); // 微信第三方登录 + filterChainDefinitionMap.put("/wechat/weChatUserLogin", "anon"); // 微信第三方登录 // callback filterChainDefinitionMap.put("/wxPay/notify/**", "anon"); // 支付回调 filterChainDefinitionMap.put("/wxPayBill/notify/**", "anon"); diff --git a/mallinkAdmin/src/main/java/com/iformall/controller/WechatLoginController.java b/mallinkAdmin/src/main/java/com/iformall/controller/WechatLoginController.java index f68aebe89..d3c1a7e18 100644 --- a/mallinkAdmin/src/main/java/com/iformall/controller/WechatLoginController.java +++ b/mallinkAdmin/src/main/java/com/iformall/controller/WechatLoginController.java @@ -16,6 +16,7 @@ import com.iformall.utils.TOTP; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; +import lombok.Data; import lombok.extern.slf4j.Slf4j; import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.mp.api.WxMpService; @@ -32,6 +33,7 @@ import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; +import java.util.ArrayList; import java.util.List; @@ -50,6 +52,13 @@ public class WechatLoginController extends BaseController { @Autowired private MallUserRoleService mallUserRoleService; + @Data + private class DisplayUserInfo { + String mallName; + String userName; + String userRole; + } + @ApiOperation(value = "微信网页登录回调", notes = "请配置此callback到网页redirect_uri") @GetMapping("callback") @ResponseBody @@ -103,9 +112,18 @@ public class WechatLoginController extends BaseController { // 跳转登录选择页面 String key = TOTP.generateWechatOpen(accessToken.getOpenId()); RedisUtils redisUtils = new RedisUtils(); - redisUtils.set(WECHAT_PREV + key, JSON.toJSONString(userList)); + redisUtils.set(WECHAT_PREV + key, accessToken.getOpenId()); + List users = new ArrayList(); + for(MallUserInfoVo user: userList) { + DisplayUserInfo disUser = new DisplayUserInfo(); + disUser.setMallName(user.getMallName()); + disUser.setUserName(user.getUsername()); + disUser.setUserRole(user.getRoleName()); + users.add(disUser); + } + String usersStr = JSON.toJSONString(users); try { - response.sendRedirect("https://" + host + "/#/loginselect?key=" + key); + response.sendRedirect("https://" + host + "/#/loginselect?key=" + key + "&list=" + usersStr); } catch (Exception e) { log.error(e.getMessage()); } @@ -124,70 +142,55 @@ public class WechatLoginController extends BaseController { } } - @ApiOperation(value = "微信登录用户信息列表") - @GetMapping("getMallUserList") - @ApiImplicitParams({ - @ApiImplicitParam(name = "key", value = "key", dataType = "String", paramType = "query", required = true)}) - public ResultData getMallUserList(String key) { - log.debug("[" + getIpAddr() + "] MallUserInfoController::getMallUserList"); - String openKey = WECHAT_PREV + key; - RedisUtils redisUtils = new RedisUtils(); - if(redisUtils.hasKey(openKey)) { - String userList = redisUtils.get(openKey); - return new ResultData(userList); - } - return new ResultData(ErrorCode.WECHAT_LOGIN_KEY_OVERTIME); - } - @ApiOperation(value = "微信用户登录") @GetMapping("weChatUserLogin") @ApiImplicitParams({ @ApiImplicitParam(name = "key", value = "key", dataType = "String", paramType = "query", required = true), - @ApiImplicitParam(name = "username", value = "username", dataType = "String", paramType = "query", required = true)}) - public void weChatUserLogin(String username, String key, HttpServletRequest request, HttpServletResponse response) { + @ApiImplicitParam(name = "userName", value = "userName", dataType = "String", paramType = "query", required = true)}) + public void weChatUserLogin(String userName, String key, HttpServletRequest request, HttpServletResponse response) { log.debug("[" + getIpAddr() + "] MallUserInfoController::weChatUserLogin"); String host = request.getHeader("host"); String openKey = WECHAT_PREV + key; RedisUtils redisUtils = new RedisUtils(); + // 限时时间内查找到此用户openId if(redisUtils.hasKey(openKey)) { - String userList = redisUtils.get(openKey); + String openId = redisUtils.get(openKey); // 删除缓存 redisUtils.delete(openKey); - JSONArray userArr = JSON.parseArray(userList); - for(int i=0;i