token

package
v1.8.101 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2024 License: Zlib Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NAccessToken  = "access:token"         /*自己本身的access token*/
	NRefreshToken = "access:token:refresh" /*刷新自己本身access token */
	NTicket       = "get:ticket"
	NOauth2       = "oauth2" /*网页,个人授权*/
	NOauthAccount = "oauth2:account"
	NOauth2App3   = "oauth2:app3"        /*第三方应用授权,比把公众号授权给某个应用*/
	NPreAuthCode  = "app3:pre_auth_code" /* for 公众号授权给第三方,需要先获取一个 预授权码,然后调用前端授权页面进行授权,授权成功后会给一个授权码 "authorization_code"
	然后用这个 authorization_code去调用 NOauth2App3,获取到 access token 相关信息 */

	NAccessTokenProxy = "access:token:proxy" /* 进行代理,中转,从别的服务器获取token相关信息 */

	NGetOwner = "get:owner"
)
View Source
const (
	PermanentInfo = "permanentInfo"
	PermanentCode = "permanent_code"
	AgentId       = "agentId"
	SuiteType     = "suiteType"
	Owner         = "owner"
	Parent        = "parent"
	Secret        = "secret"
	True          = "true"
	Encoder       = "encoder"
	Decoder       = "decoder"
)
View Source
const (
	BaiduType          = "baidu"
	FeiShuType         = "feishu"
	FxgType            = "fxg"
	GdtType            = "gdt"
	GdtAdvType         = "gdt.adv"
	OceanType          = "ocean"
	OceanAdvType       = "ocean.adv"
	WxType             = "wx"
	WxWebType          = "wx.web"
	WxApp3Type         = "wx.app3"
	WxApp3IdType       = "wx.app3.id"
	WxApp3WebType      = "wx.app3.web"
	WxWorkType         = "wx.work"
	WxWorkMsgAuditType = "wx.work.msg.audit"
	WxWorkProviderType = "wx.work.service.provider" //服务商
	WxWorkSuiteType    = "wx.work.service.suite"    //第三方应用及模板
	WxWorkCorpType     = "wx.work.service.corp"     //企业
	WxWorkAgentType    = "wx.work.service.agent"    //代应用
)

Variables

View Source
var (
	ErrNotSupported = fmt.Errorf("NOT support")
	ErrTokenExpired = fmt.Errorf("the access token is expired")
	ErrTokenInvalid = fmt.Errorf("the access token is invalid")
	ErrObjectNil    = fmt.Errorf("the object is nil")
	ErrParam        = fmt.Errorf("the param is not error")
)
View Source
var FormType = reflect.TypeOf((*Form)(nil)).Elem()

Functions

func AddToken

func AddToken(id string, app *AppItem)

func ChangeSecret added in v1.0.32

func ChangeSecret(id string, secret string) error

func ComponentUrl

func ComponentUrl(acsKey string, uri string) string

func DefaultForm

func DefaultForm(w *multipart.Writer, field, filename string) error

func DefaultUrl

func DefaultUrl(acsKey string, uri string) string

func DeleteToken

func DeleteToken(id string) error

func EmptyUrl added in v1.0.0

func EmptyUrl(acsKey string, uri string) string

func GenId added in v1.0.4

func GenId(appId, childId string) string

func GenIdWithType added in v1.0.54

func GenIdWithType(ty, appId, childId string) string

func GetEmpty

func GetEmpty(tk Token, d data.D) (access.Token, error)

func GetId added in v1.0.22

func GetId(componentId, appId string) string

func GetIdWithType added in v1.0.54

func GetIdWithType(ty, componentId, appId string) string

func PermanentCodeKey added in v1.0.53

func PermanentCodeKey(corpId string) string

func SyncCreateChild added in v1.0.0

func SyncCreateChild(parent Token, service Service, ch *Child, acsToken access.Token, realId []string, syncFunc func())

Types

type Api added in v1.0.0

type Api struct {
	// contains filtered or unexported fields
}

func NewApi added in v1.0.0

func NewApi(tk Token, opts ...ApiOption) *Api

func (*Api) AppId added in v1.0.0

func (api *Api) AppId() string

func (*Api) Clone added in v1.0.0

func (api *Api) Clone() *Api

func (*Api) GetAccessToken added in v1.0.2

func (api *Api) GetAccessToken() (string, error)

func (*Api) IsDebug added in v1.8.65

func (api *Api) IsDebug() bool

func (*Api) Request added in v1.0.0

func (api *Api) Request(method, uri string, buf []byte, resCb ResCallBack) error

func (*Api) ResetToken added in v1.0.0

func (api *Api) ResetToken()

func (*Api) Secret added in v1.0.0

func (api *Api) Secret() string

func (*Api) Upload added in v1.0.0

func (api *Api) Upload(uri string, field string, file Form, resCb ResCallBack) error

func (*Api) WithOptions added in v1.0.0

func (api *Api) WithOptions(opts ...ApiOption) *Api

type ApiBuildUrlFunc added in v1.8.12

type ApiBuildUrlFunc func(uri string, acsToken string, d data.D) string

type ApiGetTokenFunc added in v1.0.0

type ApiGetTokenFunc func(appId string, d data.D) (string, error)

type ApiOption added in v1.8.44

type ApiOption func(opts *ApiOptions)

func WithAppId added in v1.8.44

func WithAppId(appId string) ApiOption

func WithBuildUrl added in v1.8.44

func WithBuildUrl(fn ApiBuildUrlFunc) ApiOption

func WithDebug added in v1.8.65

func WithDebug() ApiOption

func WithGetTokenFunc added in v1.8.44

func WithGetTokenFunc(fn ApiGetTokenFunc) ApiOption

func WithHeadFunc added in v1.8.44

func WithHeadFunc(fn ApiSetHeadFunc) ApiOption

func WithSecret added in v1.8.44

func WithSecret(secret string) ApiOption

func WithSeqNo added in v1.8.44

func WithSeqNo(no string) ApiOption

func WithSetTokenFunc added in v1.8.44

func WithSetTokenFunc(fn ApiSetTokenFunc) ApiOption

func WithToken added in v1.8.44

func WithToken(token string) ApiOption

func WithTryCount added in v1.8.44

func WithTryCount(count int) ApiOption

type ApiOptions added in v1.0.33

type ApiOptions struct {
	data.Options
	// contains filtered or unexported fields
}

type ApiSetHeadFunc added in v1.0.0

type ApiSetHeadFunc func(h *http.Header, acsToken string)

type ApiSetTokenFunc added in v1.0.0

type ApiSetTokenFunc func(appId string, token string)

type App

type App struct {
	ParentId string `json:"parentId"`
	Id       string `json:"id"`
	AppId    string `json:"appid"`
	Secret   string `json:"secret,omitempty"`
	Type     string `json:"type,omitempty"`
	Name     string `json:"name,omitempty"`
	IsCache  bool   `json:"cache,omitempty"`
}

func (*App) String added in v1.0.58

func (a *App) String() string

type AppItem added in v1.0.0

type AppItem struct {
	// contains filtered or unexported fields
}

func NewAppItem added in v1.0.0

func NewAppItem(app App, tk Token, options ...ConfigOptions) *AppItem

func (*AppItem) Path added in v1.2.3

func (app *AppItem) Path() string

type AppMgr

type AppMgr struct {
	// contains filtered or unexported fields
}

func Mgr

func Mgr() *AppMgr

func (*AppMgr) AddRealId added in v1.0.4

func (m *AppMgr) AddRealId(realId []string, id string, ty string) error

func (*AppMgr) AddToken

func (m *AppMgr) AddToken(id string, app *AppItem)

func (*AppMgr) ChangeSecret added in v1.0.31

func (m *AppMgr) ChangeSecret(id string, secret string) error

func (*AppMgr) Clear

func (m *AppMgr) Clear(id string, key string) error

func (*AppMgr) CreateChild

func (m *AppMgr) CreateChild(parent Token, info *Child, service Service) (Token, error)

func (*AppMgr) DeleteRealId added in v1.0.55

func (m *AppMgr) DeleteRealId(ty string, realId string) error

func (*AppMgr) DeleteToken

func (m *AppMgr) DeleteToken(id string) error

func (*AppMgr) GetRealId added in v1.0.4

func (m *AppMgr) GetRealId(ty string, realId string) (string, bool)

func (*AppMgr) GetToken

func (m *AppMgr) GetToken(id string) (Token, error)

func (*AppMgr) HasToken added in v1.0.3

func (m *AppMgr) HasToken(id string) bool

func (*AppMgr) LoadApp added in v1.0.4

func (m *AppMgr) LoadApp() []App

func (*AppMgr) Read

func (m *AppMgr) Read(id string, key string) (validate.Data, error)

func (*AppMgr) Save added in v1.0.6

func (m *AppMgr) Save(async bool)

func (*AppMgr) SetAccessToken

func (m *AppMgr) SetAccessToken(id string, acs access.Token) string

func (*AppMgr) Write

func (m *AppMgr) Write(id string, key string, v *validate.Data) error

type Base

type Base interface {
	GetAppId() string
	GetSecret() string
	GetAccessToken(options ...data.OptionsFunc) (string, error)
}

type CheckErrorFunc added in v1.0.28

type CheckErrorFunc func(result ResultObject) error

type Child

type Child struct {
	App
	VMap VMap `json:"data"`
}

func (*Child) String added in v1.8.49

func (c *Child) String() string

type Config

type Config struct {
	StoreType string `json:"storeType"`
}

func (Config) IsLocal

func (c Config) IsLocal() bool

type ConfigOptions added in v1.0.4

type ConfigOptions func(conf *Config)

type CreateChildFunc added in v1.0.0

type CreateChildFunc func(tk Token, sev Service, ch *Child, acsToken access.Token) (Token, error)

type FUpdate added in v1.0.4

type FUpdate struct {
	// contains filtered or unexported fields
}

type Form added in v1.0.34

type Form interface {
	CreateForm(w *multipart.Writer, field string) error
}

type GenFunc added in v1.0.28

type GenFunc func(tk Token, d data.D) (access.Token, error)

type GetUrlFunc added in v1.0.0

type GetUrlFunc func(acsKey string, uri string) string

type Item added in v1.0.0

type Item struct {
	Apps []App `json:"apps"`
}

type RealId added in v1.0.4

type RealId struct {
	// contains filtered or unexported fields
}

func (*RealId) Add added in v1.0.4

func (rid *RealId) Add(realId []string, id string)

func (*RealId) Delete added in v1.0.4

func (rid *RealId) Delete(realId string) bool

func (*RealId) Get added in v1.0.4

func (rid *RealId) Get(realId string) (string, bool)

type Request added in v1.0.28

type Request interface {
	BuildUrl(uri string, acsKey string, d data.D) string
	SetHead(h *http.Header, acsKey string)
	SetCheckError(check CheckErrorFunc)
	CheckError(err error) error
}

Request GetUrl for request

type ResCallBack added in v1.0.0

type ResCallBack func(hp *commonhttp.Http, body []byte) error

type ResCode

type ResCode struct {
	ParentId string `json:"parentId"`
	Id       string `json:"id"`
	AppId    string `json:"appid"`
	Type     string `json:"type"`
	Code     string `json:"code"`
}

type ResToken

type ResToken struct {
	ParentId string `json:"parentId"`
	Id       string `json:"id"`
	AppId    string `json:"appid"`
	Type     string `json:"type"`
	Token    string `json:"token"`
}

type Result added in v1.0.28

type Result struct {
	Code    int32
	SubCode string
	Msg     string
	Raw     interface{}
}

func Error added in v1.8.8

func Error(code int32, err string) Result

func SubError added in v1.8.8

func SubError(code int32, subCode string, err string) Result

func Succeed added in v1.8.8

func Succeed() Result

func TryCount added in v1.8.8

func TryCount() Result

func (Result) Error added in v1.8.8

func (r Result) Error() string

error.Error interface

func (Result) GetCode added in v1.0.28

func (r Result) GetCode() int32

func (Result) GetMsg added in v1.0.28

func (r Result) GetMsg() string

func (Result) GetSubCode added in v1.0.28

func (r Result) GetSubCode() string

func (Result) IsTokenError added in v1.8.8

func (r Result) IsTokenError() bool

func (Result) IsTryCount added in v1.8.8

func (r Result) IsTryCount() bool

func (Result) Ok added in v1.8.8

func (r Result) Ok() bool

type ResultObject added in v1.8.8

type ResultObject interface {
	GetCode() int32
	GetSubCode() string
	GetMsg() string
}

type Service

type Service interface {
	Request
	Execute(tk Token, cmd string, d data.D) (interface{}, error)
}

type Ticket

type Ticket struct {
	Ticket   string `json:"ticket"`
	ExpireIn int64  `json:"expires_in"`
}

func (Ticket) GetAccessToken added in v1.8.56

func (a Ticket) GetAccessToken() access.Value

func (Ticket) GetRefAccessToken added in v1.8.56

func (a Ticket) GetRefAccessToken() access.Value

func (Ticket) IsValid

func (a Ticket) IsValid() bool

type Token

type Token interface {
	Parent() Token
	CreateChild(app *App, service Service) Token

	IsCache() bool
	GetParentId() string
	GetId() string
	GetAppType() string
	GetAppId() string
	GetSecret() string
	GetName() string
	SetSecret(secret string)

	GetAccessToken(options ...data.OptionsFunc) (string, error)
	SetAccessTokenWithAcs(acs access.Token) string
	SetAccessToken(tk string, expire int64) error
	ClearAccessToken()

	SetRefreshAccessToken(tk string, expire int64) error
	RefreshAccessToken(refToken string) (string, error)

	GetCode(name string) (string, error)
	ClearCode(name string) error
	SetCode(name, code string, expire int64) error

	GetRequest() Request
	// Execute data["appid"]
	Execute(cmd string, d data.D) (interface{}, error)
}

func CreateChild added in v1.0.0

func CreateChild(parent Token, service Service, ch *Child, acsToken access.Token) (Token, error)

func CreateChildEmpty added in v1.0.0

func CreateChildEmpty(tk Token, sev Service, ch *Child, acsToken access.Token) (Token, error)

func GetRealId added in v1.0.4

func GetRealId(ty string, realId string) (Token, error)

func GetToken

func GetToken(id string) (Token, error)

func New

func New(app *App, service Service) Token

type VMap

type VMap map[string]*validate.Data

VMap [string] = access_token, refresh_token, code...

func (*VMap) String added in v1.8.49

func (vmap *VMap) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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