我遵循了https://woocommerce.github.io/woocommerce-rest-api-docs/?ruby#authentication-over-http处的WooCommerce文档,并设法使用以下代码获取了签名:https://stackoverflow.com/a/18895255/1851900,并验证了签名。但是,仍然WooCommerce响应未经授权。
要签名的字符串:
GET&http%3A%2F%2F192.168.1.24%2F7ajati%2Fwp-json%2Fwc%2Fv3%2Fproducts&oauth_consumer_key%3Dck_d18c2f252dc5c062fc184ef2481a71c8cf908026%26oauth_nonce%3D4864e0e3-b5d4-430c-ae1a-cbed85438c91%26oauth_timestamp%3D1590797305%26oauth_signature_method%3DHMAC-SHA1
签名(在此处验证:https://www.freeformatter.com/hmac-generator.html):
d3758c59ad97dd7c35ba57709b8bd2e23733138f
HTTP请求(GET)
http://192.168.1.24/7ajati/wp-json/wc/v3/products?oauth_consumer_key=ck_d18c2f252dc5c062fc184ef2481a71c8cf908026&oauth_timestamp=HMAC-SHA1&oauth_nonce=1590797305&oauth_signature_method=4864e0e3-b5d4-430c-ae1a-cbed85438c91&oauth_signature=d3758c59ad97dd7c35ba57709b8bd2e23733138f
响应:
Response{protocol=http/1.1, code=401, message=Unauthorized, url=http://192.168.1.24/7ajati/wp-json/wc/v3/products?oauth_consumer_key=ck_d18c2f252dc5c062fc184ef2481a71c8cf908026&oauth_timestamp=HMAC-SHA1&oauth_nonce=1590797305&oauth_signature_method=4864e0e3-b5d4-430c-ae1a-cbed85438c91&oauth_signature=d3758c59ad97dd7c35ba57709b8bd2e23733138f}