工作台-消息群发

This commit is contained in:
wong
2025-08-06 18:02:03 +08:00
parent 7a2553940c
commit 94c484dbe4
5 changed files with 215 additions and 188 deletions

View File

@@ -14,7 +14,6 @@ use app\api\model\WechatMomentsModel as WechatMoments;
use think\facade\Cache;
class WebSocketController extends BaseController
{
protected $authorized;
@@ -519,7 +518,6 @@ class WebSocketController extends BaseController
->value('id');
$dataToSave = [
'commentList' => json_encode($moment['commentList'] ?? [], 256),
'createTime' => $moment['createTime'] ?? 0,
@@ -668,9 +666,8 @@ class WebSocketController extends BaseController
// 接收响应
$response = $this->client->receive();
$message = json_decode($response, true);
if (!empty($message)) {
return json_encode(['code'=>500,'msg'=>'信息发送成功','data'=>$message]);
return json_encode(['code' => 200, 'msg' => '信息发送成功', 'data' => $message]);
}
}
@@ -678,14 +675,8 @@ class WebSocketController extends BaseController
* 发送群消息
* @return \think\response\Json
*/
public function sendCommunity()
public function sendCommunity($dataArray = [])
{
if ($this->request->isPost()) {
$data = $this->request->post();
if (empty($data)) {
return json_encode(['code'=>400,'msg'=>'参数缺失']);
}
$dataArray = $data;
if (!is_array($dataArray)) {
return json_encode(['code' => 400, 'msg' => '数据格式错误']);
}
@@ -705,11 +696,10 @@ class WebSocketController extends BaseController
return json_encode(['code' => 400, 'msg' => '群id不能为空']);
}
$msg = '消息成功发送';
$message = [];
try {
//消息拼接 msgType(1:文本 3:图片 43:视频 47:动图表情包 49:小程序)
$result = [
$params = [
"cmdType" => "CmdSendMessage",
"content" => htmlspecialchars_decode($dataArray['content']),
"msgSubType" => 0,
@@ -720,23 +710,20 @@ class WebSocketController extends BaseController
"wechatFriendId" => 0,
];
$result = json_encode($result);
$this->client->send($result);
$message = $this->client->receive();
//关闭WS链接
$this->client->close();
//Log::write('WS群消息发送');
//Log::write($message);
$message = json_decode($message, 1);
// 发送请求
$this->client->send(json_encode($params));
// 接收响应
$response = $this->client->receive();
$message = json_decode($response, true);
if (!empty($message)) {
return json_encode(['code' => 200, 'msg' => '信息发送成功', 'data' => $message]);
}
} catch (\Exception $e) {
$msg = $e->getMessage();
return json_encode(['code' => 400, 'msg' => $msg, 'data' => $message]);
}
return json_encode(['code'=>200,'msg'=>$msg,'data'=>$message]);
} else {
return json_encode(['code'=>400,'msg'=>'非法请求']);
//return errorJson('非法请求');
}
}
/**
@@ -800,7 +787,6 @@ class WebSocketController extends BaseController
}
/**
* 邀请好友入群
* @param array $data 请求参数

View File

@@ -32,5 +32,6 @@ return [
'sync:wechatData' => 'app\command\SyncWechatDataToCkbTask', // 同步微信数据到存客宝
'sync:allFriends' => 'app\command\SyncAllFriendsCommand', // 同步所有在线好友
'workbench:trafficDistribute' => 'app\command\WorkbenchTrafficDistributeCommand', // 工作台流量分发任务
'workbench:groupPush' => 'app\command\WorkbenchGroupPushCommand', // 工作台群组同步任务
'switch:friends' => 'app\command\SwitchFriendsCommand',
];

View File

@@ -94,6 +94,9 @@ Route::group('v1/', function () {
Route::get('device-labels', 'app\cunkebao\controller\WorkbenchController@getDeviceLabels'); // 获取设备微信好友标签统计
Route::get('group-list', 'app\cunkebao\controller\WorkbenchController@getGroupList'); // 获取群列表
Route::get('account-list', 'app\cunkebao\controller\WorkbenchController@getAccountList'); // 获取账号列表
Route::get('getJdSocialMedia', 'app\cunkebao\controller\WorkbenchController@getJdSocialMedia'); // 获取京东联盟导购媒体
Route::get('getJdPromotionSite', 'app\cunkebao\controller\WorkbenchController@getJdPromotionSite'); // 获取京东联盟广告位
});
// 内容库相关

View File

@@ -1500,4 +1500,38 @@ class WorkbenchController extends Controller
}
/**
* 获取京东联盟导购媒体
* @return \think\response\Json
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getJdSocialMedia()
{
$data = Db::name('jd_social_media')->order('id DESC')->select();
return json(['code' => 200, 'msg' => '获取成功', 'data' => $data]);
}
/**
* 获取京东联盟广告位
* @return \think\response\Json
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getJdPromotionSite()
{
$id = $this->request->param('id', '');
if (empty($id)) {
return json(['code' => 500, 'msg' => '参数缺失']);
}
$data = Db::name('jd_promotion_site')->where('jdSocialMediaId',$id)->order('id DESC')->select();
return json(['code' => 200, 'msg' => '获取成功', 'data' => $data]);
}
}

View File

@@ -57,6 +57,9 @@
# 同步微信数据到存客宝
0 9 * * * cd /www/wwwroot/mckb_quwanzhi_com/Server && php think sync:wechatData >> /www/wwwroot/mckb_quwanzhi_com/Server/runtime/log/sync_wechat_data.log 2>&1
# 工作台群发消息
0 2 * * * cd /www/wwwroot/mckb_quwanzhi_com/Server && php think workbench:groupPush >> /www/wwwroot/mckb_quwanzhi_com/Server/runtime/log/workbench_groupPush.log 2>&1
# 工作台流量分发
0 9 * * * cd /www/wwwroot/mckb_quwanzhi_com/Server && php think workbench:trafficDistribute >> /www/wwwroot/mckb_quwanzhi_com/Server/runtime/log/traffic_distribute.log 2>&1