/** API client */ class CyPlusApiClient { private $endpoint; private $secretToken; public function __construct($endpoint, $secretToken) { $this->endpoint = $endpoint; $this->secretToken = $secretToken; } // of constructor public function getLoginInfoByUserName($userName, $region) { $json = $this->sendRequest([ 'version' => 2, 'method' => "getLoginInfoByUserName", 'token' => $this->secretToken, 'userName' => $userName, 'region' => $region, ]); /* if (!json_decode($json)) { throw \Exception("Not a JSON response"); return "Not a JSON response"; } */ return $json; } protected function sendRequest($data) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $this->endpoint); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); if (curl_errno($ch)) { throw new \Exception(curl_error($ch)); } else { curl_close($ch); return $response; } } // of sendRequest() } // of class // end of file