public class OAuth2Tools extends Object
Modifier and Type | Class and Description |
---|---|
static class |
OAuth2Tools.EScope
授权作用域枚举
|
Constructor and Description |
---|
OAuth2Tools() |
Modifier and Type | Method and Description |
---|---|
static ErrcodeBean |
checkAccessToken(String accessToken,
String openId)
附:检验授权凭证(access_token)是否有效
|
static OAuth2ATBean |
getAccessToken(String code,
String appid,
String appSecret)
oauth微信授权流程中获取的access_token
第二步:通过code换取网页授权access_token |
static String |
getOAuth2UrlStr(String appid,
String redirect_uri,
OAuth2Tools.EScope scope,
String state)
获取要进行微信oauth2授权的跳转URL(微信服务器)
第一步:用户同意授权,获取code |
static OAuth2UserBean |
getUserInfo(OAuth2ATBean auth2atBean)
oauth微信授权流程中获取用户信息
第四步:拉取用户信息(需scope为 snsapi_userinfo) |
static OAuth2ATBean |
refreshToken(String appid,
String refreshToken)
第三步:刷新access_token(如果需要)
|
public static String getOAuth2UrlStr(String appid, String redirect_uri, OAuth2Tools.EScope scope, String state) throws UnsupportedEncodingException
appid
- 公众号的唯一标识,从微信申请的appidredirect_uri
- 授权后重定向的回调链接地址, 请使用 urlEncode 对链接进行处理,要进行跳转的我方服务器URLscope
- 应用授权作用域,snsapi_base (不弹出授权页面,直接跳转,只能获取用户openid),snsapi_userinfo (弹出授权页面,可通过openid拿到昵称、性别、所在地。并且, 即使在未关注的情况下,只要用户授权,也能获取其信息 )state
- 重定向后会带上state参数,开发者可以填写a-zA-Z0-9的参数值,最多128字节,原样返回参数数据UnsupportedEncodingException
public static OAuth2ATBean getAccessToken(String code, String appid, String appSecret)
code
- appid
- appSecret
- public static OAuth2ATBean refreshToken(String appid, String refreshToken)
appid
- refreshToken
- public static OAuth2UserBean getUserInfo(OAuth2ATBean auth2atBean)
auth2atBean
- public static ErrcodeBean checkAccessToken(String accessToken, String openId)
accessToken
- 网页授权接口调用凭证,注意:此access_token与基础支持的access_token不同openId
- 用户的唯一标识Copyright © 2020. All rights reserved.