Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
My_csdo
JustAuth
提交
6186236a
J
JustAuth
项目概览
My_csdo
/
JustAuth
与 Fork 源项目一致
Fork自
justauth / JustAuth
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
J
JustAuth
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
6186236a
编写于
5月 17, 2019
作者:
智布道
👁
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
👽
合并wechat登录代码
上级
8abe74db
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
15 addition
and
34 deletion
+15
-34
README.md
README.md
+1
-1
src/main/java/me/zhyd/oauth/request/AuthWeChatRequest.java
src/main/java/me/zhyd/oauth/request/AuthWeChatRequest.java
+14
-33
未找到文件。
README.md
浏览文件 @
6186236a
...
...
@@ -103,7 +103,7 @@ authRequest.login("code");
|
<img
src=
"https://gitee.com/yadong.zhang/static/raw/master/JustAuth/alipay.png"
width=
"20"
>
|
[
AuthAlipayRequest
](
https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthAlipayRequest.java
)
|
<a
href=
"https://alipay.open.taobao.com/docs/doc.htm?spm=a219a.7629140.0.0.336d4b70GUKXOl&treeId=193&articleId=105809&docType=1"
target=
"_blank"
>
参考文档
</a>
|
|
<img
src=
"https://gitee.com/yadong.zhang/static/raw/master/JustAuth/qq.png"
width=
"20"
>
|
[
AuthQqRequest
](
https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthQqRequest.java
)
|
<a
href=
"http://wiki.connect.qq.com/"
target=
"_blank"
>
参考文档
</a>
|
|
<img
src=
"https://gitee.com/yadong.zhang/static/raw/master/JustAuth/csdn.png"
width=
"20"
>
|
[
AuthCsdnRequest
](
https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthCsdnRequest.java
)
| 待续 |
|
<img
src=
"https://gitee.com/yadong.zhang/static/raw/master/JustAuth/wechats.png"
width=
"20"
>
|
AuthWechatRequest
| 待续 |
|
<img
src=
"https://gitee.com/yadong.zhang/static/raw/master/JustAuth/wechats.png"
width=
"20"
>
|
[
AuthWeChatRequest
](
https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthCsdnRequest.java
)
| 待续 |
## 后续开发计划
...
...
src/main/java/me/zhyd/oauth/request/AuthWeChatRequest.java
浏览文件 @
6186236a
...
...
@@ -5,10 +5,7 @@ import cn.hutool.http.HttpResponse;
import
com.alibaba.fastjson.JSONObject
;
import
me.zhyd.oauth.config.AuthConfig
;
import
me.zhyd.oauth.exception.AuthException
;
import
me.zhyd.oauth.model.AuthResponse
;
import
me.zhyd.oauth.model.AuthSource
;
import
me.zhyd.oauth.model.AuthUser
;
import
me.zhyd.oauth.model.AuthUserGender
;
import
me.zhyd.oauth.model.*
;
import
me.zhyd.oauth.utils.UrlBuilder
;
/**
...
...
@@ -36,7 +33,7 @@ public class AuthWeChatRequest extends BaseAuthRequest {
* @return 所有信息
*/
@Override
protected
String
getAccessToken
(
String
code
)
{
protected
AuthToken
getAccessToken
(
String
code
)
{
String
accessTokenUrl
=
UrlBuilder
.
getWeChatAccessTokenUrl
(
config
.
getClientId
(),
config
.
getClientSecret
(),
code
);
HttpResponse
response
=
HttpRequest
.
get
(
accessTokenUrl
).
execute
();
JSONObject
accessTokenObject
=
JSONObject
.
parseObject
(
response
.
body
());
...
...
@@ -44,15 +41,20 @@ public class AuthWeChatRequest extends BaseAuthRequest {
.
containsKey
(
"refresh_token"
))
{
throw
new
AuthException
(
"Unable to get access_token or openid or refresh_token from wechat using code ["
+
code
+
"]"
);
}
return
response
.
body
();
JSONObject
object
=
JSONObject
.
parseObject
(
response
.
body
());
return
AuthToken
.
builder
()
.
accessToken
(
object
.
getString
(
"access_token"
))
.
refreshToken
(
object
.
getString
(
"refresh_token"
))
.
openId
(
object
.
getString
(
"openid"
))
.
build
();
}
@Override
protected
AuthUser
getUserInfo
(
String
access
Token
)
{
String
token
=
this
.
getToken
(
accessToken
);
String
openId
=
this
.
getOpenId
(
accessToken
);
protected
AuthUser
getUserInfo
(
AuthToken
auth
Token
)
{
String
accessToken
=
authToken
.
getAccessToken
(
);
String
openId
=
authToken
.
getOpenId
(
);
HttpResponse
response
=
HttpRequest
.
get
(
UrlBuilder
.
getWeChatUserInfoUrl
(
t
oken
,
openId
)).
execute
();
HttpResponse
response
=
HttpRequest
.
get
(
UrlBuilder
.
getWeChatUserInfoUrl
(
accessT
oken
,
openId
)).
execute
();
JSONObject
object
=
JSONObject
.
parseObject
(
response
.
body
());
if
(
object
.
containsKey
(
"errcode"
))
{
throw
new
AuthException
(
object
.
getString
(
"errmsg"
));
...
...
@@ -69,15 +71,9 @@ public class AuthWeChatRequest extends BaseAuthRequest {
.
build
();
}
/**
* 刷新access token (续期)
*
* @param accessToken 登录成功后返回的accessToken
* @return AuthResponse
*/
@Override
public
AuthResponse
refresh
(
String
access
Token
)
{
String
refreshToken
=
getRefreshToken
(
accessToken
);
public
AuthResponse
refresh
(
AuthToken
auth
Token
)
{
String
refreshToken
=
authToken
.
getRefreshToken
(
);
HttpResponse
response
=
HttpRequest
.
get
(
UrlBuilder
.
getWeChatRefreshUrl
(
config
.
getClientId
(),
refreshToken
))
.
execute
();
...
...
@@ -88,19 +84,4 @@ public class AuthWeChatRequest extends BaseAuthRequest {
return
AuthResponse
.
builder
().
data
(
object
).
build
();
}
private
String
getRefreshToken
(
String
accessToken
)
{
JSONObject
accessTokenObject
=
JSONObject
.
parseObject
(
accessToken
);
return
accessTokenObject
.
getString
(
"refresh_token"
);
}
private
String
getOpenId
(
String
accessToken
)
{
JSONObject
accessTokenObject
=
JSONObject
.
parseObject
(
accessToken
);
return
accessTokenObject
.
getString
(
"openid"
);
}
private
String
getToken
(
String
accessToken
)
{
JSONObject
accessTokenObject
=
JSONObject
.
parseObject
(
accessToken
);
return
accessTokenObject
.
getString
(
"access_token"
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录