[attach]2323[/attach]
?
我下載好了,沒(méi)composer install之前,能找到,發(fā)不出去消息。install之后,就報(bào)找不到class了,哪位大佬幫幫忙呀
把類文件手動(dòng)require進(jìn)去
老哥,現(xiàn)在類不報(bào)錯(cuò)了,但是發(fā)不出去消息,客戶端直接發(fā)能行,幫忙看看唄,千恩萬(wàn)謝。
<?php
namespace app\admin\controller;
require_once env('root_path') . 'vendor/workerman/gatewayclient/Gateway.php';
use app\admin\model\Friend;
use think\Controller;
use GatewayClient\Gateway;
use think\Request;
use app\admin\validate\Index as IndexValidata;
use think\Response;
use think\facade\Session;
class Index extends Controller
{
public function index()
{
$arr = ['id'=>1,'name'=>'老趙','url'=>'images/head/1.jpg'];
Session::set('user',$arr);
$friend = Friend::with(['user'=>function($query){
$query->field('id,username,url,autograph');
}])->where('user_id',1)->field('friend_id')->select();
$friend_array=$friend->toArray();
$record = [];
if(!empty($friend_array)){
$route = '../../../public/static/record/'.$friend_array[0]['friend_id'].'.text';
if(file_exists($route)){
$f= fopen($route,'\n\r');
while (!feof($f))
{
for ($i = 0; $i < 10 && !feof($f); $i++) {
$record[] = fgets($f);
}
}
fclose($f);
}
}
$this->assign('record',$record);
$this->assign('user',$arr);
$this->assign('friend',$friend);
return $this->fetch();
}
/**
* 聊天id:client_id和user_id做綁定
*
* @param Request $request
* @param client_id 聊天id
* @return Response
*/
public function bindUid(Request $request): Response
{
$validata = new IndexValidata();
if(!$validata->scene('client_id')->check($request->post())){
return output(1,$validata->getError());
};
Gateway::$registerAddress = '127.0.0.1:1238';
#聊天id:client_id和user_id做綁定
Gateway::bindUid($request->post('client_id'),Session::get('user.id'));
return output(0);
}
/**
* 發(fā)消息
* @param Request $request
* @param id 發(fā)給誰(shuí)
* @param text 發(fā)什么
* @return Response
*/
public function sendMessage(Request $request): Response
{
$validata = new IndexValidata();
if(!$validata->scene('sendMessage')->check($request->post())){
return output(1,$validata->getError());
};
#消息內(nèi)容
$arr = [
'error' => 0,
'type' => 'reply',
'data' => [
'message' => $request->post("text")
]
];
#連接服務(wù)
Gateway::$registerAddress = '127.0.0.1:1238';
#給uid發(fā)
Gateway::sendToAll(json($arr));
return output(0);
}