passport.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package dao
  2. import (
  3. "context"
  4. "net/url"
  5. "strconv"
  6. "go-common/app/service/main/account/model"
  7. "go-common/library/ecode"
  8. "go-common/library/net/metadata"
  9. "github.com/pkg/errors"
  10. )
  11. // PassportDetail get detail.
  12. func (d *Dao) PassportDetail(c context.Context, mid int64) (res *model.PassportDetail, err error) {
  13. ip := metadata.String(c, metadata.RemoteIP)
  14. params := url.Values{}
  15. // params.Set("access_key", accessKey)
  16. params.Set("mid", strconv.FormatInt(mid, 10))
  17. var resp struct {
  18. Code int `json:"code"`
  19. Info *model.PassportDetail `json:"data"`
  20. }
  21. req, err := d.httpR.NewRequest("GET", d.detailURI, ip, params)
  22. if err != nil {
  23. err = errors.Wrap(err, "dao passport detail")
  24. return
  25. }
  26. // req.Header.Set("Cookie", cookie)
  27. req.Header.Set("X-BACKEND-BILI-REAL-IP", ip)
  28. if err = d.httpR.Do(c, req, &resp); err != nil {
  29. err = errors.Wrap(err, "dao passport detail")
  30. return
  31. }
  32. if resp.Code != 0 {
  33. err = ecode.Int(resp.Code)
  34. err = errors.Wrap(err, "dao passport detail")
  35. return
  36. }
  37. res = resp.Info
  38. return
  39. }
  40. // PassportProfile is.
  41. func (d *Dao) PassportProfile(c context.Context, mid int64, ip string) (res *model.PassportProfile, err error) {
  42. params := url.Values{}
  43. params.Set("mid", strconv.FormatInt(mid, 10))
  44. var resp struct {
  45. Code int `json:"code"`
  46. Data *model.PassportProfile `json:"data"`
  47. }
  48. if err = d.httpP.Get(c, d.profileURI, ip, params, &resp); err != nil {
  49. err = errors.Wrap(err, "dao passport profile")
  50. return nil, err
  51. }
  52. if resp.Code != 0 {
  53. err = ecode.Int(resp.Code)
  54. err = errors.WithStack(err)
  55. return
  56. }
  57. res = resp.Data
  58. return
  59. }