com.github.sd4324530.fastweixin.api
类 OauthAPI

java.lang.Object
  继承者 com.github.sd4324530.fastweixin.api.BaseAPI
      继承者 com.github.sd4324530.fastweixin.api.OauthAPI

public class OauthAPI
extends BaseAPI

网页授权API

作者:
peiyu

字段摘要
 
从类 com.github.sd4324530.fastweixin.api.BaseAPI 继承的字段
BASE_API_URL, config
 
构造方法摘要
OauthAPI(ApiConfig config)
           
 
方法摘要
 String getOauthPageUrl(String redirectUrl, OauthScope scope, String state)
          生成回调url,这个结果要求用户在微信中打开,即可获得token,并指向redirectUrl
 OauthGetTokenResponse getToken(String code)
          用户同意授权后在回调url中会得到code,调用此方法用code换token以及openid,所以如果仅仅是授权openid,到这步就结束了
 GetUserInfoResponse getUserInfo(String token, String openid)
          获取用户详细信息
 OauthGetTokenResponse refreshToken(String refreshToken)
          刷新token
 boolean validToken(String token, String openid)
          校验token是否合法有效
 
从类 com.github.sd4324530.fastweixin.api.BaseAPI 继承的方法
executeGet, executePost, executePost, isSuccess
 
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

构造方法详细信息

OauthAPI

public OauthAPI(ApiConfig config)
方法详细信息

getOauthPageUrl

public String getOauthPageUrl(String redirectUrl,
                              OauthScope scope,
                              String state)
生成回调url,这个结果要求用户在微信中打开,即可获得token,并指向redirectUrl

参数:
redirectUrl - 用户自己设置的回调地址
scope - 授权作用域
state - 用户自带参数
返回:
回调url,用户在微信中打开即可开始授权

getToken

public OauthGetTokenResponse getToken(String code)
用户同意授权后在回调url中会得到code,调用此方法用code换token以及openid,所以如果仅仅是授权openid,到这步就结束了

参数:
code - 授权后得到的code
返回:
token对象

refreshToken

public OauthGetTokenResponse refreshToken(String refreshToken)
刷新token

参数:
refreshToken - token对象中会包含refreshToken字段,通过这个字段再次刷新token
返回:
全新的token对象

getUserInfo

public GetUserInfoResponse getUserInfo(String token,
                                       String openid)
获取用户详细信息

参数:
token - token
openid - 用户openid
返回:
用户信息对象

validToken

public boolean validToken(String token,
                          String openid)
校验token是否合法有效

参数:
token - token
openid - 用户openid
返回:
是否合法有效


Copyright © 2017. All rights reserved.