wx

package
v0.0.16 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2019 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Signature

func Signature(params ...string) string

Signature sha1签名

Types

type CommonError

type CommonError struct {
	ErrCode int    `gorm:"-" json:"errcode"`
	ErrMsg  string `gorm:"-" json:"errmsg"`
}

CommonError 错误代码

type Config

type Config struct {
	Appid        string // 微信应用代码
	AppSecret    string // 微信密钥
	WebAppid     string // 网站微信应用代码
	WebAppSecret string // 网站微信密钥
}

Config 配置

type JsConfig

type JsConfig struct {
	Debug     bool     `json:"debug"`     // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
	Appid     string   `json:"appId"`     // 必填,公众号的唯一标识
	Timestamp int64    `json:"timestamp"` // 必填,生成签名的时间戳
	NonceStr  string   `json:"nonceStr"`  // 必填,生成签名的随机串
	Signature string   `json:"signature"` // 必填,签名
	JsAPIList []string `json:"jsApiList"` // 必填,需要使用的JS接口列表
}

JsConfig js-api配置

type Service

type Service struct {
	Cache  *toolkit.Cache
	Config *Config
	TS     *TokenService
}

Service js服务

func NewService

func NewService(ts *TokenService, config *Config) *Service

NewService 新建js服务

func (*Service) GetConfig

func (s *Service) GetConfig(uri string) (*JsConfig, error)

GetConfig 获取jssdk配置

func (*Service) GetTicket

func (s *Service) GetTicket() (string, error)

GetTicket 获取JS-SDK使用权限

func (*Service) GetToken

func (s *Service) GetToken() (string, error)

GetToken 获取Token

func (*Service) Party

func (s *Service) Party(p iris.Party)

Party 分组

type Ticket

type Ticket struct {
	CommonError
	ExpiresIn int    `json:"expires_in"`
	Ticket    string `json:"ticket"`
}

Ticket JS-SDK使用授权

type Token

type Token struct {
	CommonError
	Openid       string    `gorm:"primary_key;size:36" json:"openid"`
	AccessToken  string    `gorm:"size:512" json:"access_token"`
	ExpiresIn    int       `json:"expires_in"`
	RefreshToken string    `gorm:"size:512" json:"refresh_token"`
	Scope        string    `gorm:"size:20" json:"scope"`
	Unionid      string    `gorm:"size:36" json:"unionid"`
	CreatedAt    time.Time `json:"createdAt"`
	UpdatedAt    time.Time `json:"updatedAt"`
}

Token 授权

type TokenService

type TokenService struct {
	DB     *gorm.DB
	Config *Config
}

TokenService 授权服务

func NewTokenService

func NewTokenService(db *gorm.DB, config *Config) *TokenService

NewTokenService 新建授权服务

func (*TokenService) CheckAccessToken

func (s *TokenService) CheckAccessToken(accessToken, openid string) (bool, error)

CheckAccessToken 检验access_token是否有效

func (*TokenService) FindToken

func (s *TokenService) FindToken(openid string) (*Token, error)

FindToken 查找Token

func (*TokenService) GetUserInfo

func (s *TokenService) GetUserInfo(accessToken, openid string) (*UserInfo, error)

GetUserInfo 如果scope为 snsapi_userinfo 则可以通过此方法获取到用户基本信息

func (*TokenService) RefreshAccessToken

func (s *TokenService) RefreshAccessToken(openid, refreshToken string) (*Token, error)

RefreshAccessToken 更新授权

func (*TokenService) SaveToken

func (s *TokenService) SaveToken(code string, web bool) (*Token, error)

SaveToken 获取授权

type UserInfo

type UserInfo struct {
	CommonError
	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"`
}

UserInfo 用户信息

Jump to

Keyboard shortcuts

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