miniprogram

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2025 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ObjDecodeErr 返回值对象解析错误
	ObjDecodeErr = web.NewErrorModel(-1, "json解析失败", nil, http.StatusBadRequest)
	// StructNotHasCommonError 请求需要解析的对象错误  没有commonError
	StructNotHasCommonError = web.NewErrorModel(-1, "需要解析的结构体错误", nil, http.StatusBadRequest)
)

Functions

This section is empty.

Types

type Client

type Client struct {
	HttpClient      interfaces.HttpClient
	Store           interfaces.Store
	AppId           string `json:"app_id" yaml:"app_id"`
	AppSecret       string `json:"app_secret" yaml:"app_secret"`
	CachePrefix     string `json:"cache_prefix" yaml:"cache_prefix"`
	AccessToken     string `json:"access_token" yaml:"access_token"`
	AccessTokenLock *sync.Mutex
	// contains filtered or unexported fields
}

func NewClient

func NewClient(o ...Options) *Client

func (*Client) Code2Session

func (c *Client) Code2Session(code string) (*Code2SessionResult, error)

Code2Session 登陆凭证校验的结果

func (*Client) Get

func (c *Client) Get(url string, obj interface{}) ([]byte, error)

func (*Client) GetAccessToken

func (c *Client) GetAccessToken() (string, error)

GetAccessToken 获取access_token

func (*Client) GetCachePrefix

func (c *Client) GetCachePrefix() string

GetCachePrefix 获取缓存前缀

func (*Client) HasQuery

func (c *Client) HasQuery(url string) bool

HasQuery 判断url中是否有参数

func (*Client) Post

func (c *Client) Post(url string, body []byte, obj interface{}, header map[string]string) ([]byte, error)

func (*Client) PostJSON

func (c *Client) PostJSON(url string, params interface{}, obj interface{}) ([]byte, error)

func (*Client) RefreshAccessToken

func (c *Client) RefreshAccessToken() (string, error)

RefreshAccessToken 刷新access_token

type Code2SessionResult

type Code2SessionResult struct {
	response.CommonError
	OpenId     string `json:"openid"`
	SessionKey string `json:"session_key"`
	UnionId    string `json:"unionid"`
}

Code2SessionResult 获取用户的openid和session_key 的结果

type GetAccessTokenResult

type GetAccessTokenResult struct {
	response.CommonError
	AccessToken string `json:"access_token"`
	ExpiresIn   int64  `json:"expires_in"`
}

GetAccessTokenResult 获取access_token结果

type HttpCliOptions

type HttpCliOptions func(*HttpClient)

func WithHttpClientCtx

func WithHttpClientCtx(c context.Context) HttpCliOptions

type HttpClient

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

func NewHttpClient

func NewHttpClient(opts ...HttpCliOptions) *HttpClient

func (*HttpClient) Get

func (h *HttpClient) Get(uri string) ([]byte, error)

func (*HttpClient) Post

func (h *HttpClient) Post(uri string, data []byte, header map[string]string) ([]byte, error)

func (*HttpClient) PostJSON

func (h *HttpClient) PostJSON(uri string, params interface{}) ([]byte, error)

type Options

type Options func(*Client)

func WithAccessToken

func WithAccessToken(accessToken string) Options

func WithAppidAndSecret

func WithAppidAndSecret(appId string, appSecret string) Options

func WithCachePrefix

func WithCachePrefix(prefix string) Options

func WithHttpClient

func WithHttpClient(cli interfaces.HttpClient) Options

func WithRedisStore

func WithRedisStore(cli *redis.Client) Options

type RedisStore

type RedisStore struct {
	Client *redis.Client
	// contains filtered or unexported fields
}

func NewRedisStore

func NewRedisStore(client *redis.Client) *RedisStore

func (*RedisStore) GetAccessToken

func (r *RedisStore) GetAccessToken(key string) (string, error)

func (*RedisStore) GetJsapiTicket added in v0.0.7

func (r *RedisStore) GetJsapiTicket(key string) (string, error)

func (*RedisStore) SetAccessToken

func (r *RedisStore) SetAccessToken(key string, accessToken string, expires int64) error

func (*RedisStore) SetJsapiTicket added in v0.0.7

func (r *RedisStore) SetJsapiTicket(key string, jsapiTicket string, expires int64) error

Jump to

Keyboard shortcuts

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