youtu_grpc/app/auth_service/internal/logic/code2_session_logic.go

39 lines
931 B
Go
Raw Permalink Normal View History

2025-02-05 18:45:49 +08:00
package logic
import (
"context"
2025-02-07 15:18:26 +08:00
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/auth_service/auth_service"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/auth_service/internal/svc"
2025-02-05 18:45:49 +08:00
"github.com/zeromicro/go-zero/core/logx"
)
type Code2SessionLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewCode2SessionLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Code2SessionLogic {
return &Code2SessionLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *Code2SessionLogic) Code2Session(in *auth_service.Code2SessionRequest) (*auth_service.Code2SessionResponse, error) {
2025-02-06 15:35:23 +08:00
cli, err := l.svcCtx.Cli.Get(in.AppId)
if err != nil {
return nil, err
}
res, err := cli.Code2Session(l.ctx, in.Code, in.AnonymousCode)
if err != nil {
return nil, err
}
return &auth_service.Code2SessionResponse{
OpenId: res.OpenID,
UnionId: res.UnionID,
}, nil
2025-02-05 18:45:49 +08:00
}