wechat

package
v0.0.0-...-fe406d3 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ActionInfo

type ActionInfo struct {
	Scene `json:"scene"`
}

type AppAccessToken

type AppAccessToken struct {
	AccessToken string `json:"access_token"`
	ExpiresTime int    `json:"expires_in"`
	Time        time.Time
}

应用的access token

type Client

type Client struct {

	// 应用appID
	AppID string
	// 应用appSecret
	AppSecret string
	// 应用配置的token
	AppToken string
	// 授权成功后微信回调接口
	RedirectURL string
	// 二维码有效时长s
	QrValidTime int

	AppAccessToken *AppAccessToken

	// 获取应用授权token url
	AppAccessTokenURL string
	// 获取二维码ticket url
	QrTicketURL string
	// 用户授权url
	UserAuthorizeURL string
	// 获取用户授权token url
	UserAccessTokenURL string
	// 获取用户信息url
	UserInfoURL string

	Lang WechatLangType
	// 请求资源范围,多个空格隔开
	Scopes string
	// contains filtered or unexported fields
}

func New

func New(appID, appSecret, appToken, redirectURL string, qrValidTime int, lang WechatLangType) *Client

New creates a new Wechat Login Client

func (*Client) GetAppAccessToken

func (c *Client) GetAppAccessToken() error

获取普通access token

func (*Client) GetAppAccessTokenUrl

func (c *Client) GetAppAccessTokenUrl() string

func (*Client) GetAuthorizeURL

func (c *Client) GetAuthorizeURL(state string) string

func (*Client) GetQRTicket

func (c *Client) GetQRTicket(codeType string, sceneId int) (string, error)

func (*Client) GetQrTicketURL

func (c *Client) GetQrTicketURL(appAccessToken string) string

func (*Client) GetUserAccessToken

func (c *Client) GetUserAccessToken(code string) (*GetUserAccessTokenRes, string, error)

GetUserAccessToken will go to Wepay and access access token about the user.

func (*Client) GetUserAccessTokenUrl

func (c *Client) GetUserAccessTokenUrl(code string) string

func (*Client) GetUserInfo

func (c *Client) GetUserInfo(accessToken *GetUserAccessTokenRes, openid string) (*GetUserInfoRes, error)

GetUserInfo will go to Wepay and access basic information about the user.

func (*Client) GetUserInfoUrl

func (c *Client) GetUserInfoUrl(accessToken, openid string) string

func (*Client) GetVaildAppAccessToken

func (c *Client) GetVaildAppAccessToken() (at string, err error)

GetVaildAppAccessToken 获取应用accesstoken

func (*Client) RefreshAppAccessToken

func (c *Client) RefreshAppAccessToken() error

AppAccessToken 刷新应用AccessToken

func (*Client) VerifySignature

func (c *Client) VerifySignature(vp VerifyParams) bool

签名验证(是否相同)

type GetQRTicketReq

type GetQRTicketReq struct {
	ExpireSeconds int        `json:"expire_seconds"`
	ActionName    string     `json:"action_name"`
	ActionInfo    ActionInfo `json:"action_info"`
}

QR code 请求体

type GetQRTicketRes

type GetQRTicketRes struct {
	Ticket        string `json:"ticket"`
	ExpireSeconds int    `json:"expire_seconds"`
	Url           string `json:"url"`
}

QR code 响应体

type GetUserAccessTokenRes

type GetUserAccessTokenRes struct {
	AccessToken    string        `json:"access_token"`
	ExpiresIn      time.Duration `json:"expires_in"`
	RefreshToken   string        `json:"refresh_token"`
	Openid         string        `json:"openid"`
	Scope          string        `json:"scope"`
	IsSnapshotuser int           `json:"is_snapshotuser"`
	Unionid        string        `json:"unionid"`
	Code           int           `json:"errcode"`
	Msg            string        `json:"errmsg"`
}

网页授权用户的access token

type GetUserInfoRes

type GetUserInfoRes struct {
	Openid     string   `json:"openid"`
	Nickname   string   `json:"nickname"`
	Sex        int      `json:"sex"`
	Province   string   `json:"province"`
	City       string   `json:"city"`
	Country    string   `json:"country"`
	Headimgurl string   `json:"headimgurl"`
	Privilege  []string `json:"privilege"`
	Unionid    string   `json:"unionid"`
	Code       int      `json:"errcode"`
	Msg        string   `json:"errmsg"`
}

用户信息

type Scene

type Scene struct {
	SceneId int `json:"scene_id"`
}

type UserEvent

type UserEvent struct {
	ToUserName   string `p:"ToUserName" xml:"ToUserName"`     // 开发者微信号
	FromUserName string `p:"FromUserName" xml:"FromUserName"` // 发送方账号(一个OpenID)
	CreateTime   int    `p:"CreateTime" xml:"CreateTime"`     // 消息创建时间(整型)
	MsgType      string `p:"MsgType" xml:"MsgType"`           // 消息类型,event,
	Event        string `p:"Event" xml:"Event"`               // 事件类型,subscribe(关注), SCAN(已关注)
	EventKey     string `p:"EventKey" xml:"EventKey"`         // 事件KEY值,qrscene_为前缀,后面为二维码的参数值
	Ticket       string `p:"Ticket" xml:"Ticket"`             // 二维码的ticket,可用来换取二维码图片
}

用户事件

type VerifyParams

type VerifyParams struct {
	Signature string
	Timestamp string
	Nonce     string
	Echostr   string
}

微信服务器验证

type WechatCfg

type WechatCfg struct {
	Token       string
	Appid       string
	Appsecret   string
	ExpiresTime int
}

type WechatLangType

type WechatLangType string
const (
	WECHAT_LANG_CN WechatLangType = "cn"
	WECHAT_LANG_EN WechatLangType = "en"
)

Jump to

Keyboard shortcuts

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