white.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package white
  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. // Dao bplus
  14. type Dao struct {
  15. client *httpx.Client
  16. }
  17. // New bplus
  18. func New(c *conf.Config) (d *Dao) {
  19. d = &Dao{
  20. client: httpx.NewClient(c.HTTPClient),
  21. }
  22. return
  23. }
  24. // WhiteVerify white verify
  25. func (d *Dao) WhiteVerify(c context.Context, mid int64, urlStr string) (ok bool, err error) {
  26. params := url.Values{}
  27. params.Set("uid", strconv.FormatInt(mid, 10))
  28. var res struct {
  29. Code int `json:"code"`
  30. Data struct {
  31. Status int `json:"status"`
  32. }
  33. }
  34. if err = d.client.Get(c, urlStr, "", params, &res); err != nil {
  35. return
  36. }
  37. b, _ := json.Marshal(&res)
  38. log.Info("WhiteVerify url(%s) response(%s)", urlStr+"?"+params.Encode(), b)
  39. if res.Code != ecode.OK.Code() {
  40. err = errors.Wrap(ecode.Int(res.Code), urlStr+"?"+params.Encode())
  41. return
  42. }
  43. if res.Data.Status == 1 {
  44. ok = true
  45. }
  46. return
  47. }