From 6aa704f5c0546f81578a66337928c42b1a778dd1 Mon Sep 17 00:00:00 2001 From: LuoYe_MyWork Date: Wed, 15 Apr 2020 17:21:24 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E7=99=BB=E5=BD=95=E8=BF=94=E5=9B=9E?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E5=90=8D=202=E3=80=81getGithubUrl=20?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=E5=80=BC=E4=BF=AE=E6=94=B9=E4=B8=BAjson=203?= =?UTF-8?q?=E3=80=81=E4=BF=AE=E6=94=B9=20=E6=9C=AA=E7=9F=A5=E9=94=99?= =?UTF-8?q?=E8=AF=AF=EF=BC=8C=E8=AF=B7=E8=81=94=E7=B3=BB=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E5=91=98=20=E4=B8=BA=E5=85=B7=E4=BD=93=E7=9A=84=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../security/SecurityAuthenticationHandler.java | 1 + .../java/io/qyi/e5/controller/auth2/Auth.java | 7 ++++--- .../e5/outlook/controller/AuthController.java | 2 +- .../outlook/controller/OutlookController.java | 10 +++++----- .../service/impl/OutlookServiceImpl.java | 17 ++++++++++++++++- 5 files changed, 27 insertions(+), 10 deletions(-) diff --git a/src/main/java/io/qyi/e5/config/security/SecurityAuthenticationHandler.java b/src/main/java/io/qyi/e5/config/security/SecurityAuthenticationHandler.java index 9ec993d..48cd992 100644 --- a/src/main/java/io/qyi/e5/config/security/SecurityAuthenticationHandler.java +++ b/src/main/java/io/qyi/e5/config/security/SecurityAuthenticationHandler.java @@ -34,6 +34,7 @@ public class SecurityAuthenticationHandler implements AuthenticationSuccessHandl PrintWriter writer = httpServletResponse.getWriter(); Map token = new HashMap<>(); token.put("token", at.getToken()); + token.put("username", at.getName()); writer.write(gson.toJson(ResultUtil.success(token)) ); writer.flush(); } diff --git a/src/main/java/io/qyi/e5/controller/auth2/Auth.java b/src/main/java/io/qyi/e5/controller/auth2/Auth.java index 953934e..0652de1 100644 --- a/src/main/java/io/qyi/e5/controller/auth2/Auth.java +++ b/src/main/java/io/qyi/e5/controller/auth2/Auth.java @@ -1,9 +1,11 @@ package io.qyi.e5.controller.auth2; +import io.qyi.e5.bean.result.Result; import io.qyi.e5.github.mapper.GithubMapper; import io.qyi.e5.github.service.IGithubService; import io.qyi.e5.user.mapper.UserMapper; import io.qyi.e5.util.EncryptUtil; +import io.qyi.e5.util.ResultUtil; import io.qyi.e5.util.redis.RedisUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; @@ -36,11 +38,10 @@ public class Auth { @RequestMapping("/getGithubUrl") - public void getGithubUrl(HttpServletResponse response) { + public Result getGithubUrl() { String state = EncryptUtil.getInstance().SHA1Hex(UUID.randomUUID().toString()); redisUtil.set(states + state, true, 600); - response.setStatus(302); - response.setHeader("Location", "https://github.com/login/oauth/authorize?client_id=" + client_id + "&redirect_uri=https://e5.qyi.io/auth2/receive&state=" + state); + return ResultUtil.success("https://github.com/login/oauth/authorize?client_id=" + client_id + "&redirect_uri=https://e5.qyi.io/auth2/receive&state=" + state); } /* @RequestMapping("/receive") diff --git a/src/main/java/io/qyi/e5/outlook/controller/AuthController.java b/src/main/java/io/qyi/e5/outlook/controller/AuthController.java index 6bd2f39..53463bc 100644 --- a/src/main/java/io/qyi/e5/outlook/controller/AuthController.java +++ b/src/main/java/io/qyi/e5/outlook/controller/AuthController.java @@ -60,7 +60,7 @@ public class AuthController { boolean authorization_code = outlookService.getTokenAndSave(code, outlook.getClientId(), outlook.getClientSecret(), "https://e5.qyi.io/outlook/auth2/receive" , "authorization_code"); if (!authorization_code) { - return ResultUtil.error(-3, "未知错误,请联系管理员~"); + return ResultUtil.error(-3, "clientId 或 clientSecret 填写错误!授权失败!"); } return ResultUtil.success(); } diff --git a/src/main/java/io/qyi/e5/outlook/controller/OutlookController.java b/src/main/java/io/qyi/e5/outlook/controller/OutlookController.java index 6a4ecc3..5c69b2b 100644 --- a/src/main/java/io/qyi/e5/outlook/controller/OutlookController.java +++ b/src/main/java/io/qyi/e5/outlook/controller/OutlookController.java @@ -48,8 +48,8 @@ public class OutlookController { int cron_time_random_start; int cron_time_random_end; try { - cron_time_random_start = Integer.valueOf(split[0]); - cron_time_random_end = Integer.valueOf(split[1]); + cron_time_random_start = Integer.valueOf(split[0]); + cron_time_random_end = Integer.valueOf(split[1]); } catch (NumberFormatException e) { e.printStackTrace(); return ResultUtil.error(ResultEnum.INVALID_format); @@ -60,17 +60,17 @@ public class OutlookController { } return ResultUtil.error(ResultEnum.UNKNOWN_ERROR); } + @GetMapping("/getOutlookInfo") - public Result getOutlookInfo(){ + public Result getOutlookInfo() { UsernamePasswordAuthenticationToken authentication = (UsernamePasswordAuthenticationToken) SecurityContextHolder.getContext().getAuthentication(); int github_id = authentication.getGithub_id(); QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.eq("github_id", github_id); Outlook one = outlookService.getOne(queryWrapper); OutlookVo vo = new OutlookVo(); - System.out.println(one); if (one != null) { - BeanUtils.copyProperties(one,vo); + BeanUtils.copyProperties(one, vo); } return ResultUtil.success(vo); } diff --git a/src/main/java/io/qyi/e5/outlook/service/impl/OutlookServiceImpl.java b/src/main/java/io/qyi/e5/outlook/service/impl/OutlookServiceImpl.java index 786aedb..12101e0 100644 --- a/src/main/java/io/qyi/e5/outlook/service/impl/OutlookServiceImpl.java +++ b/src/main/java/io/qyi/e5/outlook/service/impl/OutlookServiceImpl.java @@ -164,12 +164,27 @@ public class OutlookServiceImpl extends ServiceImpl impl } } + /** + * 读取邮件内容 + * @Description: + * @param: count 读取数量,0 则读取当前页所有 + * @return: void + * @Author: 落叶随风 + * @Date: 2020/4/15 + */ + public void getMailBody(int count,String MailBody ,String access_token) throws Exception { + Map head = new HashMap<>(); + head.put("Content-Type", "application/json"); + head.put("Authorization", access_token); + String s = OkHttpRequestUtils.doGet("https://graph.microsoft.com/v1.0/me/messages/", head, null); + } + public String MailList(String access_token) throws Exception { Map head = new HashMap<>(); head.put("Content-Type", "application/json"); head.put("Authorization", access_token); String s = OkHttpRequestUtils.doGet("https://graph.microsoft.com/v1.0/me/messages?$select=sender,subject", head, null); - logger.info("请求邮件列表返回数据:" + s); + logger.debug("请求邮件列表返回数据:" + s); return s; }