From abb121a57c356a577b0fb765faeafc730b99b37c Mon Sep 17 00:00:00 2001 From: "yadong.zhang" Date: Thu, 12 Dec 2019 11:47:54 +0800 Subject: [PATCH] =?UTF-8?q?:memo:=20=E6=B7=BB=E5=8A=A0qq=E6=8E=88=E6=9D=83?= =?UTF-8?q?=E7=99=BB=E5=BD=95=E7=9A=84=E5=B8=AE=E5=8A=A9=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/oauth/qq.md | 95 ++++++++++++++++++++++++++++++++++++++++++-- docs/oauth/wechat.md | 3 ++ 2 files changed, 95 insertions(+), 3 deletions(-) diff --git a/docs/oauth/qq.md b/docs/oauth/qq.md index 00ff6e4..3632721 100644 --- a/docs/oauth/qq.md +++ b/docs/oauth/qq.md @@ -1,7 +1,96 @@ -(敬请期待...) - ## 1. 申请应用 +### 1.登录QQ互联平台 +https://connect.qq.com/ +### 2.申请开发者 +进入“应用管理”页面:[https://connect.qq.com/manage.html#/](https://connect.qq.com/manage.html#/) +如果是第一次使用,并且未进行过开发者认证,需要提交一下个人资料,待认证通过后方可创建应用。 + +### 3. 添加应用 + +依次点击:应用管理 -> 网站应用 -> 创建应用,应用信息提交后,等待审核通过即可 + +应用审核通过后如下: + +![file](../_media/oauth/qq_01.png) + +copy以下三个信息:`App ID`、`App Key`和`网站回调域`。 + ## 2. 集成JustAuth -## 3. 授权结果 \ No newline at end of file + +### 2.1 引入依赖 + +```xml + + me.zhyd.oauth + JustAuth + ${latest.version} + +``` + +`${latest.version}`表示当前最新的版本,可以在[这儿](https://github.com/justauth/JustAuth/releases)获取最新的版本信息。 + +### 2.2 创建Request + +```java +AuthRequest authRequest = new AuthQqRequest(AuthConfig.builder() + .clientId("App ID") + .clientSecret("App Key") + .redirectUri("网站回调域") + .build()); +``` + +### 2.3 生成授权地址 + +我们可以直接使用以下方式生成第三方平台的授权链接: +```java +String authorizeUrl = authRequest.authorize(); +``` +这个链接我们可以直接后台重定向跳转,也可以返回到前端后,前端控制跳转。前端控制的好处就是,可以将第三方的授权页嵌入到iframe中,适配网站设计。 + + +### 2.4 以上完整代码如下 + +```java +import me.zhyd.oauth.config.AuthConfig; +import me.zhyd.oauth.request.AuthQqRequest; +import me.zhyd.oauth.request.AuthRequest; +import me.zhyd.oauth.utils.AuthStateUtils; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; + + +@RestController +@RequestMapping("/oauth") +public class RestAuthController { + + @RequestMapping("/render") + public void renderAuth(HttpServletResponse response) throws IOException { + AuthRequest authRequest = getAuthRequest(); + response.sendRedirect(authRequest.authorize(AuthStateUtils.createState())); + } + + @RequestMapping("/callback") + public Object login(String code) { + AuthRequest authRequest = getAuthRequest(); + return authRequest.login(code); + } + + private AuthRequest getAuthRequest() { + return new AuthQqRequest(AuthConfig.builder() + .clientId("App ID") + .clientSecret("App Key") + .redirectUri("网站回调域") + .build()); + } +} +``` + +## 3. 授权结果 + +暂无 \ No newline at end of file diff --git a/docs/oauth/wechat.md b/docs/oauth/wechat.md index c74daa8..395d2ed 100644 --- a/docs/oauth/wechat.md +++ b/docs/oauth/wechat.md @@ -1,3 +1,6 @@ +### 声明: +此文档适用于**微信开放平台**、**微信开放平台**、**微信开放平台**,不是**微信公众平台**! + ## 1. 申请应用 ### 1.注册微信开放平台账号 -- GitLab