|
@@ -2,7 +2,7 @@ package wechat
|
|
|
|
|
|
import (
|
|
import (
|
|
"context"
|
|
"context"
|
|
- "encoding/json"
|
|
|
|
|
|
+ "fmt"
|
|
"github.com/imroc/req/v3"
|
|
"github.com/imroc/req/v3"
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
"strconv"
|
|
"strconv"
|
|
@@ -32,16 +32,13 @@ func SyncAllWx(svcCtx *svc.ServiceContext) {
|
|
|
|
|
|
// 遍历微信列表
|
|
// 遍历微信列表
|
|
for _, account := range result.Data {
|
|
for _, account := range result.Data {
|
|
- if account.Wechatid == "" {
|
|
|
|
|
|
+ if account.Wechatid == nil || *account.Wechatid == "" {
|
|
continue
|
|
continue
|
|
}
|
|
}
|
|
wxinfo, err := svcCtx.DB.Wx.Query().
|
|
wxinfo, err := svcCtx.DB.Wx.Query().
|
|
Where(
|
|
Where(
|
|
wx.And(
|
|
wx.And(
|
|
- wx.Or(
|
|
|
|
- wx.WxidEQ(account.Wechatid),
|
|
|
|
- wx.PortEQ(account.Deviceid),
|
|
|
|
- ),
|
|
|
|
|
|
+ wx.WxidEQ(*account.Wechatid),
|
|
wx.CtypeEQ(1),
|
|
wx.CtypeEQ(1),
|
|
),
|
|
),
|
|
).
|
|
).
|
|
@@ -52,66 +49,73 @@ func SyncAllWx(svcCtx *svc.ServiceContext) {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
var status uint8
|
|
var status uint8
|
|
- if account.Isonline == 0 {
|
|
|
|
|
|
+ logx.Info(fmt.Printf("*account.Isonline: %d\n", *account.Isonline))
|
|
|
|
+ if *account.Isonline == 0 {
|
|
status = 1
|
|
status = 1
|
|
} else {
|
|
} else {
|
|
status = 0
|
|
status = 0
|
|
}
|
|
}
|
|
|
|
+
|
|
if wxinfo != nil {
|
|
if wxinfo != nil {
|
|
|
|
+ logx.Info(fmt.Printf("wxinfo is not nil, account: %s\n", *account.Wechatid))
|
|
|
|
+ logx.Info(fmt.Printf("wxinfo is not nil, account: %s\n", *account.Wechatnick))
|
|
err = svcCtx.DB.Wx.UpdateOneID(wxinfo.ID).
|
|
err = svcCtx.DB.Wx.UpdateOneID(wxinfo.ID).
|
|
SetServerID(0).
|
|
SetServerID(0).
|
|
- SetPort(account.Deviceid).
|
|
|
|
|
|
+ SetPort(*account.Deviceid).
|
|
SetProcessID(strconv.FormatInt(account.Cid, 10)).
|
|
SetProcessID(strconv.FormatInt(account.Cid, 10)).
|
|
- SetAccount(account.Wechatno).
|
|
|
|
- SetNickname(account.Wechatnick).
|
|
|
|
- SetHeadBig(account.Avatar).
|
|
|
|
|
|
+ SetNotNilAccount(account.Wechatno).
|
|
|
|
+ SetNotNilNickname(account.Wechatnick).
|
|
|
|
+ SetNotNilHeadBig(account.Avatar).
|
|
SetStatus(status).
|
|
SetStatus(status).
|
|
Exec(context.TODO())
|
|
Exec(context.TODO())
|
|
-
|
|
|
|
if err != nil {
|
|
if err != nil {
|
|
logx.Error("syncWx: ", err)
|
|
logx.Error("syncWx: ", err)
|
|
- return
|
|
|
|
|
|
+ continue
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
- logx.Debug("wxinfo is nil")
|
|
|
|
|
|
+ logx.Error(fmt.Printf("wxinfo is nil, account: %+v\n", account))
|
|
_, err := svcCtx.DB.Wx.Create().
|
|
_, err := svcCtx.DB.Wx.Create().
|
|
SetServerID(0).
|
|
SetServerID(0).
|
|
- SetPort(account.Deviceid).
|
|
|
|
|
|
+ SetPort(*account.Deviceid).
|
|
SetProcessID(strconv.FormatInt(account.Cid, 10)).
|
|
SetProcessID(strconv.FormatInt(account.Cid, 10)).
|
|
- SetWxid(account.Wechatid).
|
|
|
|
- SetAccount(account.Wechatno).
|
|
|
|
- SetHeadBig(account.Avatar).
|
|
|
|
- SetNickname(account.Wechatnick).
|
|
|
|
|
|
+ SetWxid(*account.Wechatid).
|
|
|
|
+ SetNotNilAccount(account.Wechatno).
|
|
|
|
+ SetNotNilHeadBig(account.Avatar).
|
|
|
|
+ SetNotNilNickname(account.Wechatnick).
|
|
SetStatus(status).
|
|
SetStatus(status).
|
|
SetAllowList([]string{}).SetBlockList([]string{}).SetGroupAllowList([]string{}).SetGroupBlockList([]string{}).
|
|
SetAllowList([]string{}).SetBlockList([]string{}).SetGroupAllowList([]string{}).SetGroupBlockList([]string{}).
|
|
Save(context.TODO())
|
|
Save(context.TODO())
|
|
if err != nil {
|
|
if err != nil {
|
|
logx.Error("syncWx: ", err)
|
|
logx.Error("syncWx: ", err)
|
|
- return
|
|
|
|
|
|
+ continue
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- data := map[string]interface{}{
|
|
|
|
- "MsgType": "TriggerFriendPushTask",
|
|
|
|
- "Content": map[string]interface{}{
|
|
|
|
- "WeChatId": account.Wechatid,
|
|
|
|
- },
|
|
|
|
- }
|
|
|
|
- jsonStr, err := json.Marshal(data)
|
|
|
|
- err = svcCtx.WechatWs["default"].SendMsg([]byte(jsonStr))
|
|
|
|
- if err != nil {
|
|
|
|
- logx.Error("syncWx: ", err)
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- dataChatroom := map[string]interface{}{
|
|
|
|
- "MsgType": "TriggerChatroomPushTask",
|
|
|
|
- "Content": map[string]interface{}{
|
|
|
|
- "WeChatId": account.Wechatid,
|
|
|
|
- "Flag": 1,
|
|
|
|
- },
|
|
|
|
- }
|
|
|
|
- jsonStrChatroom, err := json.Marshal(dataChatroom)
|
|
|
|
- err = svcCtx.WechatWs["default"].SendMsg([]byte(jsonStrChatroom))
|
|
|
|
|
|
+ //data := map[string]interface{}{
|
|
|
|
+ // "MsgType": "TriggerFriendPushTask",
|
|
|
|
+ // "Content": map[string]interface{}{
|
|
|
|
+ // "WeChatId": *account.Wechatid,
|
|
|
|
+ // },
|
|
|
|
+ //}
|
|
|
|
+ //jsonStr, err := json.Marshal(data)
|
|
|
|
+ //err = svcCtx.WechatWs["default"].SendMsg([]byte(jsonStr))
|
|
|
|
+ //if err != nil {
|
|
|
|
+ // logx.Error("syncWx: ", err)
|
|
|
|
+ // continue
|
|
|
|
+ //}
|
|
|
|
+ //
|
|
|
|
+ //dataChatroom := map[string]interface{}{
|
|
|
|
+ // "MsgType": "TriggerChatroomPushTask",
|
|
|
|
+ // "Content": map[string]interface{}{
|
|
|
|
+ // "WeChatId": *account.Wechatid,
|
|
|
|
+ // "Flag": 1,
|
|
|
|
+ // },
|
|
|
|
+ //}
|
|
|
|
+ //jsonStrChatroom, err := json.Marshal(dataChatroom)
|
|
|
|
+ //err = svcCtx.WechatWs["default"].SendMsg([]byte(jsonStrChatroom))
|
|
|
|
+ //if err != nil {
|
|
|
|
+ // logx.Error("syncWx: ", err)
|
|
|
|
+ // continue
|
|
|
|
+ //}
|
|
}
|
|
}
|
|
}
|
|
}
|