首先,我将向您展示我的完整代码以了解该问题
这是具有消费者密钥和文件checkout.ts的秘密的woocommerce api auth
this.WooCommerce = WC({
url:"http://localhost/wordpress/",
consumerKey:"ck_429c9a4521b73420e6c6d57179ab2b19350fbdb8",
consumerSecret:"cs_b9aaa8b11d15a6132abca0a8b5ca324fcfa76f87",
});
这是函数placeOrder()的checkout.ts文件的命令的post方法。
this.WooCommerce.postAsync("orders", orderData).then ((data) => {
//console.log(JSON.parse(data.body).order);
let response = (JSON.parse(data.body).order);
this.alertCtrl.create({
title: "Order Placed Successfully",
message: "Your order has been placed successfully. Your order number is " + response.order_number,
buttons: [{
text: "OK",
handler: () => {
this.navCtrl.push(HomePage);
}
}]
}).present();
})
这是html文件checkout.html
<ion-item>
<ion-label>First Name</ion-label>
<ion-input type="text" [(ngModel)]="newOrder.billing_address.first_name"></ion-input>
</ion-item>
....
<button ion-button block color="danger" (click)="placeOrder()">Place Order</button>
当我点击下订单按钮时,它会显示给我这个错误
我在一些论坛中搜索这个问题,他们建议我在消费者密钥和秘密之后添加一些代码给woocommerce api auth
verifySsl: false,
queryStringAuth: true
还要将一些代码添加到.htaccess文件中
RewriteCond %{HTTP:Authorization} ^(.)
RewriteRule ^(.) - [E=HTTP_AUTHORIZATION:%1]
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
我在控制台中仍有相同的问题,这是网络结果qazxsw poi
所以根据他们的var WooCommerce = new WooCommerceAPI({
url: 'http://example.com', // Your store URL
consumerKey: 'consumer_key', // Your consumer key
consumerSecret: 'consumer_secret', // Your consumer secret
wpAPI: true, // Enable the WP REST API integration
version: 'wc/v2' // WooCommerce WP REST API version
});
你使用OAUTH 1.0授权策略,所以上面是基本的WooCommerce对象签名和属性。