wechat.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package dao
  2. import (
  3. "context"
  4. "encoding/json"
  5. "net/http"
  6. "go-common/app/admin/ep/merlin/conf"
  7. "go-common/app/admin/ep/merlin/model"
  8. "go-common/library/log"
  9. )
  10. const (
  11. _wechatGroup = "/ep/admin/saga/v2/wechat/appchat/send"
  12. )
  13. //WeChatSendMessage We Chat Send Message
  14. func (d *Dao) WeChatSendMessage(c context.Context, msgSendReq *model.MsgSendReq) (msgSendRes *model.MsgSendRes, err error) {
  15. var (
  16. url = conf.Conf.WeChat.WeChatHost + _wechatGroup
  17. req *http.Request
  18. res = &model.MsgSendRes{}
  19. )
  20. msgSendRequest, _ := json.Marshal(msgSendReq)
  21. log.Info("url:(%s)", url)
  22. log.Info("msgSendRequest:(%s)", string(msgSendRequest))
  23. if req, err = d.newRequest(http.MethodPost, url, msgSendReq); err != nil {
  24. return
  25. }
  26. req.Header.Set("Content-Type", "application/json")
  27. if err = d.httpClient.Do(c, req, &res); err != nil {
  28. log.Error("d.AddWechatSend url(%s) res($s) error(%v)", url, res, err)
  29. return
  30. }
  31. msgSendRes = res
  32. rsp, _ := json.Marshal(msgSendRes)
  33. log.Info("wechat send message response :(%s)", string(rsp))
  34. return
  35. }