39 lines
931 B
Go
39 lines
931 B
Go
package logic
|
|
|
|
import (
|
|
"context"
|
|
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/auth_service/auth_service"
|
|
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/auth_service/internal/svc"
|
|
|
|
"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) {
|
|
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
|
|
}
|