account.go 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. package dao
  2. import (
  3. "context"
  4. "fmt"
  5. "net/url"
  6. "go-common/app/service/main/spy/model"
  7. "go-common/library/log"
  8. )
  9. // tel level.
  10. const (
  11. TelRiskLevelLow = 1
  12. TelRiskLevelMedium = 2
  13. TelRiskLevelHigh = 3
  14. TelRiskLevelUnknown = 4
  15. )
  16. // TelRiskLevel tel risk level.
  17. func (d *Dao) TelRiskLevel(c context.Context, mid int64) (riskLevel int8, err error) {
  18. params := url.Values{}
  19. params.Set("mid", fmt.Sprintf("%d", mid))
  20. params.Set("type", "123")
  21. var resp struct {
  22. TS int64 `json:"ts"`
  23. Code int64 `json:"code"`
  24. Data struct {
  25. Level int8 `json:"level"`
  26. Mid int64 `json:"mid"`
  27. Score int64 `json:"score"`
  28. } `json:"data"`
  29. }
  30. if err = d.httpClient.Get(c, d.c.Property.TelValidateURL, "", params, &resp); err != nil {
  31. log.Error("d.httpClient.Do() error(%v) , riskLevel = TelRiskLevelUnknown", err)
  32. riskLevel = TelRiskLevelUnknown
  33. err = nil
  34. return
  35. }
  36. if resp.Code != 0 {
  37. err = fmt.Errorf("GET TelRiskLevel url resp(%v)", resp)
  38. return
  39. }
  40. log.Info("GET TelValidateURL suc url(%s) resp(%v)", d.c.Property.TelValidateURL+"?"+params.Encode(), resp)
  41. riskLevel = resp.Data.Level
  42. return
  43. }
  44. // BlockAccount block account.
  45. func (d *Dao) BlockAccount(c context.Context, mid int64) (err error) {
  46. params := url.Values{}
  47. params.Set("mid", fmt.Sprintf("%d", mid))
  48. params.Set("admin_reason", "spy")
  49. params.Set("blockType", "3")
  50. params.Set("operator", "spy")
  51. params.Set("type", "json")
  52. var resp struct {
  53. Code int64 `json:"code"`
  54. }
  55. if err = d.httpClient.Get(c, d.c.Property.BlockAccountURL, "", params, &resp); err != nil {
  56. log.Error("httpClient.Do() error(%v)", err)
  57. return
  58. }
  59. if resp.Code != 0 {
  60. err = fmt.Errorf("GET block account url resp(%v)", resp)
  61. }
  62. return
  63. }
  64. // SecurityLogin security login
  65. func (d *Dao) SecurityLogin(c context.Context, mid int64, reason string) (err error) {
  66. params := url.Values{}
  67. params.Set("mids", fmt.Sprintf("%d", mid))
  68. params.Set("operator", "spy")
  69. params.Set("desc", reason)
  70. params.Set("type", "json")
  71. var resp struct {
  72. Code int64 `json:"code"`
  73. }
  74. if err = d.httpClient.Post(c, d.c.Property.SecurityLoginURL, "", params, &resp); err != nil {
  75. log.Error("message url(%s) error(%v)", d.c.Property.SecurityLoginURL+"?"+params.Encode(), err)
  76. return
  77. }
  78. if resp.Code != 0 {
  79. err = fmt.Errorf("POST SecurityLogin url resp(%v)", resp)
  80. return
  81. }
  82. log.Info("POST SecurityLogin suc url(%s) resp(%v)", resp)
  83. return
  84. }
  85. // TelInfo tel info.
  86. func (d *Dao) TelInfo(c context.Context, mid int64) (tel *model.TelInfo, err error) {
  87. params := url.Values{}
  88. params.Set("mid", fmt.Sprintf("%d", mid))
  89. var resp struct {
  90. Code int64 `json:"code"`
  91. Data model.TelInfo `json:"data"`
  92. }
  93. if err = d.httpClient.Get(c, d.c.Property.TelInfoByMidURL, "", params, &resp); err != nil {
  94. log.Error("d.httpClient.Do() error(%v) ,TelInfo", err)
  95. return
  96. }
  97. if resp.Code != 0 {
  98. err = fmt.Errorf("GET TelRiskLevel url resp(%v)", resp)
  99. return
  100. }
  101. tel = &resp.Data
  102. log.Info("GET TelInfoByMidURL suc url(%s) resp(%v)", d.c.Property.TelInfoByMidURL+"?"+params.Encode(), resp)
  103. return
  104. }
  105. // ProfileInfo get user profile info from account service.
  106. func (d *Dao) ProfileInfo(c context.Context, mid int64, remoteIP string) (profile *model.ProfileInfo, err error) {
  107. params := url.Values{}
  108. params.Set("mid", fmt.Sprintf("%d", mid))
  109. var resp struct {
  110. Code int64 `json:"code"`
  111. Data model.ProfileInfo `json:"data"`
  112. }
  113. if err = d.httpClient.Get(c, d.c.Property.ProfileInfoByMidURL, remoteIP, params, &resp); err != nil {
  114. log.Error("d.httpClient.Do() error(%v), ProfileInfo", err)
  115. return
  116. }
  117. if resp.Code != 0 {
  118. err = fmt.Errorf("GET ProfileInfo url resp(%v)", resp)
  119. return
  120. }
  121. profile = &resp.Data
  122. log.Info("GET ProfileInfoByMidURL suc url(%s) resp(%v)", d.c.Property.ProfileInfoByMidURL+"?"+params.Encode(), resp)
  123. return
  124. }