php自动加载文件

<?php

namespace app\admin\service\grpc;

class Grpc
{

    public function __construct()
    {
        spl_autoload_register('app\admin\service\grpc\Grpc::autoload');
    }

    public function index($data)
    {

        //用于连接 服务端
        $client = new \GmRPC\XuexitestClient('101.132.154.98:19051', [
            'credentials' => \Grpc\ChannelCredentials::createInsecure()
        ]);

        if (empty($data['type'])) {
            return  false;
        }

        try {
            switch ($data['type']) {
                case 1://添加房卡
                    $request = new \GmRPC\RoomCard();
                    $request->setUid($data['uid']);
                    $request->setCards($data['coin']);
                    $get = $client->addCard($request)->wait();
                    break;
                case 2://添加滚动屏公告
                    $request = new \GmRPC\ScrollMsg();
                    $request->setMsgs($data['msg']);
                    $get = $client->notice($request)->wait();
                    break;
                case 3: //踢单个玩家
                    $request = new \GmRPC\QuitGame();
                    $request->setGameId($data['gameId']);
                    $get = $client->QuitGame($request)->wait();
                    break;
                case 4: //踢所有人下线
                    $request = new \GmRPC\QuitAllGame();
                    $request->setMsg($data['msg']);
                    $get = $client->SayTest($request)->wait();
                    break;
                case 5: //踢所有人下线
                    $userList = [];
                    $request = new \GmRPC\OnlineUsers();
                    $get = $client->onLine($request)->wait();
                    list($reply, $status) = $get;
                    $data = $reply->getUsers();
                    foreach ($data as $key=>$value){
                        $arr['uid'] = $value->getUid();
                        $arr['gameId'] = $value->getGameId();
                        $arr['nickName'] = $value->getNickName();
                        $arr['deskName'] = $value->getDeskName();
                        $arr['gameType'] = $value->getGameType();
                        $arr['ip'] = $value->getIp();
                        $userList[]=$arr;
                    }
                    return $userList;
                    break;
            }
            list($reply, $status) = $get;
            return $status;
        } catch (Exception $e) {
            throw new Exception($e->getMessage(), 100);
        }
    }


    public function getUser($reply){
        $data = $reply->getUsers();
        foreach ($data as $key=>$value){
            echo $value->getUid().'-';
        }
    }

    public function autoload($class)
    {
        $path = APP_PATH . 'admin/service/grpc/';
        $filename1 =$path.$class.'.php';
        $filename1 = str_replace('\\', '/', $filename1);
         if (is_file($filename1)) {
             require_once $filename1;
         }
    }
}






  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值