【问题标题】:BigCommerce API PHP - Authorizing?BigCommerce API PHP - 授权?
【发布时间】:2016-08-04 13:30:46
【问题描述】:

我正在使用 BigCommerce API 的 PHP 库。我似乎遇到了麻烦并不断​​收到错误消息。我不确定这是授权问题还是我遗漏了什么。

我正在使用 XAMPP 并安装 composer 以及我需要的 BigCommerce PHP 包。我遵循了这个指南:https://github.com/bigcommerce/bigcommerce-api-php

这就是我的代码的样子(凭证 X 已失效):

<?php

require "vendor/autoload.php";

use Bigcommerce\Api\Client as Bigcommerce;


    Bigcommerce::configure(array(

        'store_url' => 'http://store-XXXXXXXX.mybigcommerce.com',
        'username' => 'admin',
        'api_key' => 'xxxxxxxxxxxxxxxxxxxxxxxxx'
    ));


$ping = Bigcommerce::getTime();


if (!$ping ) {
$error = Bigcommerce::getLastError();
print_r($error);
}   


?>

返回:Array ( [0] =&gt; stdClass Object ( [status] =&gt; 400 [message] =&gt; The connection is not secure. API requests must be made via HTTPS. ) )

我想知道它是否与我在配置中使用的“store_url”有关。所以我将其更改为前端 URL(我的商店的真实名称),然后我收到此消息:

Fatal error: Uncaught exception 'Bigcommerce\Api\NetworkError' with message 'SSL certificate problem: self signed certificate in certificate chain' in C:\xampp\htdocs\test\PSC_BigC\bigcommerce-api-php-master\src\vendor\bigcommerce\api\src\Bigcommerce\Api\Connection.php:274 Stack trace: #0 C:\xampp\htdocs\test\PSC_BigC\bigcommerce-api-php-master\src\vendor\bigcommerce\api\src\Bigcommerce\Api\Connection.php(368): Bigcommerce\Api\Connection->handleResponse() #1 C:\xampp\htdocs\test\PSC_BigC\bigcommerce-api-php-master\src\vendor\bigcommerce\api\src\Bigcommerce\Api\Client.php(423): Bigcommerce\Api\Connection->get('https://psc-dev...') #2 C:\xampp\htdocs\test\PSC_BigC\bigcommerce-api-php-master\src\test.php(19): Bigcommerce\Api\Client::getTime() #3 {main} thrown in C:\xampp\htdocs\test\PSC_BigC\bigcommerce-api-php-master\src\vendor\bigcommerce\api\src\Bigcommerce\Api\Connection.php on line 274

【问题讨论】:

  • 错误说明很清楚,您需要为“store_url”使用 https。继续使用“.mybigcommerce.com”网址,但使用 https。
  • 正确。请参阅下面的答案。

标签: php api ssl xampp bigcommerce


【解决方案1】:

这是因为您使用的是自签名证书。

您需要将 Bigcommerce 配置为忽略该警告。

Bigcommerce::verifyPeer(false);

这有效地关闭了它似乎正在使用的 cURL 客户端中的检查。

【讨论】:

    【解决方案2】:

    错误状态:“API 请求必须通过 HTTPS 进行。”

    将您的商店 URL 更改为“https://store-XXXXXXXX.mybigcommerce.com”,因为它是安全的。

    文档中的示例(商店 URL 需要是 HTTPS)。

    https://github.com/bigcommerce/bigcommerce-api-php

    Bigcommerce::configure(array(
        'store_url' => 'https://store.mybigcommerce.com',
        'username'  => 'admin',
        'api_key'   => 'd81aada4xc34xx3e18f0xxxx7f36ca'
    ));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-09-21
      • 2016-02-20
      • 1970-01-01
      • 2020-09-23
      • 2015-12-02
      • 1970-01-01
      • 2012-12-24
      • 1970-01-01
      相关资源
      最近更新 更多