webchat

package
v0.0.0-...-e9adc15 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2021 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidIvSize       = errors.New("iv length must equal block size")
	ErrUnPaddingOutOfRange = errors.New("unPadding out of range")
)

error defined

Functions

func MiniProgramDecrypt

func MiniProgramDecrypt(sessionKey, encryptedData, biv string) ([]byte, error)

func MiniProgramVerifySign

func MiniProgramVerifySign(sessionKey, rawData, signature string) bool

func PCKSUnPadding

func PCKSUnPadding(origData []byte) ([]byte, error)

PCKSUnPadding PKCS#5和PKCS#7 解填充

Types

type Client

type Client struct {
	*Config
	*resty.Client
}

func New

func New(c Config) *Client

func NewWithClient

func NewWithClient(c Config, hc *http.Client) *Client

func (*Client) Exchange

func (sf *Client) Exchange(ctx context.Context, code string) (*Token, error)

func (*Client) GetUserInfo

func (sf *Client) GetUserInfo(ctx context.Context, accessToken, openid string) (*UserInfoResponse, error)

func (*Client) MiniProgramCode2Session

func (sf *Client) MiniProgramCode2Session(ctx context.Context, code string) (*MiniProgramCode2SessionResponse, error)

func (*Client) RefreshToken

func (sf *Client) RefreshToken(ctx context.Context, refreshToken string) (*Token, error)

func (*Client) VerifyAuthToken

func (sf *Client) VerifyAuthToken(ctx context.Context, accessToken string) error

type Config

type Config struct {
	// ClientID is the application's ID.
	ClientID string

	// ClientSecret is the application's secret.
	ClientSecret string

	// RedirectURL is the URL to redirect users going through
	// the OAuth flow, after the resource owner's URLs.
	RedirectURL string
}

func (*Config) AuthCodeURL

func (c *Config) AuthCodeURL(state string) string

AuthCodeURL 获取授权登录地址

type ErrResponse

type ErrResponse struct {
	ErrCode int    `json:"errcode"`
	ErrMsg  string `json:"errmsg"`
}

type MiniProgramCode2SessionResponse

type MiniProgramCode2SessionResponse struct {
	Unionid    string `json:"unionid"`     // 用户统一标识。针对一个微信开放平台帐号下的应用,同一用户的unionid是唯一的。
	Openid     string `json:"openid"`      // 普通用户的标识,对当前开发者帐号唯一
	SessionKey string `json:"session_key"` // 会话key
	ErrCode    int    `json:"errcode"`     // 错误码
	ErrMsg     string `json:"errmsg"`      // 错误消息
}

type Token

type Token struct {
	AccessToken  string `json:"access_token"`  // 接口调用凭证
	ExpiresIn    int    `json:"expires_in"`    // 超时时间,单位: s
	RefreshToken string `json:"refresh_token"` // 用户刷新refresh token
	Openid       string `json:"openid"`        // 授权用户唯一标识
	Scope        string `json:"scope"`         // 用户授权的作用域,使用逗号(,)分隔
}

type UserInfoResponse

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

Jump to

Keyboard shortcuts

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