oauth2

package
v1.3.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 3, 2022 License: Apache-2.0 Imports: 7 Imported by: 0

README

微信开放平台 移动应用、网站应用 微信登录功能 SDK

Documentation

Overview

微信开放平台 移动应用、网站应用 微信登录功能 SDK.

Index

Constants

View Source
const (
	LanguageZhCN = mpoauth2.LanguageZhCN
	LanguageZhTW = mpoauth2.LanguageZhTW
	LanguageEN   = mpoauth2.LanguageEN
)
View Source
const (
	SexUnknown = mpoauth2.SexUnknown
	SexMale    = mpoauth2.SexMale
	SexFemale  = mpoauth2.SexFemale
)

Variables

This section is empty.

Functions

func FastRegisterWxaLink(appId, componentAppid, redirectURI string) string

FastRegisterWxaLink 快速注册小程序的开放平台连接. appId: 公众号的 appid component_appid: 第三方平台的appid redirectURI: 授权后重定向的回调链接地址 公众号管理员扫码后在手机端完成授权确认。 跳转回第三方平台,会在上述 redirect_uri后拼接 ticket=*

func GetAuthAppInfo

func GetAuthAppInfo(clt *core.Client, appId string) (authorizer map[string]interface{}, authorization map[string]interface{}, err error)

获取授权方的授权信息 获取授权app的具体信息

func GetPreAuthCode

func GetPreAuthCode(clt *core.Client) (code string, err error)

获取预授权码 配合 授权链接获取的authcode 一起服用, 换取token

func OpenAuthWebURL

func OpenAuthWebURL(appId, redirectURI, preAuthCode string, authType int) string

AuthWebURL 生成网页连接的开放平台授权地址.

 appId:       开放平台
	preAuthCode: 预授权code, 从平台获取

authType : 1则商户点击链接后,手机端仅展示公众号、2表示仅展示小程序,3表示公众号和小程序都展示。如果为未指定,则默认小程序和公众号都展示

redirectURI: 授权后重定向的回调链接地址
func OpenAuthWechatLink(appId, redirectURI, preAuthCode string, authType int) string

OpenAuthWechatLink 生成微信内点击的开放平台授权地址.

 appId:       开放平台
	preAuthCode: 预授权code, 从平台获取
	authType : 1则商户点击链接后,手机端仅展示公众号、2表示仅展示小程序,3表示公众号和小程序都展示。如果为未指定,则默认小程序和公众号都展示
 redirectURI: 授权后重定向的回调链接地址
func OpenAuthWechatNewLink(appId, redirectURI, preAuthCode string, authType int) string

OpenAuthWechatLink 生成微信内点击的开放平台授权地址.

 appId:       开放平台
	preAuthCode: 预授权code, 从平台获取
	authType : 1则商户点击链接后,手机端仅展示公众号、2表示仅展示小程序,3表示公众号和小程序都展示。如果为未指定,则默认小程序和公众号都展示
 redirectURI: 授权后重定向的回调链接地址

func WebAuth

func WebAuth(accessToken, openId string, httpClient *http.Client) (valid bool, err error)

Auth 检验授权凭证 access_token 是否有效.

accessToken: 网页授权接口调用凭证
openId:      用户的唯一标识
httpClient:  如果不指定则默认为 util.DefaultHttpClient

func WebAuthCodeURL

func WebAuthCodeURL(appId, redirectURI, scope, state string) string

WebAuthCodeURL 生成网页授权地址.

appId:       网页的唯一标识
redirectURI: 授权后重定向的回调链接地址
scope:       应用授权作用域
state:       重定向后会带上 state 参数, 开发者可以填写 a-zA-Z0-9 的参数值, 最多128字节

func WxaCode2Session

func WxaCode2Session(clt *core.Client, appId, js_code string) (openid, unionid, session_key string, err error)

小程序 获取openid 和sessionkey

Types

type AuthorizationInfo

type AuthorizationInfo struct {
	AppId        string        `json:"authorizer_appid"`
	AccessToken  string        `json:"authorizer_access_token"`
	ExpiresIn    int           `json:"expires_in"`
	RefreshToken string        `json:"authorizer_refresh_token"`
	FuncInfo     []interface{} `json:"func_info"`
}

func GetAuthInfo

func GetAuthInfo(clt *core.Client, auth_code string) (authInfo AuthorizationInfo, err error)

获取授权信息 授权链接获取的authcode 一起服用, 换取token

func RefreshAuthInfo

func RefreshAuthInfo(clt *core.Client, appId string, refreshToken string) (authInfo AuthorizationInfo, err error)

刷新第三方帐号的授权信息 注意: 此处appid和refresh token 均为第三方帐号的appid和refreshtoken, 不是开放平台的appid和token

type Endpoint

type Endpoint mpoauth2.Endpoint

func NewEndpoint

func NewEndpoint(AppId, AppSecret string) *Endpoint

func (*Endpoint) ExchangeTokenURL

func (p *Endpoint) ExchangeTokenURL(code string) string

func (*Endpoint) RefreshTokenURL

func (p *Endpoint) RefreshTokenURL(refreshToken string) string

type UserInfo

type UserInfo mpoauth2.UserInfo

func GetUserInfo

func GetUserInfo(accessToken, openId, lang string, httpClient *http.Client) (info *UserInfo, err error)

GetUserInfo 获取用户信息.

accessToken: 网页授权接口调用凭证
openId:      用户的唯一标识
lang:        返回国家地区语言版本,zh_CN 简体,zh_TW 繁体,en 英语, 如果留空 "" 则默认为 zh_CN
httpClient:  如果不指定则默认为 util.DefaultHttpClient

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL