| @@ -78,13 +78,8 @@ public class WechatLoginController extends BaseController { | |||
| log.debug("[" + getIpAddr() + "] MallUserInfoController::login"); | |||
| String host = request.getHeader("host"); | |||
| log.debug("Host: " + host); | |||
| String rUrl = ""; | |||
| try { | |||
| rUrl = URLEncoder.encode("https://mall.youlane.cn/api/wechat/callback","utf-8"); | |||
| } catch (UnsupportedEncodingException e) { | |||
| log.error(e.getMessage()); | |||
| } | |||
| String wechatUrl = wxMpService.buildQrConnectUrl("https://mall.youlane.cn/api/wechat/callback", "snsapi_login", "111"); | |||
| host = getHost(host); | |||
| String wechatUrl = wxMpService.buildQrConnectUrl("https://"+host+"/api/wechat/callback", "snsapi_login", "111"); | |||
| try { | |||
| response.sendRedirect(wechatUrl); | |||
| } catch (IOException e) { | |||
| @@ -92,6 +87,22 @@ public class WechatLoginController extends BaseController { | |||
| } | |||
| } | |||
| private String getHost(String host) { | |||
| if(host.contains("iformall.com")) { | |||
| if(host.contains("admintest")) { | |||
| host = "admin.malls.iformall.com"; | |||
| } else { | |||
| host = "admintest.malls.iformall.com"; | |||
| } | |||
| } else if(host.contains("youlane.cn")) { | |||
| host = "mall.youlane.cn"; | |||
| } else { | |||
| host = "admin.malls.iformall.com"; | |||
| } | |||
| return host; | |||
| } | |||
| @ApiOperation(value = "微信网页登录回调", notes = "请配置此callback到网页redirect_uri") | |||
| @GetMapping("callback") | |||
| @ResponseBody | |||
| @@ -100,10 +111,14 @@ public class WechatLoginController extends BaseController { | |||
| String host = request.getHeader("host"); | |||
| log.debug("host: " + host); | |||
| log.debug("code: " + code); | |||
| host = getHost(host); | |||
| try { | |||
| WxMpOAuth2AccessToken accessToken = wxMpService.oauth2getAccessToken(code); | |||
| log.info("accessToken: " + accessToken.getAccessToken() + ", openId: " + accessToken.getOpenId() + ", unionId: " + accessToken.getUnionId()); | |||
| accessToken = wxMpService.oauth2refreshAccessToken(accessToken.getRefreshToken()); | |||
| log.info("accessToken: " + accessToken.getAccessToken() + ", openId: " + accessToken.getOpenId() + ", unionId: " + accessToken.getUnionId()); | |||
| // 获取 用户信息 | |||
| WxMpUser mpUser = wxMpService.oauth2getUserInfo(accessToken, null); | |||
| if(mpUser != null) { | |||
| @@ -162,7 +177,7 @@ public class WechatLoginController extends BaseController { | |||
| if(codeObj == null) { | |||
| log.info("用户登录成功,切换主页"); | |||
| try { | |||
| response.sendRedirect("https://mall.youlane.cn/#/layout"); | |||
| response.sendRedirect("https://"+host+"/#/layout"); | |||
| } catch (Exception e) { | |||
| log.error(e.getMessage()); | |||
| } | |||