diff --git a/Applications/YourApp/Events.php b/Applications/YourApp/Events.php index d6e2696..2b9f97b 100644 --- a/Applications/YourApp/Events.php +++ b/Applications/YourApp/Events.php @@ -19,6 +19,7 @@ */ //declare(ticks=1); +require_once __DIR__ . '/../../config.php'; use \GatewayWorker\Lib\Gateway; @@ -59,6 +60,31 @@ class Events */ public static function onClose($client_id) { + global $config; + if (!!$config['close']) self::post($config['close'], ['client' => $client_id]); + } + public static function post($url, $data, $type = 'json') + { + $curl = curl_init(); + curl_setopt($curl, CURLOPT_URL, $url); + curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); + curl_setopt($curl, CURLOPT_POST, true); + if ($type === 'data') { + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($curl, CURLOPT_POSTFIELDS, $data); + curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); + } + if ($type === 'json') { + $data_string = json_encode($data, JSON_UNESCAPED_UNICODE); + curl_setopt($curl, CURLOPT_HTTPHEADER, [ + 'Content-Type: application/json; charset=utf-8', + 'Content-Length: ' . strlen($data_string) + ]); + curl_setopt($curl, CURLOPT_POSTFIELDS, $data_string); + } + $r = curl_exec($curl); + curl_close($curl); + return $r; } } diff --git a/config.php b/config.php index b93da68..158714a 100644 --- a/config.php +++ b/config.php @@ -1,7 +1,13 @@ '鹿和开发套件', // 服务名称 - 'port' => 3282, // 服务端口 - 'register' => 3238, // 服务注册端口 - 'start' => 3900, // 内部通讯起始端口 + // 服务名称 + 'name' => '鹿和开发套件', + // 服务端口 + 'port' => 3282, + // 服务注册端口 + 'register' => 3238, + // 内部通讯起始端口 + 'start' => 3900, + // 退出接口 + 'close' => '', ]; \ No newline at end of file