diff --git a/application/database.php b/application/database.php index 4a48ccc..c52d5f1 100644 --- a/application/database.php +++ b/application/database.php @@ -12,11 +12,11 @@ return [ // 数据库名 'database' => 'customerservice', // 用户名 - 'username' => 'customerservice', + 'username' => 'root', // 密码 - 'password' => 'ExXLFhBBpFx5M4XA', + 'password' => 'root', // 端口 - 'hostport' => '3306', + 'hostport' => '3307', // 连接dsn 'dsn' => '', // 数据库连接参数 diff --git a/extend/game/GameSrvApi.php b/extend/game/GameSrvApi.php new file mode 100644 index 0000000..4ed36c8 --- /dev/null +++ b/extend/game/GameSrvApi.php @@ -0,0 +1,91 @@ +host =config('game_host'); + } + + /** + * post请求 + * @param $action + * @param $params + * @param bool $json_decode + * @return string|\stdClass + */ + public function doPost($action, $params, $json_decode = true) + { + $client = new Client([ + 'timeout' => 30 + ]); + + $json = json_encode($params); + + list($microsecond, $time) = explode(' ', microtime()); //' '中间是一个空格 + $ts = floor((floatval($microsecond) + floatval($time)) * 1000); + $sign = md5(implode(';', ['5a7553560c9cf51c105678f3', '/' . $action, $json, $ts])); + $query = sprintf("ts=%s&sign=%s", $ts, $sign); + $fullUrl = $this->host . '/' . $action . '?' . $query; + Log::record('fullUrl:' . $fullUrl); + Log::record('json:' . $json); + $resBody = null; + try { + $res = $client->post($fullUrl, ['body' => $json]); + if ($res) { + if ($res->getStatusCode() == 200) { + $resBody = $res->getBody()->getContents(); + if ($json_decode) { + return json_decode($resBody, true); + } + } else { + Log::record('response status code = ' . $res->getStatusCode()); + //exception('游服status不通',404); + } + } else { + Log::record('client request null'); + //exception('游服client不通',404); + } + } catch (\Exception $e) { + Log::record('游服'.$e->getMessage()); + //exception('游服不通',404); + } + return $resBody; + } + + /** + * 用户详情 + * + * """Param"": { + * ""ID"":323, //用户id + * }" + * + * + * "{ + * ""State"": 1, + * ""ErrMes"":"""", + * ""Data"": { + * } + * }" + * + * @param $params + * @return \stdClass|string + */ + public static function PlayerData($params) + { + return (new self)->doPost('api/Player/PlayerData', ['Param' => $params]); + } +} \ No newline at end of file