message.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package hook
  2. import "fmt"
  3. // 开启/关闭实时消息接收功能
  4. func (h *Hook) ConfigureMsgRecive(isEnable string, url string) (err error) {
  5. resp, err := h.Client.R().SetBody(&ConfigureMsgReciveReq{
  6. IsEnable: isEnable,
  7. URL: url,
  8. }).Post("http://" + h.ServerIp + ":" + h.WxPort + "/ConfigureMsgRecive")
  9. if err != nil {
  10. return
  11. }
  12. if !resp.IsSuccessState() {
  13. err = fmt.Errorf("ConfigureMsgRecive failed with status code %d", resp.StatusCode)
  14. return
  15. }
  16. return
  17. }
  18. // 发送微信文本消息
  19. func (h *Hook) SendTextMsg(wxid, msg string) (err error) {
  20. resp, err := h.Client.R().SetBody(&SendTextMsgReq{
  21. Wxid: wxid,
  22. Msg: msg,
  23. }).Post("http://" + h.ServerIp + ":" + h.WxPort + "/SendTextMsg")
  24. if err != nil {
  25. return
  26. }
  27. if !resp.IsSuccessState() {
  28. err = fmt.Errorf("SendTextMsg failed with status code %d", resp.StatusCode)
  29. return
  30. }
  31. return
  32. }
  33. // 发送微信图片
  34. func (h *Hook) SendPicMsg(wxid, picpath, diyfilename string) (err error) {
  35. resp, err := h.Client.R().SetBody(&SendPicMsgReq{
  36. Wxid: wxid,
  37. Picpath: picpath,
  38. Diyfilename: diyfilename,
  39. }).Post("http://" + h.ServerIp + ":" + h.WxPort + "/SendPicMsg")
  40. if err != nil {
  41. return
  42. }
  43. if !resp.IsSuccessState() {
  44. err = fmt.Errorf("SendPicMsg failed with status code %d", resp.StatusCode)
  45. return
  46. }
  47. return
  48. }
  49. // 发送微信图片(本地测试)
  50. func (h *Hook) SendPicMsgLocal(wxid, picpath string) (err error) {
  51. resp, err := h.Client.R().SetBody(&SendPicMsgLocalReq{
  52. Wxid: wxid,
  53. Picpath: picpath,
  54. }).Post("http://" + h.ServerIp + ":" + h.WxPort + "/SendPicMsg")
  55. if err != nil {
  56. return
  57. }
  58. if !resp.IsSuccessState() {
  59. err = fmt.Errorf("SendPicMsgLocal failed with status code %d", resp.StatusCode)
  60. return
  61. }
  62. return
  63. }