47 lines
990 B
Go
47 lines
990 B
Go
|
package cli
|
|||
|
|
|||
|
import (
|
|||
|
"context"
|
|||
|
"errors"
|
|||
|
"sync"
|
|||
|
)
|
|||
|
|
|||
|
const (
|
|||
|
DouyinClientType = "douyin"
|
|||
|
WechatClientType = "wechat"
|
|||
|
)
|
|||
|
|
|||
|
var (
|
|||
|
ErrClientNotFound = errors.New("client not found")
|
|||
|
)
|
|||
|
|
|||
|
type Helper struct {
|
|||
|
sync.Map
|
|||
|
}
|
|||
|
|
|||
|
// Get 获取小程序客户端
|
|||
|
func (h *Helper) Get(appId string) (cli DWClient, err error) {
|
|||
|
if v, ok := h.Load(appId); ok {
|
|||
|
cli = v.(DWClient)
|
|||
|
return
|
|||
|
}
|
|||
|
return nil, ErrClientNotFound
|
|||
|
}
|
|||
|
|
|||
|
// Set 设置小程序客户端
|
|||
|
func (h *Helper) Set(appId string, cli DWClient) {
|
|||
|
h.Store(appId, cli)
|
|||
|
}
|
|||
|
|
|||
|
type DWClient interface {
|
|||
|
// GetAccessToken 获取access_token
|
|||
|
GetAccessToken(ctx context.Context) (string, error)
|
|||
|
// Code2Session 登录凭证校验
|
|||
|
Code2Session(ctx context.Context, code, anonymousCode string) (*Code2SessionResponse, error)
|
|||
|
}
|
|||
|
|
|||
|
type Code2SessionResponse struct {
|
|||
|
OpenID string `json:"openId"` // 用户唯一标识
|
|||
|
UnionID string `json:"unionId"` // 用户在开放平台的唯一标识符,在满足UnionID下发条件的情况下会返回
|
|||
|
}
|