代码同步提交

This commit is contained in:
wong
2025-09-16 09:57:06 +08:00
parent 2b3c41ce36
commit f577dbdd70
11 changed files with 236 additions and 36 deletions

View File

@@ -33,7 +33,11 @@ class WebSocketController extends BaseController
*/
public function __construct($userData = [])
{
parent::__construct();
//parent::__construct();
if (empty($userData)){
return;
}
$this->initConnection($userData);
}
@@ -51,7 +55,6 @@ class WebSocketController extends BaseController
// 检查缓存中是否存在有效的token
$cacheKey = 'websocket_token_' . $userData['userName'];
$cachedToken = Cache::get($cacheKey);
if ($cachedToken) {
$this->authorized = $cachedToken;
$this->accountId = $userData['accountId'];
@@ -61,9 +64,11 @@ class WebSocketController extends BaseController
'username' => $userData['userName'],
'password' => $userData['password']
];
// 调用登录接口获取token
$headerData = ['client:kefu-client'];
$headerData[] = 'verifysessionid:3f21df29-6d8a-4980-ae8a-bf15ef17955f';
$headerData[] = 'verifycode:0k3g';
$header = setHeader($headerData, '', 'plain');
$result = requestCurl('https://kf.quwanzhi.com:9991/token', $params, 'POST', $header);
$result_array = handleApiResponse($result);
@@ -877,8 +882,10 @@ class WebSocketController extends BaseController
"seq" => time(),
"wechatAccountId" => $data['wechatAccountId'],
"chatroomName" => $data['chatroomName'],
"wechatFriendIds" => $data['wechatFriendIds']
// "wechatFriendIds" => $data['wechatFriendIds']
"wechatFriendIds" => [17453051,17453058]
];
// 记录请求日志
Log::info('创建群聊请求:' . json_encode($params, 256));

View File

@@ -249,4 +249,43 @@ class WechatController extends BaseController
WechatAccountModel::create($data);
}
}
public function chatroomCreate($data = [])
{
$authorization = $this->authorization;
if (empty($authorization)) {
return json_encode(['code' => 500, 'msg' => '缺少授权信息']);
}
try {
// 设置请求头
$headerData = ['Client:system'];
$header = setHeader($headerData, $authorization,'json');
$params = [
"chatroomOperateType" => 7,
"extra" => "{chatroomName:{$data['chatroomName']}}",
"wechatAccountId" => $data['wechatAccountId'],
"wechatChatroomId" => 0,
"wechatFriendIds" => $data['wechatFriendIds']
];
// 发送请求获取状态信息
$result = requestCurl($this->baseUrl . 'api/WechatChatroom/chatroomOperate', $params, 'POST', $header,'json');
$response = handleApiResponse($result);
if (!empty($response)) {
return json_encode(['code' => 500, 'msg' =>$response]);
}else{
return json_encode(['code' => 200, 'msg' =>'成功']);
}
} catch (\Exception $e) {
if (empty($authorization)) { // 只有作为独立API调用时才返回
return json_encode(['code' => 500, 'msg' => '获取失败:' . $e->getMessage()]);
}
}
}
}