notify.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package dao
  2. import (
  3. "context"
  4. "fmt"
  5. "net/url"
  6. "go-common/app/job/main/coupon/model"
  7. "go-common/library/log"
  8. "github.com/pkg/errors"
  9. )
  10. const (
  11. _defPltform = "inner"
  12. )
  13. // NotifyRet notify use coupon ret.
  14. func (d *Dao) NotifyRet(c context.Context, notifyURL string, ticketNO string, orderNO string, ip string) (data *model.CallBackRet, err error) {
  15. params := url.Values{}
  16. params.Set("ticket_no", ticketNO)
  17. params.Set("order_no", orderNO)
  18. params.Set("platform", _defPltform)
  19. params.Set("build", "0")
  20. log.Info("call service notify ret %s", notifyURL+"?"+params.Encode())
  21. var res struct {
  22. Code int `json:"code"`
  23. Message string `json:"message"`
  24. Data *model.CallBackRet `json:"result"`
  25. }
  26. if err = d.client.Post(c, notifyURL, ip, params, &res); err != nil {
  27. err = errors.Wrapf(err, "call service(%s) error", notifyURL+"?"+params.Encode())
  28. return
  29. }
  30. if res.Code != 0 {
  31. err = errors.WithStack(fmt.Errorf("call service(%s) error, res code is not 0, resp:%v", notifyURL+"?"+params.Encode(), res))
  32. return
  33. }
  34. data = res.Data
  35. log.Info("call service notify ret suc req(%s) data(%v) ", params.Encode(), data)
  36. return
  37. }