示例#1
0
 /**
  * Execute JSON-RPC Request
  *
  * @param string $method
  * @param array $params
  * @return array
  */
 public function call($method, $params = null)
 {
     $this->clear();
     $request = array('jsonrpc' => '2.0', 'id' => 'a' . uniqid('', true), 'method' => $method);
     if (isset($params)) {
         $request['params'] = $params;
     }
     $json = $this->encoder->encode($request);
     $response = $this->post($json);
     $this->response = $this->encoder->decode($response);
     return $this->response;
 }
示例#2
0
 /**
  * Get JSON request as array
  *
  * @return array
  * @throws Exception
  */
 protected function getJsonRequest()
 {
     if (!$this->isJsonRpc()) {
         throw new Exception('Invalid Json-RPC request');
     }
     // Parse json
     $requestContent = (string) $this->request->getContent();
     $request = $this->encoder->decode($requestContent);
     if (empty($request) || !is_array($request)) {
         throw new Exception('Invalid Json-RPC request (empty)');
     }
     return $request;
 }