2025-02-07 15:18:26 +08:00

47 lines
990 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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下发条件的情况下会返回
}