|
@@ -4,11 +4,11 @@ import (
|
|
|
"context"
|
|
|
"encoding/json"
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
|
+ "strconv"
|
|
|
"time"
|
|
|
"wechat-api/ent/addwechatfriendlog"
|
|
|
"wechat-api/internal/pkg/wechat_ws"
|
|
|
"wechat-api/internal/svc"
|
|
|
- "wechat-api/workphone"
|
|
|
)
|
|
|
|
|
|
type TaskResultNoticeHandler struct {
|
|
@@ -23,14 +23,24 @@ func NewTaskResultNoticeHandler(svcCtx *svc.ServiceContext) *TaskResultNoticeHan
|
|
|
|
|
|
// Handle 实现 MessageHandlerStrategy 接口
|
|
|
func (f *TaskResultNoticeHandler) Handle(ctx context.Context, msg *wechat_ws.MsgJsonObject, svcCtx *svc.ServiceContext) error {
|
|
|
- message := workphone.TaskResultNoticeMessage{}
|
|
|
- err := json.Unmarshal([]byte(msg.Message), &message)
|
|
|
- logx.Infof("msg.Message 的内容是:%s", msg.Message)
|
|
|
- if err != nil {
|
|
|
- logx.Errorf("Unmarshal.fail")
|
|
|
+
|
|
|
+ var messageTask TaskResultNoticeMessage
|
|
|
+ if err := json.Unmarshal([]byte(msg.Message), &messageTask); err != nil {
|
|
|
+ logx.Errorf("预处理 JSON 失败: %v", err)
|
|
|
return err
|
|
|
}
|
|
|
- if message.TaskType != workphone.EnumMsgType_AddFriendsTask {
|
|
|
+ // 如果 TaskId 是字符串,就转换成数字
|
|
|
+ var taskIdInt int64
|
|
|
+ if messageTask.TaskId != nil {
|
|
|
+ var err error
|
|
|
+ taskIdInt, err = strconv.ParseInt(*messageTask.TaskId, 10, 64)
|
|
|
+ if err != nil {
|
|
|
+ logx.Errorf("Unmarshal.fail")
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if messageTask.TaskType != "AddFriendsTask" {
|
|
|
logx.Infof("不是添加好友任务的回执")
|
|
|
return nil
|
|
|
}
|
|
@@ -40,12 +50,12 @@ func (f *TaskResultNoticeHandler) Handle(ctx context.Context, msg *wechat_ws.Msg
|
|
|
return err
|
|
|
}
|
|
|
update := svcCtx.DB.AddWechatFriendLog.Update().
|
|
|
- Where(addwechatfriendlog.OwnerWxIDEQ(message.WeChatId)).
|
|
|
- Where(addwechatfriendlog.TaskIDEQ(message.TaskId)).
|
|
|
+ Where(addwechatfriendlog.OwnerWxIDEQ(*messageTask.WeChatId)).
|
|
|
+ Where(addwechatfriendlog.TaskIDEQ(taskIdInt)).
|
|
|
//SetFindResult(m).
|
|
|
SetAddResult(m).
|
|
|
SetUpdatedAt(time.Now().Unix())
|
|
|
- if message.Success {
|
|
|
+ if *messageTask.Success {
|
|
|
update.SetIsCanAdd(2)
|
|
|
}
|
|
|
if _, err := update.Save(ctx); err != nil {
|
|
@@ -54,3 +64,12 @@ func (f *TaskResultNoticeHandler) Handle(ctx context.Context, msg *wechat_ws.Msg
|
|
|
}
|
|
|
return nil
|
|
|
}
|
|
|
+
|
|
|
+type TaskResultNoticeMessage struct {
|
|
|
+ Success *bool `json:"Success,omitempty"` // 指针,便于判断字段是否存在
|
|
|
+ Code *int32 `json:"Code,omitempty"` // 错误码
|
|
|
+ ErrMsg *string `json:"ErrMsg,omitempty"` // 错误描述
|
|
|
+ TaskId *string `json:"TaskId,omitempty"` // 任务ID(因前面问题,保持 string 类型)
|
|
|
+ TaskType string `json:"TaskType,omitempty"` // 枚举类型
|
|
|
+ WeChatId *string `json:"WeChatId,omitempty"` // 微信号
|
|
|
+}
|