GatewayClient,报找不到类

li460620829

[attach]2323[/attach]
 

3074 2 0
2个回答

li460620829

我下载好了,没composer install之前,能找到,发不出去消息。install之后,就报找不到class了,哪位大佬帮帮忙呀

  • 暂无评论
xiuwang

把类文件手动require进去

  • li460620829 2019-07-25

    老哥,现在类不报错了,但是发不出去消息,客户端直接发能行,帮忙看看呗,千恩万谢。
    <?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);
    }
    
    /**
     * 发消息
     * @param Request $request
     * @param id      发给谁
     * @param text    发什么
     * @return Response
     */
    public function sendMessage(Request $request): Response
    {
        $validata = new IndexValidata();
        if(!$validata->scene('sendMessage')->check($request->post())){
            return output(1,$validata->getError());
        };
        #消息内容
        $arr = [
            'error' => 0,
            'type'  => 'reply',
            'data'  => [
                'message'   => $request->post("text")
            ]
        ];
        #连接服务
        Gateway::$registerAddress = '127.0.0.1:1238';
        #给uid发
        Gateway::sendToAll(json($arr));
        return output(0);
    }
年代过于久远,无法发表回答
×
🔝