jssdk

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SnsapiUserinfo = "snsapi_uesrnfo"
	SnsapiBase     = "snsapi_base"
)

授权作用域,供 GetCodeURL 使用。

Variables

This section is empty.

Functions

func AuthAccessToken

func AuthAccessToken(conf *common.Config, token *AccessToken) (bool, error)

AuthAccessToken 验证 access_token 是否有效

func GetCodeURL

func GetCodeURL(conf *common.Config, redirectURI, scope, state string) string

GetCodeURL 获取 code

Types

type AccessToken

type AccessToken struct {
	AccessToken  string        `json:"access_token"`
	ExpiresIn    time.Duration `json:"expires_in"`
	Created      time.Time     `json:"-"` // 该 access_token 的获取时间
	RefreshToken string        `json:"refresh_token"`
	OpenID       string        `json:"openid"`
	Scope        string        `json:"scope"`
}

AccessToken 表示 jssdk 中返回的 access_token 结构体

NOTE: 与 mp/common/token.AccessToken 同名,但结构不同。

func GetAccessToken

func GetAccessToken(conf *common.Config, code string) (*AccessToken, error)

GetAccessToken 根据 code 获取 access_token

func RefreshAccessToken

func RefreshAccessToken(conf *common.Config, token *AccessToken) (*AccessToken, error)

RefreshAccessToken 刷新 access_token

type UserInfo

type UserInfo struct {
	OpenID     string   `json:"openid"`
	Nickname   string   `json:"nickname"`
	Sex        string   `json:"sex"`        // 性别,1男,2女,0未知
	Province   string   `json:"province"`   // 省份
	City       string   `json:"city"`       // 城市
	Country    string   `json:"country"`    // 国家
	HeadImgURL string   `json:"headimgurl"` // 头像地址
	Privilege  []string `json:"privilege"`
	UnionID    string   `json:"unionid,omitempty"`
}

UserInfo 查询用户信息接口返回的数据

func GetUserInfo

func GetUserInfo(conf *common.Config, token *AccessToken, lang string) (*UserInfo, error)

GetUserInfo 获取用户基本信息

若不指定 lang 则使用 zh_CN 作为其默认值。

func (*UserInfo) HeadImageURL

func (u *UserInfo) HeadImageURL(size int) (string, error)

HeadImageURL 相对于 HeadImgURL 的好处是,可以指定图片的尺寸。 可以是 46,64,96,132,0(表示640)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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