2
我正在使用WooCommerce-REST-API-Client-Library-v2並試圖進行簡單的獲取訂單調用。我沒有問題通過http建立到我的測試服務器的連接,但是當我嘗試使用https連接到生產服務器時,我在響應中收到無效的JSON返回錯誤。在woocommerce設置中啓用安全結帳。我嘗試過使用和不使用base64_encoding憑證。有人可以告訴我我做錯了什麼,或者提供一個正確格式的示例,使用WooCommerce-REST-API-Client-Library-v2通過HTTPS進行身份驗證。這是我的代碼。謝謝!如何使用HTTPS驗證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());
}
}