package util import ( "bp.jydev.jianyu360.cn/SocialPlatform/socialPlatform/entity" "bp.jydev.jianyu360.cn/SocialPlatform/socialPlatform/rpc/social/social" "context" "fmt" "github.com/zeromicro/go-zero/core/logx" "net/http" ) func GetTouristCookieInfo(r *http.Request) (sessionId, trustedId string, err error) { cn, ce := r.Cookie(entity.CookieName) ti, te := r.Cookie(entity.JYTrustedId) if ce != nil || cn == nil || cn.Value == "" { //session err = fmt.Errorf("当用户信息有误") logx.Error("当前用户没有session信息") return } if te != nil || ti == nil || ti.Value == "" { //不存在信用标识 err = fmt.Errorf("当用户信息有误") logx.Error("当前用户没有JYTrustedIdn信息") return } sessionId = cn.Value trustedId = ti.Value return } // tourist func GetTouristInfo(r *http.Request, sl social.Social, ctx context.Context) (ti *social.TouristInfo, err error) { sessionId, trustedId, stErr := GetTouristCookieInfo(r) if stErr != nil { return nil, stErr } result, rErr := sl.TouristInfo(ctx, &social.TouristInfoReq{ SessionId: sessionId, Ip: entity.GetIp(r), TrustedId: trustedId, }) if rErr != nil || result.Data.BaseUserId == 0 { logx.Error(result, "-获取当前游客信息有误:", rErr.Error()) return nil, rErr } ti = result.Data return }