relation.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package dao
  2. import (
  3. "context"
  4. "net/url"
  5. "strconv"
  6. "go-common/library/ecode"
  7. "go-common/library/net/metadata"
  8. "github.com/pkg/errors"
  9. )
  10. const _passportURL = "http://passport.bilibili.co/intranet/acc/bindDetail"
  11. // PassportDetail .
  12. type PassportDetail struct {
  13. BindEmail bool `json:"bind_email"`
  14. BindTel bool `json:"bind_tel"`
  15. Mid int64 `json:"mid"`
  16. }
  17. // PassportDetail get detail.
  18. func (d *Dao) PassportDetail(c context.Context, mid int64) (res *PassportDetail, err error) {
  19. ip := metadata.String(c, metadata.RemoteIP)
  20. params := url.Values{}
  21. params.Set("mid", strconv.FormatInt(mid, 10))
  22. var resp struct {
  23. Code int `json:"code"`
  24. Info *PassportDetail `json:"data"`
  25. }
  26. req, err := d.httpClient.NewRequest("GET", _passportURL, ip, params)
  27. if err != nil {
  28. err = errors.Wrap(err, "dao passport detail")
  29. return
  30. }
  31. // req.Header.Set("Cookie", cookie)
  32. req.Header.Set("X-BACKEND-BILI-REAL-IP", ip)
  33. if err = d.httpClient.Do(c, req, &resp); err != nil {
  34. err = errors.Wrap(err, "dao passport detail")
  35. return
  36. }
  37. if resp.Code != 0 {
  38. err = ecode.Int(resp.Code)
  39. err = errors.Wrap(err, "dao passport detail")
  40. return
  41. }
  42. res = resp.Info
  43. return
  44. }