예제 #1
0
function authenticateClient($clientId, $clientSecret)
{
    // Receive access token via oAuth
    if (extension_loaded('curl')) {
        $header[] = 'Authorization: OAuth Content-Type: application/x-www-form-urlencoded';
        $ibCurl = curl_init();
        curl_setopt($ibCurl, CURLOPT_HEADER, false);
        curl_setopt($ibCurl, CURLOPT_HTTPHEADER, $header);
        curl_setopt($ibCurl, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ibCurl, CURLOPT_SSL_VERIFYHOST, 2);
        curl_setopt($ibCurl, CURLOPT_URL, PS_ITEMBASE_SERVER_OAUTH);
        curl_setopt($ibCurl, CURLOPT_POST, true);
        curl_setopt($ibCurl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ibCurl, CURLOPT_POSTFIELDS, array('client_id' => $clientId, 'client_secret' => $clientSecret, 'response_type' => 'token', 'grant_type' => 'client_credentials'));
        $jsonResponse = curl_exec($ibCurl);
        if ($jsonResponse === FALSE) {
            itembaseErrorHandler(0, curl_error($ibCurl), __FILE__, __LINE__ - 1);
        }
        curl_close($ibCurl);
    } else {
        $opts = array('http' => array('ignore_errors' => true));
        $context = stream_context_create($opts);
        $jsonResponse = file_get_contents(PS_ITEMBASE_SERVER_OAUTH . '?client_id=' . $clientId . '&client_secret=' . $clientSecret . '&response_type=token&grant_type=client_credentials', false, $context);
        if ($jsonResponse === FALSE) {
            itembaseErrorHandler(0, 'file_get_contents', __FILE__, __LINE__ - 1);
        }
    }
    return $jsonResponse;
}
예제 #2
0
 /**
  * JSON encode
  * 
  * @param mixed $data
  * @return string
  */
 private function jsonEncode($data)
 {
     if (function_exists('json_encode')) {
         $result = json_encode($data);
         if (is_callable('json_last_error')) {
             if (json_last_error() != JSON_ERROR_NONE) {
                 itembaseErrorHandler(0, 'json_encode error ' . json_last_error(), __FILE__, __LINE__ - 1);
             }
         }
     } else {
         include_once rtrim(_PS_MODULE_DIR_, '/') . '/itembase/json.php';
         $json = new Services_JSON(SERVICES_JSON_SUPPRESS_ERRORS);
         $result = $json->encode($data);
     }
     return $result;
 }