2016-06-21 10 views
2

私はWooCommerce-REST-API-Client-Library-v2を使用しており、簡単なget orders呼び出しを試みています。 httpでテストサーバーへの接続を確立することに問題はありませんが、httpsを使用してプロダクションサーバーに接続しようとすると、無効なJSONが応答でエラーを返しました。セキュリティで保護されたチェックアウトは、Woocommerce設定で有効になっています。私は資格情報をbase64_encodingの有無にかかわらず試しました。誰かが私に間違っていることを教えてもらえますか、またはWooCommerce-REST-API-Client-Library-v2を使用してHTTPSで認証するための適切なフォーマットの例を提供できますか?ここに私のコードです。ありがとう!HTTPS(Basic Auth)を使用してWoocommerce APIで認証する方法

$consumer_key = base64_encode('ck_removed'); // Add your own Consumer Key here 
$consumer_secret = base64_encode('cs_removed'); // Add your own Consumer Secret here 
$store_url = 'https://removed.co.uk'; // Add the home URL to the store you want to connect to here 
$is_ssl= TRUE; 

try { 
    $client = new WC_API_Client($consumer_key, $consumer_secret, $store_url); 
    // Get WC Orders Request 
    $orders=$client->orders->get(); 
    $orders=$orders['orders']; 
} catch (WC_API_Client_Exception $e) { 
    echo $e->getMessage() . PHP_EOL; 
    echo $e->getCode() . PHP_EOL; 
    if ($e instanceof WC_API_Client_HTTP_Exception) { 
     print_r($e->get_request()); 
     print_r($e->get_response()); 
    } 
} 

答えて

1

HTTPステータスコード:301 Moved Permanentlyがある場合、到達しようとしているエンドポイントはSSL/TLS対応ではありません。したがって、ホストをHTTPSからHTTPに変更すると、完了します。ただし、エンドポイントがSSL/TLS対応の場合は、鍵ベース(公開鍵、秘密鍵)基本認証を使用できます。 SSL/TLS対応のエンドポイントでは、OAuthは機能しません。がんばろう!

$options = array(
    'debug'   => true, 
    'return_as_array' => false, 
    'validate_url' => false, 
    'timeout'   => 30, 
    'ssl_verify'  => false 
); 

try { 
    $client = new WC_API_Client($http_store_url, $consumer_key $consumer_secret, $options); 
    $orders=$client->orders->get(); 
    print_r($orders); 
} catch (WC_API_Client_Exception $e) { 
    echo $e->getMessage() . PHP_EOL; 
    echo $e->getCode() . PHP_EOL; 
    if ($e instanceof WC_API_Client_HTTP_Exception) { 
     print_r($e->get_request()); 
     print_r($e->get_response()); 
    } 
} 
関連する問題