无法将VendHQ(POS)连接到WooCommerce(WP)

我花了很多天试图解决这个问题,这似乎是一个常见问题。我读过许多关于同一问题的其他文章。我已经尝试了所有可以找到的解决方案,但是仍然得到相同的结果-无法成功将客户的VendHQ(POS)连接到我的WooCommerce商店(WordPress 5.2.4,PHP 7.2)。我已经联系VendHQ寻求帮助,但是他们的解决方案以及其他解决方案都无法正常工作。

我尝试过什么:

  1. 按照VendHQ的说明进行操作,并创建我的WooCommerce REST API密钥,并将其放入VendHQ连接设置中。这给出了最初的错误“ woocommerce_rest_cannot_view,抱歉,您无法列出资源,401”

  2. 我几次将以下代码添加到我的.htaccess文件中,但遗憾的是未解决该问题:

    # BEGIN WordPress
    SetEnvIf Authorization "(.)" HTTP_AUTHORIZATION=$1
    RewriteEngine On
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
    RewriteBase /
    RewriteRule ^index.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    # END WordPress
  1. 我按照建议几次将apache httpd.conf文件修改为AllowOverride All,而不是默认值None,再次没有成功。我将以下代码添加到了我的apache文件中: “ /etc/apache2/conf.d/includes/pre_main_global.conf”
    <Directory "/var/www/">
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>

我不了解Apache和操作指令,因为我知道它有多危险。但是,这一次出现了几次,似乎很简单。更新.conf文件并重新启动Apache服务器后,仍然无法建立连接。

  1. 最后,我在.htaccess文件中添加了更多代码:
    Header always set access-Control-Max-Age 1728000
    Header always set access-control-allow-origin: "*"
    Header always set access-Control-Allow-Methods: "GET,POST,OPTIONS,DELETE,PUT"
    Header always set access-Control-Allow-Headers: "DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,C$"
    Header always set access-Control-Allow-Credentials true
    Header always set access-control-allow-origin: "https://my_client_shop.com/"

所有这些都到位之后,我仍然无法连接两个系统,但是现在出现了一个新错误:

"We are unable to connect your WooCommerce store. Your website does not allow connections with Authorization Headers in the Vend API."

我认为最后的更改将解决此问题。有人看到过“授权标头”错误的问题吗?

我在Chrome浏览器中测试了WC API密钥:

https://my_client_shop.com/wp-json/wc/v2/system_status?consumer_key=ck_389f08cda9f8a802b366b1de8cb562cba95e462c&consumer_secret=cs_65fcd907905f9d8c64b38a7dd60de4f034526ff2 

它显示了json文件的详细信息。没有键,我再次收到“无法列出401”错误。因此,据此我认为这些键实际上是有效的。

看来我们离我们越来越近了,但我没主意了。

最后,如果有帮助的话,我客户的商店网站会位于一个多站点上。

因此,我希望其他人能够仔细研究所有这些内容,并能够找到一个可行的解决方案,并可以共享它:)或指出我可能错过或遇到的错误。非常感谢您提出的所有建议。

lingcy 回答:无法将VendHQ(POS)连接到WooCommerce(WP)

我正在使用的开发人员最终使用以下代码处理WooCommerce文件:

private function perform_basic_authentication() {

$this->auth_method = 'basic_auth';
$consumer_key = 'ck_PUT_YOUR_WC_REST_API_KEY';
$consumer_secret = 'cs_PUT_YOUR_WC_REST_API_KEY';

// If the $_GET parameters are present,use those first.
if ( ! empty( $_GET['consumer_key'] ) && ! empty( $_GET['consumer_secret'] ) ) { // WPCS: CSRF ok.
$consumer_key = $_GET['consumer_key']; // WPCS: CSRF ok,sanitization ok.
$consumer_secret = $_GET['consumer_secret']; // WPCS: CSRF ok,sanitization ok.
}

// If the above is not present,we will do full basic auth.
if ( ! $consumer_key && ! empty( $_SERVER['PHP_AUTH_USER'] ) && ! empty( $_SERVER['PHP_AUTH_PW'] ) ) {
$consumer_key = $_SERVER['PHP_AUTH_USER']; // WPCS: CSRF ok,sanitization ok.
$consumer_secret = $_SERVER['PHP_AUTH_PW']; // WPCS: CSRF ok,sanitization ok.
}

// Stop if don't have any key.
if ( ! $consumer_key || ! $consumer_secret ) {
return false;
}

// Get user data.
$this->user = $this->get_user_data_by_consumer_key( $consumer_key );
if ( empty( $this->user ) ) {
return false;
}

// Validate user secret.
if ( ! hash_equals( $this->user->consumer_secret,$consumer_secret ) ) { // @codingStandardsIgnoreLine
$this->set_error( new WP_Error( 'woocommerce_rest_authentication_error',__( 'Consumer secret is invalid.','woocommerce' ),array( 'status' => 401 ) ) );

return false;
}

return $this->user->user_id;

}

这确实奏效,但是它可以帮助您进行大量挖掘。不幸的是,它位于WC Core文件中,因此更新WC将使它无法正常运行。我正在等待开发人员找到将其移至子主题的方法。

,

这对我有用。

我将此添加到了 .htaccess 文件中。可以通过FTP访问此文件到您的Wordpress服务器。

CGIPassAuth on

我从这里得到的:allowing-authorization-header-in-apache

本文链接:https://www.f2er.com/3142171.html

大家都在问