depend.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package medal
  2. import (
  3. "context"
  4. "fmt"
  5. "net/url"
  6. "strconv"
  7. "go-common/library/log"
  8. )
  9. // SendMsg send message.
  10. func (d *Dao) SendMsg(c context.Context, mid int64, title string, context string) (err error) {
  11. params := url.Values{}
  12. params.Set("mc", "2_1_13")
  13. params.Set("title", title)
  14. params.Set("data_type", "4")
  15. params.Set("context", context)
  16. params.Set("mid_list", fmt.Sprintf("%d", mid))
  17. var res struct {
  18. Code int `json:"code"`
  19. Data *struct {
  20. Status int8 `json:"status"`
  21. Remark string `json:"remark"`
  22. } `json:"data"`
  23. }
  24. if err = d.client.Post(c, d.sendMsgURI, "", params, &res); err != nil {
  25. log.Error("sendMsgURL(%s) error(%v)", d.sendMsgURI+"?"+params.Encode(), err)
  26. return
  27. }
  28. if res.Code != 0 {
  29. log.Error("sendMsgURL(%s) res(%d)", d.sendMsgURI+"?"+params.Encode(), res.Code)
  30. }
  31. log.Info("d.sendMsgURL url(%s) res(%d)", d.sendMsgURI+"?"+params.Encode(), res.Code)
  32. return
  33. }
  34. // GetWearedfansMedal get weared fans medals from live.
  35. func (d *Dao) GetWearedfansMedal(c context.Context, mid int64, source int8) (isLove bool, err error) {
  36. params := url.Values{}
  37. params.Set("uid", strconv.FormatInt(mid, 10))
  38. params.Set("source", strconv.FormatInt(int64(source), 10))
  39. var res struct {
  40. Code int `json:"code"`
  41. Data *struct {
  42. Max int8 `json:"max"`
  43. Cnt int8 `json:"cnt"`
  44. MasterMax int8 `json:"master_max"`
  45. } `json:"data"`
  46. }
  47. if err = d.client.Post(c, d.getWaredFansMedalURI, "", params, &res); err != nil {
  48. log.Error("GetWearedfansMedal(%s) error(%v)", d.getWaredFansMedalURI+"?"+params.Encode(), err)
  49. return
  50. }
  51. if res.Code != 0 {
  52. log.Error("GetWearedfansMedal(%s) res(%d)", d.getWaredFansMedalURI+"?"+params.Encode(), res.Code)
  53. }
  54. log.Info("GetWearedfansMedal(%s) res(%+v)", d.getWaredFansMedalURI+"?"+params.Encode(), res)
  55. if res.Code == 0 {
  56. if res.Data.Cnt > 0 {
  57. isLove = true
  58. return
  59. }
  60. }
  61. return
  62. }