talk_to_friend_task_result_notice.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package MessageHandlers
  2. import (
  3. "context"
  4. "encoding/json"
  5. "fmt"
  6. "github.com/zeromicro/go-zero/core/logx"
  7. "wechat-api/ent/contact"
  8. "wechat-api/internal/pkg/wechat_ws"
  9. "wechat-api/internal/svc"
  10. "wechat-api/workphone"
  11. )
  12. type TalkToFriendTaskResultNoticeHandler struct {
  13. svcCtx *svc.ServiceContext
  14. }
  15. func NewTalkToFriendTaskResultNoticeHandler(svcCtx *svc.ServiceContext) *TalkToFriendTaskResultNoticeHandler {
  16. return &TalkToFriendTaskResultNoticeHandler{
  17. svcCtx: svcCtx,
  18. }
  19. }
  20. type TalkToFriendTaskResultNoticeMessage struct {
  21. Success bool `json:"success"` // 是否成功
  22. Code string `json:"code"` // 错误码 Success = true 忽略
  23. ErrMsg string `json:"errMsg"` // 错误内容描述 Success = true 忽略
  24. WeChatId string `json:"weChatId"` // 执行的微信
  25. FriendId string `json:"friendId"` // 执行的用户对象
  26. MsgId string `json:"msgId"` // 聊天Id
  27. MsgSvrId int64 `json:"msgSvrId"` //
  28. CreateTime int64 `json:"createTime"` // 消息发送时间
  29. }
  30. func (f *TalkToFriendTaskResultNoticeHandler) Handler(msg *wechat_ws.MsgJsonObject) error {
  31. if msg.MsgType == "TalkToFriendTaskResultNotice" {
  32. logx.Info("msg 的内容是:%s", msg)
  33. message := workphone.TalkToFriendTaskResultNoticeMessage{}
  34. err := json.Unmarshal([]byte(msg.Message), &message)
  35. if err != nil {
  36. return err
  37. }
  38. logx.Info("msg.Message 的内容是:%s", message)
  39. friendId, _ := f.svcCtx.Rds.Get(context.TODO(), fmt.Sprintf("MsgId_FriendId:%s", message.MsgId)).Result()
  40. if friendId == "" {
  41. return nil
  42. }
  43. if message.Code == workphone.EnumErrorCode_InternalError {
  44. err = f.svcCtx.DB.Contact.
  45. Update().
  46. Where(contact.WxWxidEQ(message.WeChatId), contact.WxidEQ(friendId)).
  47. SetStatus(2).
  48. Exec(context.TODO())
  49. if err != nil {
  50. return err
  51. }
  52. }
  53. }
  54. return nil
  55. }