46 lines
1.1 KiB
Go
46 lines
1.1 KiB
Go
package cli
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/auth_service/pkg/douyin/access-token"
|
|
douyinopenapi "gitea.youtukeji.com.cn/youtu/openapi-helper/douyin"
|
|
"github.com/silenceper/wechat/v2/cache"
|
|
)
|
|
|
|
type DouYinApi struct {
|
|
api *douyinopenapi.DouYinOpenApi // 抖音openapi客户端
|
|
}
|
|
|
|
func (d *DouYinApi) GetAccessToken(_ context.Context) (string, error) {
|
|
return d.api.GetAccessToken()
|
|
}
|
|
|
|
func (d *DouYinApi) Code2Session(_ context.Context, code, anonymousCode string) (session *Code2SessionResponse, err error) {
|
|
var r douyinopenapi.Code2SessionResponse
|
|
r, err = d.api.Code2Session(code, anonymousCode)
|
|
if err != nil {
|
|
return
|
|
}
|
|
if r.Errcode != 0 {
|
|
err = errors.New(r.Errmsg)
|
|
return
|
|
}
|
|
session = &Code2SessionResponse{
|
|
OpenID: r.Openid,
|
|
UnionID: r.Unionid,
|
|
}
|
|
return
|
|
}
|
|
|
|
func NewDouYinApi(appId, appSecret string, cache cache.Cache) *DouYinApi {
|
|
return &DouYinApi{
|
|
api: douyinopenapi.NewDouYinOpenApi(douyinopenapi.DouYinOpenApiConfig{
|
|
AppId: appId,
|
|
AppSecret: appSecret,
|
|
AccessToken: access_token.NewDefaultAccessToken(appId, appSecret, cache, false),
|
|
Cache: cache,
|
|
}),
|
|
}
|
|
}
|