示例#1
0
 /**
  * Prepares URL (and returns it) and POST data (updates it via reference).
  *
  * @param string $controller Kayako controller to call. Null to use default controller defined for object.
  * @param string $method HTTP verb.
  * @param array $parameters List of additional parameters (like object identifiers or search parameters).
  * @param array $data Placeholder for POST/PUT data.
  * @return string
  */
 private function getRequestData($controller, $method, $parameters = array(), &$data = array())
 {
     $salt = mt_rand();
     $signature = base64_encode(hash_hmac('sha256', $salt, $this->config->getSecretKey(), true));
     $parameters_str = '';
     foreach ($parameters as $parameter) {
         $parameters_str .= sprintf("/%s", $parameter);
     }
     if ($this->config->isControllerAsQuery()) {
         $url = sprintf("%s?e=%s%s", $this->config->getBaseURL(), $controller, $parameters_str);
     } else {
         $url = sprintf("%s%s%s", $this->config->getBaseURL(), ltrim($controller, '/'), $parameters_str);
     }
     switch ($method) {
         case self::METHOD_POST:
         case self::METHOD_PUT:
             $data['apikey'] = $this->config->getAPIKey();
             $data['salt'] = $salt;
             $data['signature'] = $signature;
             break;
         case self::METHOD_GET:
         case self::METHOD_DELETE:
             $url .= sprintf("&apikey=%s&salt=%s&signature=%s", $this->config->getAPIKey(), $salt, urlencode($signature));
             break;
     }
     return $url;
 }