bplus.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package bplus
  2. import (
  3. "context"
  4. "encoding/json"
  5. "net/url"
  6. "strconv"
  7. "go-common/app/interface/main/app-resource/conf"
  8. "go-common/library/ecode"
  9. "go-common/library/log"
  10. httpx "go-common/library/net/http/blademaster"
  11. "github.com/pkg/errors"
  12. )
  13. const (
  14. _checkUser = "/promo_svr/v0/promo_svr/inner_user_check"
  15. )
  16. // Dao bplus
  17. type Dao struct {
  18. client *httpx.Client
  19. // url
  20. checkUserURL string
  21. }
  22. // New bplus
  23. func New(c *conf.Config) (d *Dao) {
  24. d = &Dao{
  25. client: httpx.NewClient(c.HTTPClient),
  26. // url
  27. checkUserURL: c.Host.VC + _checkUser,
  28. }
  29. return
  30. }
  31. // UserCheck 动态互推入口白名单
  32. func (d *Dao) UserCheck(c context.Context, mid int64) (ok bool, err error) {
  33. params := url.Values{}
  34. params.Set("uid", strconv.FormatInt(mid, 10))
  35. var res struct {
  36. Code int `json:"code"`
  37. Data struct {
  38. Status int `json:"status"`
  39. }
  40. }
  41. if err = d.client.Get(c, d.checkUserURL, "", params, &res); err != nil {
  42. return
  43. }
  44. b, _ := json.Marshal(&res)
  45. log.Info("UserCheck url(%s) response(%s)", d.checkUserURL+"?"+params.Encode(), b)
  46. if res.Code != ecode.OK.Code() {
  47. err = errors.Wrap(ecode.Int(res.Code), d.checkUserURL+"?"+params.Encode())
  48. return
  49. }
  50. if res.Data.Status == 1 {
  51. ok = true
  52. }
  53. return
  54. }