使用HTTP Outh 2身份验证和PHP curl的请求不起作用?

时间:2018-06-29 11:00:29

标签: php authentication curl

我已使用PHP CURL和以下代码建立了http请求。

      <?php

$para='{
  "payment_method": "bacs",
  "payment_method_title": "Direct Bank Transfer",
  "set_paid": true,
  "billing": {
    "first_name": "John",
    "last_name": "Doe",
    "address_1": "969 Market",
    "address_2": "",
    "city": "San Francisco",
    "state": "CA",
    "postcode": "94103",
    "country": "US",
    "email": "john.doe@example.com",
    "phone": "(555) 555-5555"
  },
  "shipping": {
    "first_name": "John",
    "last_name": "Doe",
    "address_1": "969 Market",
    "address_2": "",
    "city": "San Francisco",
    "state": "CA",
    "postcode": "94103",
    "country": "US"
  },
  "line_items": [
    {
      "product_id": 13,
      "quantity": 2
    }

  ]

}';

       $process= curl_init('http://xxx');
        $header[] = 'Content-Type: application/json';
                curl_setopt($process, CURLOPT_HEADER, $header);
                curl_setopt($process, CURLOPT_POST, true);
                curl_setopt($process, CURLOPT_POSTFIELDS, urlencode("oauth_consumer_key=xxxxxxfa18148227334d91&
                   oauth_signature_method=HMAC-SHA1&
                   oauth_signature=xxxxx%253D&
                   oauth_timestamp=xxxx&
                   oauth_nonce=xxXbG&
                   oauth_version=2.0"));
                curl_setopt($process, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($process, CURLOPT_POSTFIELDS, $para);
                $return = curl_exec($process);
                print_r($return);
                curl_close($process);
        ?>

出现以下错误,我想使用curl获取woocommerce订单api,这与woocommerce rest api有关,我也在.htaccess中添加了此RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}],但仍然无法正常工作。

  {"code":"woocommerce_rest_cannot_create","message":"Sorry, you are not allowed to create resources.","data":{"status":401}}

请帮助我如何解决此问题?

0 个答案:

没有答案