自动点赞优化
This commit is contained in:
@@ -48,7 +48,7 @@ export function BasicSettings({ formData, onChange, onNext }: BasicSettingsProps
|
||||
}
|
||||
|
||||
const incrementFriendMaxLikes = () => {
|
||||
onChange({ friendMaxLikes: Math.min(formData.friendMaxLikes + 1, 10) })
|
||||
onChange({ friendMaxLikes: Math.min(formData.friendMaxLikes + 1, 20) })
|
||||
}
|
||||
|
||||
const decrementFriendMaxLikes = () => {
|
||||
@@ -163,7 +163,7 @@ export function BasicSettings({ formData, onChange, onNext }: BasicSettingsProps
|
||||
id="friend-max-likes"
|
||||
type="number"
|
||||
min={1}
|
||||
max={10}
|
||||
max={20}
|
||||
value={formData.friendMaxLikes}
|
||||
onChange={(e) => onChange({ friendMaxLikes: Number.parseInt(e.target.value) || 1 })}
|
||||
className="h-12 rounded-none border-x-0 border-gray-200 text-center"
|
||||
|
||||
@@ -519,6 +519,60 @@ class WebSocketController extends BaseController
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 修改好友标签
|
||||
* @param array $data 请求参数
|
||||
* @return string JSON响应
|
||||
*/
|
||||
public function modifyFriendLabel($data = [])
|
||||
{
|
||||
// 获取请求参数
|
||||
$wechatFriendId = !empty($data['wechatFriendId']) ? $data['wechatFriendId'] : 0;
|
||||
$wechatAccountId = !empty($data['wechatAccountId']) ? $data['wechatAccountId'] : '';
|
||||
$labels = !empty($data['labels']) ? $data['labels'] : [];
|
||||
|
||||
// 验证必要参数
|
||||
if (empty($wechatFriendId)) {
|
||||
return json_encode(['code' => 400, 'msg' => '好友ID不能为空']);
|
||||
}
|
||||
|
||||
if (empty($wechatAccountId)) {
|
||||
return json_encode(['code' => 400, 'msg' => '微信账号ID不能为空']);
|
||||
}
|
||||
|
||||
if (empty($labels)) {
|
||||
return json_encode(['code' => 400, 'msg' => '标签不能为空']);
|
||||
}
|
||||
|
||||
try {
|
||||
// 构建请求参数
|
||||
$params = [
|
||||
"cmdType" => "CmdModifyFriendLabel",
|
||||
"labels" => $labels,
|
||||
"seq" => time(),
|
||||
"wechatAccountId" => $wechatAccountId,
|
||||
"wechatFriendId" => $wechatFriendId,
|
||||
];
|
||||
|
||||
// 发送请求并获取响应
|
||||
$message = $this->sendMessage($params);
|
||||
|
||||
// 记录日志
|
||||
Log::info('修改好友标签:' . json_encode($params, 256));
|
||||
Log::info('修改好友标签结果:' . json_encode($message, 256));
|
||||
|
||||
// 返回成功响应
|
||||
return json_encode(['code' => 200, 'msg' => '修改标签成功', 'data' => $message]);
|
||||
} catch (\Exception $e) {
|
||||
// 记录错误日志
|
||||
Log::error('修改好友标签失败:' . $e->getMessage());
|
||||
|
||||
// 返回错误响应
|
||||
return json_encode(['code' => 500, 'msg' => '修改标签失败:' . $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
/************************************
|
||||
* 消息发送相关功能
|
||||
************************************/
|
||||
|
||||
@@ -16,7 +16,7 @@ class WechatFriendController extends BaseController
|
||||
* @param bool $isInner 是否为任务调用
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function getlist($pageIndex = '', $pageSize = '', $preFriendId = '', $isInner = false,$isDel = '')
|
||||
public function getlist($data = [], $isInner = false,$isDel = '')
|
||||
{
|
||||
// 获取授权token
|
||||
$authorization = trim($this->request->header('authorization', $this->authorization));
|
||||
@@ -28,6 +28,13 @@ class WechatFriendController extends BaseController
|
||||
}
|
||||
}
|
||||
|
||||
$pageIndex = !empty($data['pageIndex']) ? $data['pageIndex'] : '';
|
||||
$pageSize = !empty($data['pageSize']) ? $data['pageSize'] : '';
|
||||
$preFriendId = !empty($data['preFriendId']) ? $data['preFriendId'] : '';
|
||||
$friendKeyword = !empty($data['friendKeyword']) ? $data['friendKeyword'] : '';
|
||||
$wechatAccountKeyword = !empty($data['wechatAccountKeyword']) ? $data['wechatAccountKeyword'] : '';
|
||||
|
||||
|
||||
try {
|
||||
// 初始化isUpdate标志为false
|
||||
$isUpdate = false;
|
||||
@@ -57,7 +64,8 @@ class WechatFriendController extends BaseController
|
||||
'pageIndex' => !empty($pageIndex) ? $pageIndex : input('pageIndex', 0),
|
||||
'pageSize' => !empty($pageSize) ? $pageSize : input('pageSize', 20),
|
||||
'preFriendId' => !empty($preFriendId) ? $preFriendId : input('preFriendId', ''),
|
||||
'wechatAccountKeyword' => input('wechatAccountKeyword', '')
|
||||
'friendKeyword' => !empty($friendKeyword) ? $friendKeyword : input('friendKeyword', ''),
|
||||
'wechatAccountKeyword' => !empty($wechatAccountKeyword) ? $wechatAccountKeyword : input('wechatAccountKeyword', '')
|
||||
];
|
||||
|
||||
// 设置请求头
|
||||
|
||||
@@ -57,6 +57,7 @@ Route::group('v1/', function () {
|
||||
Route::post('copy', 'app\cunkebao\controller\WorkbenchController@copy'); // 拷贝工作台
|
||||
Route::get('detail', 'app\cunkebao\controller\WorkbenchController@detail'); // 获取工作台详情
|
||||
Route::post('update', 'app\cunkebao\controller\WorkbenchController@update'); // 更新工作台
|
||||
Route::get('like-records', 'app\cunkebao\controller\WorkbenchController@getLikeRecords'); // 获取点赞记录列表
|
||||
});
|
||||
|
||||
// 内容库相关
|
||||
|
||||
@@ -639,4 +639,88 @@ class WorkbenchController extends Controller
|
||||
return json(['code' => 500, 'msg' => '拷贝失败:' . $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取点赞记录列表
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function getLikeRecords()
|
||||
{
|
||||
$page = $this->request->param('page', 1);
|
||||
$limit = $this->request->param('limit', 10);
|
||||
$workbenchId = $this->request->param('workbenchId', 0);
|
||||
$startTime = $this->request->param('startTime', '');
|
||||
$endTime = $this->request->param('endTime', '');
|
||||
|
||||
$where = [
|
||||
['wali.workbenchId', '=', $workbenchId]
|
||||
];
|
||||
|
||||
// 添加时间筛选
|
||||
if (!empty($startTime) && !empty($endTime)) {
|
||||
$where[] = ['wali.createTime', 'between', [
|
||||
strtotime($startTime . ' 00:00:00'),
|
||||
strtotime($endTime . ' 23:59:59')
|
||||
]];
|
||||
} elseif (!empty($startTime)) {
|
||||
$where[] = ['wali.createTime', '>=', strtotime($startTime . ' 00:00:00')];
|
||||
} elseif (!empty($endTime)) {
|
||||
$where[] = ['wali.createTime', '<=', strtotime($endTime . ' 23:59:59')];
|
||||
}
|
||||
|
||||
// 查询点赞记录
|
||||
$list = Db::name('workbench_auto_like_item')->alias('wali')
|
||||
->join(['s2_wechat_moments' => 'wm'], 'wm.snsId = wali.snsId', 'left')
|
||||
->join(['s2_wechat_account' => 'wa'], 'wa.id = wali.wechatAccountId', 'left')
|
||||
->join(['s2_wechat_friend' => 'wf'], 'wf.id = wm.wechatFriendId', 'left')
|
||||
->field([
|
||||
'wali.id',
|
||||
'wali.workbenchId',
|
||||
'wali.momentsId',
|
||||
'wali.snsId',
|
||||
'wali.wechatAccountId',
|
||||
'wali.wechatFriendId',
|
||||
'wali.createTime as likeTime',
|
||||
'wm.content',
|
||||
'wm.resUrls',
|
||||
'wm.createTime as momentTime',
|
||||
'wm.userName',
|
||||
'wa.nickName as operatorName',
|
||||
'wf.nickName as friendName',
|
||||
])
|
||||
->where($where)
|
||||
->order('wali.createTime', 'desc')
|
||||
->page($page, $limit)
|
||||
->select();
|
||||
|
||||
// 处理数据
|
||||
foreach ($list as &$item) {
|
||||
// 处理时间格式
|
||||
$item['likeTime'] = date('Y-m-d H:i:s', $item['likeTime']);
|
||||
$item['momentTime'] = !empty($item['momentTime']) ? date('Y-m-d H:i:s', $item['momentTime']) : '';
|
||||
|
||||
// 处理资源链接
|
||||
if (!empty($item['resUrls'])) {
|
||||
$item['resUrls'] = json_decode($item['resUrls'], true);
|
||||
} else {
|
||||
$item['resUrls'] = [];
|
||||
}
|
||||
}
|
||||
|
||||
// 获取总记录数
|
||||
$total = Db::name('workbench_auto_like_item')->alias('wali')
|
||||
->where($where)
|
||||
->count();
|
||||
|
||||
return json([
|
||||
'code' => 200,
|
||||
'msg' => '获取成功',
|
||||
'data' => [
|
||||
'list' => $list,
|
||||
'total' => $total,
|
||||
'page' => $page,
|
||||
'limit' => $limit
|
||||
]
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -73,7 +73,11 @@ class WechatFriendJob
|
||||
]);
|
||||
|
||||
// 调用微信好友列表获取方法,传入isDel参数
|
||||
$result = $wechatFriendController->getlist($pageIndex, $pageSize, $preFriendId, true, $isDel);
|
||||
$result = $wechatFriendController->getlist([
|
||||
'pageIndex' => $pageIndex,
|
||||
'pageSize' => $pageSize,
|
||||
'preFriendId' => $preFriendId,
|
||||
], true, $isDel);
|
||||
$response = json_decode($result, true);
|
||||
|
||||
// 判断是否成功
|
||||
|
||||
@@ -16,6 +16,7 @@ use app\cunkebao\model\WorkbenchGroupCreate;
|
||||
use think\Db;
|
||||
use app\api\controller\WebSocketController;
|
||||
use app\api\controller\AutomaticAssign;
|
||||
use app\api\controller\WechatFriendController;
|
||||
|
||||
class WorkbenchJob
|
||||
{
|
||||
@@ -113,7 +114,7 @@ class WorkbenchJob
|
||||
}
|
||||
|
||||
/************************************
|
||||
* 工作台处理主流程
|
||||
* 工作台处理核心逻辑
|
||||
************************************/
|
||||
|
||||
/**
|
||||
@@ -229,37 +230,52 @@ class WorkbenchJob
|
||||
if (!$this->validateAutoLikeConfig($workbench, $config)) {
|
||||
return;
|
||||
}
|
||||
//验证是否达到点赞次数上限
|
||||
|
||||
// 验证是否达到点赞次数上限
|
||||
$likeCount = $this->getTodayLikeCount($workbench, $config);
|
||||
if ($likeCount >= $config['maxLikes']) {
|
||||
Log::info("工作台 {$workbench->id} 点赞次数已达上限");
|
||||
return;
|
||||
}
|
||||
//验证是否在点赞时间范围内
|
||||
|
||||
// 验证是否在点赞时间范围内
|
||||
if (!$this->isWithinLikeTimeRange($config)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
$page = 1;
|
||||
$pageSize = 100;
|
||||
$friendList = $this->getFriendList($config,$page,$pageSize);
|
||||
foreach ($friendList as $friend) {
|
||||
//验证是否达到好友点赞次数上限
|
||||
$friendMaxLikes = Db::name('workbench_auto_like_item')
|
||||
->where('workbenchId', $workbench->id)
|
||||
->where('wechatFriendId', $friend['friendId'])
|
||||
->count();
|
||||
// 处理分页获取好友列表
|
||||
$this->processAllFriends($workbench, $config);
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理所有好友分页
|
||||
* @param Workbench $workbench
|
||||
* @param WorkbenchAutoLike $config
|
||||
* @param int $page 当前页码
|
||||
* @param int $pageSize 每页大小
|
||||
*/
|
||||
protected function processAllFriends($workbench, $config, $page = 1, $pageSize = 100)
|
||||
{
|
||||
$friendList = $this->getFriendList($config, $page, $pageSize);
|
||||
if (empty($friendList)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if($friendMaxLikes < $config['friendMaxLikes']){
|
||||
foreach ($friendList as $friend) {
|
||||
// 验证是否达到好友点赞次数上限
|
||||
$friendMaxLikes = Db::name('workbench_auto_like_item')
|
||||
->where('workbenchId', $workbench->id)
|
||||
->where('wechatFriendId', $friend['friendId'])
|
||||
->count();
|
||||
if ($friendMaxLikes < $config['friendMaxLikes']) {
|
||||
$this->processFriendMoments($workbench, $config, $friend);
|
||||
}
|
||||
}
|
||||
|
||||
if(count($friendList) == $pageSize){
|
||||
$this->getFriendList($config, $page + 1, $pageSize);
|
||||
// 如果当前页数据量等于页大小,说明可能还有更多数据,继续处理下一页
|
||||
if (count($friendList) == $pageSize) {
|
||||
$this->processAllFriends($workbench, $config, $page + 1, $pageSize);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -328,56 +344,72 @@ class WorkbenchJob
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
|
||||
print_r($friend);
|
||||
exit;
|
||||
|
||||
//执行切换好友命令
|
||||
// 执行切换好友命令
|
||||
$automaticAssign = new AutomaticAssign();
|
||||
$automaticAssign->allotWechatFriend(['wechatFriendId' => $friend['friendId'],'toAccountId' => $toAccountId],true);
|
||||
//执行采集朋友圈命令
|
||||
$webSocket = new WebSocketController(['userName' => $username,'password' => $password,'accountId' => $toAccountId]);
|
||||
$webSocket->getMoments(['wechatFriendId' => $friend['friendId'],'wechatAccountId' => $friend['wechatAccountId']]);
|
||||
$automaticAssign->allotWechatFriend(['wechatFriendId' => $friend['friendId'], 'toAccountId' => $toAccountId], true);
|
||||
|
||||
// 执行采集朋友圈命令
|
||||
$webSocket = new WebSocketController(['userName' => $username, 'password' => $password, 'accountId' => $toAccountId]);
|
||||
$webSocket->getMoments(['wechatFriendId' => $friend['friendId'], 'wechatAccountId' => $friend['wechatAccountId']]);
|
||||
|
||||
|
||||
//查询未点赞的朋友圈
|
||||
$moments = $this->getUnlikedMoments($friend['friendId']);
|
||||
|
||||
print_r($moments);
|
||||
exit;
|
||||
|
||||
|
||||
if (empty($moments)) {
|
||||
//处理完毕切换
|
||||
Log::info("好友 {$friend['friendId']} 没有需要点赞的朋友圈");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
foreach ($moments as $moment) {
|
||||
//点赞朋友圈
|
||||
$this->likeMoment($workbench, $config, $friend, $moment, $webSocket);
|
||||
// 查询未点赞的朋友圈
|
||||
$moments = $this->getUnlikedMoments($friend['friendId']);
|
||||
if (empty($moments)) {
|
||||
Log::info("好友 {$friend['friendId']} 没有需要点赞的朋友圈");
|
||||
// 处理完毕切换回原账号
|
||||
$automaticAssign->allotWechatFriend(['wechatFriendId' => $friend['friendId'], 'toAccountId' => $friend['accountId']], true);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
//处理完毕切换
|
||||
$automaticAssign->allotWechatFriend(['wechatFriendId' => $friend['friendId'],'toAccountId' => $friend['accountId']],true);
|
||||
|
||||
foreach ($moments as $moment) {
|
||||
// 点赞朋友圈
|
||||
$this->likeMoment($workbench, $config, $friend, $moment, $webSocket);
|
||||
|
||||
if(!empty($config['enableFriendTags']) && !empty($config['friendTags'])){
|
||||
// 修改好友标签
|
||||
$labels = $this->getFriendLabels($friend);
|
||||
$labels[] = $config['friendTags'];
|
||||
$webSocket->modifyFriendLabel(['wechatFriendId' => $friend['friendId'], 'wechatAccountId' => $toAccountId, 'labels' => $labels]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 每个好友只点赞一条朋友圈,然后退出
|
||||
break;
|
||||
}
|
||||
|
||||
// 处理完毕切换回原账号
|
||||
$automaticAssign->allotWechatFriend(['wechatFriendId' => $friend['friendId'], 'toAccountId' => $friend['accountId']], true);
|
||||
} catch (\Exception $e) {
|
||||
//处理完毕切换
|
||||
$automaticAssign->allotWechatFriend(['wechatFriendId' => $friend['friendId'],'toAccountId' => $friend['accountId']],true);
|
||||
|
||||
return [
|
||||
'status' => 'error',
|
||||
'message' => '采集过程发生错误: ' . $e->getMessage()
|
||||
];
|
||||
// 异常情况下也要确保切换回原账号
|
||||
$automaticAssign->allotWechatFriend(['wechatFriendId' => $friend['friendId'], 'toAccountId' => $friend['accountId']], true);
|
||||
|
||||
Log::error("处理好友 {$friend['friendId']} 朋友圈失败: " . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取好友标签
|
||||
* @param int $friendId
|
||||
* @return array
|
||||
*/
|
||||
protected function getFriendLabels($friend)
|
||||
{
|
||||
// 获取好友标签
|
||||
$wechatFriendController = new WechatFriendController();
|
||||
$result = $wechatFriendController->getlist([ 'friendKeyword' => $friend['wechatId'],'wechatAccountKeyword' => $friend['wechatAccountWechatId']],true);
|
||||
$result = json_decode($result, true);
|
||||
$labels = [];
|
||||
if(!empty($result['data'])){
|
||||
foreach($result['data'] as $item){
|
||||
$labels = array_merge($labels, $item['labels']);
|
||||
}
|
||||
}
|
||||
return $labels;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 获取未点赞的朋友圈
|
||||
* @param int $friendId
|
||||
@@ -404,7 +436,6 @@ class WorkbenchJob
|
||||
* @param WorkbenchAutoLike $config
|
||||
* @param array $friend
|
||||
* @param array $moment
|
||||
|
||||
* @param WebSocketController $webSocket
|
||||
*/
|
||||
protected function likeMoment($workbench, $config, $friend, $moment, $webSocket)
|
||||
@@ -419,7 +450,11 @@ class WorkbenchJob
|
||||
|
||||
if ($result['code'] == 200) {
|
||||
$this->recordLike($workbench, $moment, $friend);
|
||||
// sleep($config['interval']);
|
||||
|
||||
// 添加间隔时间
|
||||
if (!empty($config['interval'])) {
|
||||
sleep($config['interval']);
|
||||
}
|
||||
} else {
|
||||
Log::error("工作台 {$workbench->id} 点赞失败: " . ($result['msg'] ?? '未知错误'));
|
||||
}
|
||||
@@ -498,10 +533,12 @@ class WorkbenchJob
|
||||
|
||||
/**
|
||||
* 获取好友列表
|
||||
* @param string $friendsJson
|
||||
* @param WorkbenchAutoLike $config 配置
|
||||
* @param int $page 页码
|
||||
* @param int $pageSize 每页大小
|
||||
* @return array
|
||||
*/
|
||||
protected function getFriendList($config,$page = 1,$pageSize = 100)
|
||||
protected function getFriendList($config, $page = 1, $pageSize = 100)
|
||||
{
|
||||
$friends = json_decode($config['friends'], true);
|
||||
$devices = json_decode($config['devices'], true);
|
||||
@@ -521,14 +558,19 @@ class WorkbenchJob
|
||||
'ca.userName',
|
||||
'wf.id as friendId',
|
||||
'wf.wechatId',
|
||||
'wf.wechatAccountId'
|
||||
'wf.wechatAccountId',
|
||||
'wa.wechatId as wechatAccountWechatId'
|
||||
]);
|
||||
|
||||
if(!empty($friends) && is_array($friends) && count($friends) > 0){
|
||||
$list = $list->whereIn('wf.id', $friends);
|
||||
}
|
||||
|
||||
$list = $list->group('wf.wechatId')->order('wf.id DESC')->page($page,$pageSize)->select();
|
||||
return $list;
|
||||
if (!empty($friends) && is_array($friends) && count($friends) > 0) {
|
||||
$list = $list->whereIn('wf.id', $friends);
|
||||
}
|
||||
|
||||
$list = $list->group('wf.wechatId')
|
||||
->order('wf.id DESC')
|
||||
->page($page, $pageSize)
|
||||
->select();
|
||||
|
||||
return $list;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user