main.go 903 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package main
  2. import (
  3. "github.com/zeromicro/go-zero/core/logx"
  4. "net/url"
  5. "wechat-api/internal/pkg/wechat_ws"
  6. )
  7. func msgHandler(msg wechat_ws.MsgJsonObject) error {
  8. logx.Info("当前处理的消息是:", msg)
  9. return nil
  10. }
  11. func main() {
  12. //u := url.URL{Scheme: "ws", Host: "chat.gkscrm.com:13088"}
  13. u := url.URL{Scheme: "ws", Host: "wecom.gkscrm.com:15088"}
  14. logx.Info(u.String())
  15. client, err := wechat_ws.NewWechatWsClient(u.String(), "default")
  16. if err != nil {
  17. return
  18. }
  19. go client.WritePump()
  20. client.SendMsg([]byte(`{
  21. "MsgType": "TalkToFriendTask",
  22. "Content": {
  23. "WxId": "1688856818598875",
  24. "ConvId": "7881302495311662",
  25. "ContentType": "Text",
  26. "Content": "5L2g5aW9",
  27. "TaskId": 17409293978671188
  28. }
  29. }`))
  30. //
  31. //time.Sleep(5)
  32. //
  33. //client.SendMsg([]byte(`{"msgType":"text","message":"二次你好"}`))
  34. client.ReadPump(msgHandler)
  35. }