http.go 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. package dao
  2. import (
  3. "context"
  4. "net/url"
  5. "strconv"
  6. "go-common/app/job/main/member/model"
  7. "go-common/library/ecode"
  8. "go-common/library/log"
  9. )
  10. // AsoSt aso user status.
  11. type AsoSt struct {
  12. Code int64
  13. Data struct {
  14. Email string `json:"email"`
  15. Telphone string `json:"telphone"`
  16. SafeQs int8 `json:"safe_question"`
  17. Spacesta int8 `json:"spacesta"`
  18. } `json:"data"`
  19. }
  20. const (
  21. _asoURI = "http://passport.bilibili.co/intranet/acc/queryByMid"
  22. _identityURL = "http://account.bilibili.co/api/identify/info"
  23. _updateFaceURL = "http://account.bilibili.co/api/internal/member/updateFace"
  24. )
  25. // AsoStatus get aso bind status.
  26. func (d *Dao) AsoStatus(c context.Context, mid int64) (aso *model.MemberAso, err error) {
  27. params := url.Values{}
  28. params.Set("mid", strconv.FormatInt(mid, 10))
  29. res := new(struct {
  30. Code int64 `json:"code"`
  31. Data model.MemberAso `json:"data"`
  32. })
  33. if err = d.client.Get(c, _asoURI, "", params, res); err != nil {
  34. log.Error("get aso err %v uri %s ", err, _asoURI+params.Encode())
  35. return
  36. }
  37. if res.Code != 0 {
  38. err = ecode.RequestErr
  39. log.Error("asotatus err res %v", res)
  40. return
  41. }
  42. aso = &res.Data
  43. return
  44. }
  45. // IdentifyStaus identify status.
  46. func (d *Dao) IdentifyStaus(c context.Context, mid int64) (b bool, err error) {
  47. params := url.Values{}
  48. params.Set("mid", strconv.FormatInt(mid, 10))
  49. var res struct {
  50. Code int64 `json:"code"`
  51. Data struct {
  52. Identify int8 `json:"identify"` // 0
  53. } `json:"data"`
  54. }
  55. if err = d.client.Get(c, _identityURL, "", params, &res); err != nil {
  56. log.Error("get aso err %v uri %s ", err, _asoURI+params.Encode())
  57. return
  58. }
  59. if res.Code == 0 && res.Data.Identify == 0 {
  60. b = true
  61. }
  62. return
  63. }
  64. // UpdateAccFace update acc face.
  65. func (d *Dao) UpdateAccFace(c context.Context, mid int64, face string) (err error) {
  66. params := url.Values{}
  67. params.Set("mid", strconv.FormatInt(mid, 10))
  68. params.Set("face", face)
  69. var res struct {
  70. Code int `json:"code"`
  71. }
  72. if err = d.client.Post(c, _updateFaceURL, "", params, &res); err != nil {
  73. log.Error("update account face err %v uri %s ", err, _updateFaceURL+params.Encode())
  74. return
  75. }
  76. if res.Code != 0 {
  77. err = ecode.Int(res.Code)
  78. log.Error("UpdateAccFace mid(%d) error(%v)", mid, err)
  79. return
  80. }
  81. return
  82. }