wechat.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package dao
  2. import (
  3. "context"
  4. "net/http"
  5. "go-common/app/admin/ep/melloi/conf"
  6. "go-common/app/admin/ep/melloi/model"
  7. "go-common/library/log"
  8. )
  9. const (
  10. _wechatGroup = "/ep/admin/saga/v2/wechat/appchat/send"
  11. _wechatPerson = "/ep/admin/saga/v2/wechat/message/send"
  12. )
  13. //AddWechatSend send msg to group
  14. func (d *Dao) AddWechatSend(c context.Context, cookie, content string) (msgSendRes *model.MsgSendRes, err error) {
  15. var (
  16. url = conf.Conf.Wechat.Host + _wechatGroup
  17. req *http.Request
  18. msgSendReq = &model.MsgSendReq{
  19. ChatID: conf.Conf.Wechat.Chatid,
  20. MsgType: conf.Conf.Wechat.Msgtype,
  21. Text: model.MsgSendReqText{Content: content},
  22. Safe: conf.Conf.Wechat.Safe,
  23. }
  24. )
  25. if req, err = d.newRequest(http.MethodPost, url, msgSendReq); err != nil {
  26. return
  27. }
  28. req.Header.Set("Cookie", cookie)
  29. req.Header.Set("Content-Type", "application/json")
  30. if err = d.httpClient.Do(c, req, &msgSendRes); err != nil {
  31. log.Error("d.AddWechatSend url(%s) res($s) error(%v)", url, msgSendRes, err)
  32. return
  33. }
  34. return
  35. }
  36. // PushWechatMsgToPerson send msg to users
  37. func (d *Dao) PushWechatMsgToPerson(c context.Context, cookie string, users []string, msg string) (msgSendRes *model.MsgSendRes, err error) {
  38. var (
  39. url = conf.Conf.Wechat.Host + _wechatPerson
  40. req *http.Request
  41. msgSendReq = &model.MsgSendPersonReq{
  42. Users: users,
  43. Content: msg,
  44. }
  45. )
  46. if req, err = d.newRequest(http.MethodPost, url, msgSendReq); err != nil {
  47. return
  48. }
  49. req.Header.Set("Cookie", cookie)
  50. req.Header.Set("Content-Type", "application/json")
  51. if err = d.httpClient.Do(c, req, &msgSendRes); err != nil {
  52. log.Error("d.WeChatPerson url(%s) res($s) error(%v)", url, msgSendRes, err)
  53. return
  54. }
  55. return
  56. }