open

package
v1.1.4 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Success = 0

	HostDefault = "https://api.weixin.qq.com"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AT added in v1.1.3

type AT struct {
	AccessToken  string // 获取到的凭证
	ExpiresIn    int    // 凭证有效时间,单位:秒。目前是7200秒之内的值。
	RefreshToken string // 用户刷新 access_token
	Openid       string // 授权用户唯一标识
	Scope        string // 用户授权的作用域,使用逗号(,)分隔
	Unionid      string // 当且仅当该移动应用已获得该用户的 userinfo 授权时,才会出现该字段
}

type AccessToken added in v1.1.0

type AccessToken struct {
	AccessToken  string `json:"access_token,omitempty"`  // 获取到的凭证
	ExpiresIn    int    `json:"expires_in,omitempty"`    // 凭证有效时间,单位:秒。目前是7200秒之内的值。
	RefreshToken string `json:"refresh_token,omitempty"` // 用户刷新 access_token
	Openid       string `json:"openid,omitempty"`        // 授权用户唯一标识
	Scope        string `json:"scope,omitempty"`         // 用户授权的作用域,使用逗号(,)分隔
	Unionid      string `json:"unionid,omitempty"`       // 当且仅当该移动应用已获得该用户的 userinfo 授权时,才会出现该字段
	Errcode      int    `json:"errcode,omitempty"`       // 错误码
	Errmsg       string `json:"errmsg,omitempty"`        // 错误信息
}

type Config added in v1.1.0

type Config struct {
	Ctx         context.Context
	Appid       string
	Secret      string
	AccessToken string
	Host        string
}

type ErrorCode added in v1.1.0

type ErrorCode struct {
	Errcode int    `json:"errcode,omitempty"` // 错误码
	Errmsg  string `json:"errmsg,omitempty"`  // 错误信息
}

type SDK

type SDK struct {
	DebugSwitch wechat.DebugSwitch

	Appid  string
	Secret string
	Host   string
	// contains filtered or unexported fields
}

func New

func New(appid, secret string, autoManageToken bool) (o *SDK)

New 初始化微信开放平台 SDK Appid:Appid Secret:appSecret autoManageToken:是否自动维护刷新 AccessToken(用户量较少时推荐使用,默认10分钟轮询检测一次,发现有效期小于1.5倍轮询时间时,自动刷新)

func (*SDK) CheckAccessToken added in v1.1.0

func (s *SDK) CheckAccessToken(c context.Context, accessToken, openid string) (err error)

CheckAccessToken 检验授权凭证 access_token 是否有效 注意:当开启自动管理 access_token 时,会自动删除无效的 access_token 文档:https://developers.weixin.qq.com/doc/oplatform/Mobile_App/WeChat_Login/Authorized_API_call_UnionID.html

func (*SDK) Code2AccessToken added in v1.1.0

func (s *SDK) Code2AccessToken(c context.Context, code string) (at *AccessToken, err error)

Code2AccessToken 通过 code 获取用户 access_token 微信开放平台文档:https://developers.weixin.qq.com/doc/oplatform/Mobile_App/WeChat_Login/Development_Guide.html

func (*SDK) DelAccessToken added in v1.1.3

func (s *SDK) DelAccessToken(openid string)

DelAccessToken 根据 openid 删除 map 中维护的 access_token

func (*SDK) DoRequestGet added in v1.1.0

func (s *SDK) DoRequestGet(c context.Context, path string, ptr interface{}) (err error)

func (*SDK) GetAccessTokenMap added in v1.1.3

func (s *SDK) GetAccessTokenMap() (openidATMap map[string]*AT)

GetAccessTokenMap 获取 access_token map,key 为 openid

func (*SDK) RefreshAccessToken added in v1.1.3

func (s *SDK) RefreshAccessToken(c context.Context, refreshToken string) (at *AccessToken, err error)

RefreshAccessToken 刷新或续期 access_token 文档:https://developers.weixin.qq.com/doc/oplatform/Mobile_App/WeChat_Login/Authorized_API_call_UnionID.html

func (*SDK) SetAccessTokenCallback added in v1.1.3

func (s *SDK) SetAccessTokenCallback(fn func(at *AT, err error))

SetAccessTokenCallback access token callback listener

func (*SDK) SetAccessTokenRefreshInternal added in v1.1.3

func (s *SDK) SetAccessTokenRefreshInternal(internal time.Duration)

SetAccessTokenRefreshInternal 设置自动刷新 access_token 间隔时长,默认10分钟

func (*SDK) UserInfo added in v1.1.0

func (s *SDK) UserInfo(c context.Context, accessToken, openid, lan string) (ui *UserInfo, err error)

UserInfo 获取用户个人信息(UnionID 机制) 注意:errcode = 0 为成功 文档:https://developers.weixin.qq.com/doc/oplatform/Mobile_App/WeChat_Login/Authorized_API_call_UnionID.html

type UserInfo added in v1.1.0

type UserInfo struct {
	Openid     string   `json:"openid,omitempty"`     // 普通用户的标识,对当前开发者帐号唯一
	Nickname   string   `json:"nickname,omitempty"`   // 普通用户昵称
	Sex        int      `json:"sex,omitempty"`        // 普通用户性别,1 为男性,2 为女性
	Province   string   `json:"province,omitempty"`   // 普通用户个人资料填写的省份
	City       string   `json:"city,omitempty"`       // 普通用户个人资料填写的城市
	Country    string   `json:"country,omitempty"`    // 国家,如中国为 CN
	Headimgurl string   `json:"headimgurl,omitempty"` // 用户头像,最后一个数值代表正方形头像大小(有 0、46、64、96、132 数值可选,0 代表 640*640 正方形头像),用户没有头像时该项为空
	Privilege  []string `json:"privilege,omitempty"`  // 用户特权信息,json 数组,如微信沃卡用户为(chinaunicom)
	Unionid    string   `json:"unionid,omitempty"`    // 用户统一标识。针对一个微信开放平台帐号下的应用,同一用户的 unionid 是唯一的。
	Errcode    int      `json:"errcode,omitempty"`    // 错误码
	Errmsg     string   `json:"errmsg,omitempty"`     // 错误信息
}

Jump to

Keyboard shortcuts

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