Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Z
zcq
Project
Project
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
Graph
比较
统计图
议题
0
议题
0
列表
看板
标记
Milestones
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
注册表
注册表
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
svn
zcq
Commits
5a93283d
提交
5a93283d
authored
4月 09, 2020
作者:
xinjunguo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
--no commit message
上级
e1b5b3d2
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
83 行增加
和
0 行删除
+83
-0
WeChatLoginH5Controller.java
...a/com/zrqx/third/wechatlogin/WeChatLoginH5Controller.java
+72
-0
WeChatLoginH5Config.java
...om/zrqx/third/wechatlogin/config/WeChatLoginH5Config.java
+11
-0
没有找到文件。
com.zrqx.third/src/main/java/com/zrqx/third/wechatlogin/WeChatLoginH5Controller.java
0 → 100644
浏览文件 @
5a93283d
package
com
.
zrqx
.
third
.
wechatlogin
;
import
javax.servlet.http.HttpServletRequest
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.autoconfigure.cache.CacheProperties.Redis
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
com.zrqx.core.enums.ResponseCodeEnum
;
import
com.zrqx.core.exception.BaseException
;
import
com.zrqx.core.model.third.wechartlogin.WeChartThirdReturn
;
import
com.zrqx.core.util.CallBack
;
import
com.zrqx.third.constant.RequestPath
;
import
com.zrqx.third.util.HttpsUtils
;
import
com.zrqx.third.wechatlogin.config.WeChatLoginH5Config
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
@RestController
@RequestMapping
(
RequestPath
.
WECHAT_H5_LOGIN
)
@Api
(
description
=
"微信客户端内访问第三方页面授权登录"
)
public
class
WeChatLoginH5Controller
{
@ApiOperation
(
value
=
"微信登录"
,
notes
=
"微信登录"
)
@GetMapping
({
"/query"
})
public
CallBack
<
WeChartThirdReturn
>
query
(
String
code
,
HttpServletRequest
request
)
throws
Exception
{
String
appid
=
"appid="
+
WeChatLoginH5Config
.
APPID
;
String
secret
=
"&secret="
+
WeChatLoginH5Config
.
SECRET
;
String
code1
=
"&code="
+
code
;
String
grant_type
=
"&grant_type="
+
WeChatLoginH5Config
.
GRANT_TYPE
;
String
param
=
appid
+
secret
+
code1
+
grant_type
;
String
result
=
HttpsUtils
.
sendGet
(
"https://api.weixin.qq.com/sns/oauth2/access_token"
,
param
);
JSONObject
object
=
(
JSONObject
)
JSON
.
parse
(
result
);
if
(
object
.
containsKey
(
"errcode"
))
{
throw
new
BaseException
(
ResponseCodeEnum
.
EXCEPTION
.
getCode
(),
object
.
get
(
"errcode"
).
toString
());
}
String
openId
=
object
.
get
(
"openid"
).
toString
();
String
access_token
=
object
.
get
(
"access_token"
).
toString
();
String
param1
=
"access_token="
+
access_token
+
"&openid="
+
openId
;
String
result1
=
HttpsUtils
.
sendGet
(
"https://api.weixin.qq.com/sns/userinfo"
,
param1
);
JSONObject
object1
=
(
JSONObject
)
JSON
.
parse
(
result1
);
if
(
object1
.
containsKey
(
"errcode"
))
{
throw
new
BaseException
(
ResponseCodeEnum
.
EXCEPTION
.
getCode
(),
object1
.
get
(
"errcode"
).
toString
());
}
String
nickname
=
object1
.
get
(
"nickname"
).
toString
();
String
headimgurl
=
object1
.
get
(
"headimgurl"
).
toString
();
String
unionid
=
object1
.
get
(
"unionid"
).
toString
();
WeChartThirdReturn
user
=
new
WeChartThirdReturn
();
user
.
setOpenid
(
openId
);
user
.
setNickname
(
nickname
);
user
.
setHeadImgUrl
(
headimgurl
);
user
.
setUnionid
(
unionid
);
return
CallBack
.
success
(
user
);
}
}
\ No newline at end of file
com.zrqx.third/src/main/java/com/zrqx/third/wechatlogin/config/WeChatLoginH5Config.java
0 → 100644
浏览文件 @
5a93283d
package
com
.
zrqx
.
third
.
wechatlogin
.
config
;
public
class
WeChatLoginH5Config
{
public
static
final
String
APPID
=
"wxa036be65443d937f"
;
public
static
final
String
SECRET
=
"e2070c6ac1a3c465042320d17a946479"
;
public
static
final
String
GRANT_TYPE
=
"authorization_code"
;
public
static
final
String
RESPONSE_TYPE
=
"code"
;
public
static
final
String
SCOPE
=
"snsapi_login"
;
public
static
final
String
REDIRECTURI
=
"www.zgsccbs.com"
;
}
\ No newline at end of file
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论