C# Class Senparc.Weixin.MP.AdvancedAPIs.OAuthApi

Show file Open project: JeffreySu/WeiXinMPSDK

Public Methods

Method Description
Auth ( string accessToken, string openId ) : WxJsonResult

检验授权凭证(access_token)是否有效

AuthAsync ( string accessToken, string openId ) : Task

【异步方法】检验授权凭证(access_token)是否有效

GetAccessToken ( string appId, string secret, string code, string grantType = "authorization_code" ) : OAuthAccessTokenResult

获取AccessToken

GetAccessTokenAsync ( string appId, string secret, string code, string grantType = "authorization_code" ) : Task

【异步方法】获取AccessToken

GetAuthorizeUrl ( string appId, string redirectUrl, string state, OAuthScope scope, string responseType = "code", bool addConnectRedirect = true ) : string

获取验证地址

GetUserInfo ( string accessToken, string openId, Language lang = Language.zh_CN ) : OAuthUserInfo

获取用户基本信息

GetUserInfoAsync ( string accessToken, string openId, Language lang = Language.zh_CN ) : Task

【异步方法】 获取用户基本信息

RefreshToken ( string appId, string refreshToken, string grantType = "refresh_token" ) : RefreshTokenResult

刷新access_token(如果需要)

RefreshTokenAsync ( string appId, string refreshToken, string grantType = "refresh_token" ) : Task

【异步方法】刷新access_token(如果需要)

Method Details

Auth() public static method

检验授权凭证(access_token)是否有效
public static Auth ( string accessToken, string openId ) : WxJsonResult
accessToken string 调用接口凭证
openId string 用户的唯一标识
return Senparc.Weixin.Entities.WxJsonResult

AuthAsync() public static method

【异步方法】检验授权凭证(access_token)是否有效
public static AuthAsync ( string accessToken, string openId ) : Task
accessToken string
openId string 用户的唯一标识
return Task

GetAccessToken() public static method

获取AccessToken
public static GetAccessToken ( string appId, string secret, string code, string grantType = "authorization_code" ) : OAuthAccessTokenResult
appId string 公众号的唯一标识
secret string 公众号的appsecret
code string code作为换取access_token的票据,每次用户授权带上的code将不一样,code只能使用一次,5分钟未被使用自动过期。
grantType string 填写为authorization_code(请保持默认参数)
return OAuthAccessTokenResult

GetAccessTokenAsync() public static method

【异步方法】获取AccessToken
public static GetAccessTokenAsync ( string appId, string secret, string code, string grantType = "authorization_code" ) : Task
appId string
secret string
code string code作为换取access_token的票据,每次用户授权带上的code将不一样,code只能使用一次,5分钟未被使用自动过期。
grantType string
return Task

GetAuthorizeUrl() public static method

获取验证地址
public static GetAuthorizeUrl ( string appId, string redirectUrl, string state, OAuthScope scope, string responseType = "code", bool addConnectRedirect = true ) : string
appId string 公众号的唯一标识
redirectUrl string 授权后重定向的回调链接地址,请使用urlencode对链接进行处理
state string 重定向后会带上state参数,开发者可以填写a-zA-Z0-9的参数值,最多128字节
scope OAuthScope 应用授权作用域,snsapi_base (不弹出授权页面,直接跳转,只能获取用户openid),snsapi_userinfo (弹出授权页面,可通过openid拿到昵称、性别、所在地。并且,即使在未关注的情况下,只要用户授权,也能获取其信息)
responseType string 返回类型,请填写code(或保留默认)
addConnectRedirect bool 加上后可以解决40029-invalid code的问题(测试中)
return string

GetUserInfo() public static method

获取用户基本信息
public static GetUserInfo ( string accessToken, string openId, Language lang = Language.zh_CN ) : OAuthUserInfo
accessToken string 调用接口凭证
openId string 普通用户的标识,对当前公众号唯一
lang Language 返回国家地区语言版本,zh_CN 简体,zh_TW 繁体,en 英语
return OAuthUserInfo

GetUserInfoAsync() public static method

【异步方法】 获取用户基本信息
public static GetUserInfoAsync ( string accessToken, string openId, Language lang = Language.zh_CN ) : Task
accessToken string 调用接口凭证
openId string 普通用户的标识,对当前公众号唯一
lang Language 返回国家地区语言版本,zh_CN 简体,zh_TW 繁体,en 英语
return Task

RefreshToken() public static method

刷新access_token(如果需要)
public static RefreshToken ( string appId, string refreshToken, string grantType = "refresh_token" ) : RefreshTokenResult
appId string 公众号的唯一标识
refreshToken string 填写通过access_token获取到的refresh_token参数
grantType string 填写refresh_token
return RefreshTokenResult

RefreshTokenAsync() public static method

【异步方法】刷新access_token(如果需要)
public static RefreshTokenAsync ( string appId, string refreshToken, string grantType = "refresh_token" ) : Task
appId string
refreshToken string 填写通过access_token获取到的refresh_token参数
grantType string
return Task