util.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package util
  2. import (
  3. "bp.jydev.jianyu360.cn/SocialPlatform/socialPlatform/entity"
  4. "bp.jydev.jianyu360.cn/SocialPlatform/socialPlatform/rpc/social/social"
  5. "context"
  6. "fmt"
  7. "github.com/zeromicro/go-zero/core/logx"
  8. "net/http"
  9. )
  10. func GetTouristCookieInfo(r *http.Request) (sessionId, trustedId string, err error) {
  11. cn, ce := r.Cookie(entity.CookieName)
  12. ti, te := r.Cookie(entity.JYTrustedId)
  13. if ce != nil || cn == nil || cn.Value == "" { //session
  14. err = fmt.Errorf("当用户信息有误")
  15. logx.Error("当前用户没有session信息")
  16. return
  17. }
  18. if te != nil || ti == nil || ti.Value == "" { //不存在信用标识
  19. err = fmt.Errorf("当用户信息有误")
  20. logx.Error("当前用户没有JYTrustedIdn信息")
  21. return
  22. }
  23. sessionId = cn.Value
  24. trustedId = ti.Value
  25. return
  26. }
  27. // tourist
  28. func GetTouristInfo(r *http.Request, sl social.Social, ctx context.Context) (ti *social.TouristInfo, err error) {
  29. sessionId, trustedId, stErr := GetTouristCookieInfo(r)
  30. if stErr != nil {
  31. return nil, stErr
  32. }
  33. result, rErr := sl.TouristInfo(ctx, &social.TouristInfoReq{
  34. SessionId: sessionId,
  35. Ip: entity.GetIp(r),
  36. TrustedId: trustedId,
  37. })
  38. if rErr != nil || result.Data.BaseUserId == 0 {
  39. logx.Error(result, "-获取当前游客信息有误:", rErr.Error())
  40. return nil, rErr
  41. }
  42. ti = result.Data
  43. return
  44. }