<?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; } } }
php自动加载文件
最新推荐文章于 2023-06-06 17:52:52 发布