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());
}
}