代码优化

This commit is contained in:
wong
2025-07-11 16:47:50 +08:00
parent 9193004c54
commit 66c6455a44
3 changed files with 13 additions and 40 deletions

View File

@@ -916,17 +916,14 @@ class ContentLibraryController extends Controller
//执行切换好友命令 //执行切换好友命令
$automaticAssign = new AutomaticAssign(); $automaticAssign = new AutomaticAssign();
$automaticAssign->allotWechatFriend(['wechatFriendId' => $friend['id'],'toAccountId' => $toAccountId],true); $automaticAssign->allotWechatFriend(['wechatFriendId' => $friend['id'],'toAccountId' => $toAccountId],true);
//存入缓存
$friendData['friendId'] = $friend['id'];
artificialAllotWechatFriend($friendData);
//执行采集朋友圈命令 //执行采集朋友圈命令
$webSocket = new WebSocketController(['userName' => $username,'password' => $password,'accountId' => $toAccountId]); $webSocket = new WebSocketController(['userName' => $username,'password' => $password,'accountId' => $toAccountId]);
$webSocket->getMoments(['wechatFriendId' => $friend['id'],'wechatAccountId' => $friend['wechatAccountId']]); $webSocket->getMoments(['wechatFriendId' => $friend['id'],'wechatAccountId' => $friend['wechatAccountId']]);
//采集完毕切换 //采集完毕切换
$res = $automaticAssign->allotWechatFriend(['wechatFriendId' => $friend['id'],'toAccountId' => $friend['accountId']],true); $automaticAssign->allotWechatFriend(['wechatFriendId' => $friend['id'],'toAccountId' => $friend['accountId']],true);
$res = json_decode($res, true);
if($res == '无效路径或登录状态失效'){
$cacheFriend = $friend;
$cacheFriend['friendId'] = $friend['id'];
artificialAllotWechatFriend($friend);
}
} }
@@ -1035,12 +1032,6 @@ class ContentLibraryController extends Controller
]; ];
} catch (\Exception $e) { } catch (\Exception $e) {
$cacheFriend = $friendData;
$cacheFriend['friendId'] = $friend['id'];
artificialAllotWechatFriend($friend);
return [ return [
'status' => 'error', 'status' => 'error',
'message' => '采集过程发生错误: ' . $e->getMessage() 'message' => '采集过程发生错误: ' . $e->getMessage()

View File

@@ -46,26 +46,20 @@ class WechatMomentsJob
// 执行切换好友命令 // 执行切换好友命令
$automaticAssign = new AutomaticAssign(); $automaticAssign = new AutomaticAssign();
$automaticAssign->allotWechatFriend(['wechatFriendId' => $friend['friendId'], 'toAccountId' => $toAccountId], true); $automaticAssign->allotWechatFriend(['wechatFriendId' => $friend['friendId'], 'toAccountId' => $toAccountId], true);
//存入缓存
artificialAllotWechatFriend($friend);
// 执行采集朋友圈命令 // 执行采集朋友圈命令
$webSocket = new WebSocketController(['userName' => $username, 'password' => $password, 'accountId' => $toAccountId]); $webSocket = new WebSocketController(['userName' => $username, 'password' => $password, 'accountId' => $toAccountId]);
$webSocket->getMoments(['wechatFriendId' => $friend['friendId'], 'wechatAccountId' => $friend['wechatAccountId']]); $webSocket->getMoments(['wechatFriendId' => $friend['friendId'], 'wechatAccountId' => $friend['wechatAccountId']]);
// 处理完毕切换回原账号 // 处理完毕切换回原账号
$res = $automaticAssign->allotWechatFriend(['wechatFriendId' => $friend['friendId'], 'toAccountId' => $friend['accountId']], true); $automaticAssign->allotWechatFriend(['wechatFriendId' => $friend['friendId'], 'toAccountId' => $friend['accountId']], true);
$res = json_decode($res, true);
if ($res == '无效路径或登录状态失效'){
artificialAllotWechatFriend($friend);
}
} catch (\Exception $e) { } catch (\Exception $e) {
// 发生异常时也要切换回原账号 // 发生异常时也要切换回原账号
$res = $automaticAssign->allotWechatFriend(['wechatFriendId' => $friend['friendId'], 'toAccountId' => $friend['accountId']], true); $automaticAssign->allotWechatFriend(['wechatFriendId' => $friend['friendId'], 'toAccountId' => $friend['accountId']], true);
$res = json_decode($res, true);
if ($res == '无效路径或登录状态失效'){
artificialAllotWechatFriend($friend);
}
Log::error("采集好友 {$friend['id']} 的朋友圈失败:" . $e->getMessage()); Log::error("采集好友 {$friend['id']} 的朋友圈失败:" . $e->getMessage());
continue; continue;
} }

View File

@@ -219,7 +219,8 @@ class WorkbenchAutoLikeJob
// 执行切换好友命令 // 执行切换好友命令
$automaticAssign = new AutomaticAssign(); $automaticAssign = new AutomaticAssign();
$automaticAssign->allotWechatFriend(['wechatFriendId' => $friend['friendId'], 'toAccountId' => $toAccountId], true); $automaticAssign->allotWechatFriend(['wechatFriendId' => $friend['friendId'], 'toAccountId' => $toAccountId], true);
//存入缓存
artificialAllotWechatFriend($friend);
// 创建WebSocket链接 // 创建WebSocket链接
$webSocket = new WebSocketController(['userName' => $username, 'password' => $password, 'accountId' => $toAccountId]); $webSocket = new WebSocketController(['userName' => $username, 'password' => $password, 'accountId' => $toAccountId]);
@@ -234,12 +235,7 @@ class WorkbenchAutoLikeJob
if (empty($moments) || count($moments) == 0) { if (empty($moments) || count($moments) == 0) {
// 处理完毕切换回原账号 // 处理完毕切换回原账号
$res = $automaticAssign->allotWechatFriend(['wechatFriendId' => $friend['friendId'], 'toAccountId' => $friend['accountId']], true); $automaticAssign->allotWechatFriend(['wechatFriendId' => $friend['friendId'], 'toAccountId' => $friend['accountId']], true);
$res = json_decode($res, true);
if($res == '无效路径或登录状态失效'){
artificialAllotWechatFriend($friend);
}
Log::info("好友 {$friend['friendId']} 没有需要点赞的朋友圈"); Log::info("好友 {$friend['friendId']} 没有需要点赞的朋友圈");
return; return;
} }
@@ -263,19 +259,11 @@ class WorkbenchAutoLikeJob
} }
// 处理完毕切换回原账号 // 处理完毕切换回原账号
$res = $automaticAssign->allotWechatFriend(['wechatFriendId' => $friend['friendId'], 'toAccountId' => $friend['accountId']], true); $automaticAssign->allotWechatFriend(['wechatFriendId' => $friend['friendId'], 'toAccountId' => $friend['accountId']], true);
$res = json_decode($res, true);
if($res == '无效路径或登录状态失效'){
artificialAllotWechatFriend($friend);
}
} catch (\Exception $e) { } catch (\Exception $e) {
// 异常情况下也要确保切换回原账号 // 异常情况下也要确保切换回原账号
$automaticAssign = new AutomaticAssign(); $automaticAssign = new AutomaticAssign();
$res = $automaticAssign->allotWechatFriend(['wechatFriendId' => $friend['friendId'], 'toAccountId' => $friend['accountId']], true); $automaticAssign->allotWechatFriend(['wechatFriendId' => $friend['friendId'], 'toAccountId' => $friend['accountId']], true);
$res = json_decode($res, true);
if($res == '无效路径或登录状态失效'){
artificialAllotWechatFriend($friend);
}
Log::error("处理好友 {$friend['friendId']} 朋友圈失败异常: " . $e->getMessage()); Log::error("处理好友 {$friend['friendId']} 朋友圈失败异常: " . $e->getMessage());
} }
} }