Beispiel #1
0
 public static function sendOAuthBody($method, $endpoint, $oauth_consumer_key, $oauth_consumer_secret, $content_type, $body, $more_headers = false, $signature = false)
 {
     $hmac_method = new OAuthSignatureMethod_HMAC_SHA1();
     $hash = base64_encode(sha1($body, TRUE));
     if ($signature == "HMAC-SHA256") {
         $hmac_method = new OAuthSignatureMethod_HMAC_SHA256();
         $hash = base64_encode(hash('sha256', $body, TRUE));
     }
     $parms = array('oauth_body_hash' => $hash);
     $test_token = '';
     $test_consumer = new OAuthConsumer($oauth_consumer_key, $oauth_consumer_secret, NULL);
     $acc_req = OAuthRequest::from_consumer_and_token($test_consumer, $test_token, $method, $endpoint, $parms);
     $acc_req->sign_request($hmac_method, $test_consumer, $test_token);
     // Pass this back up "out of band" for debugging
     global $LastOAuthBodyBaseString;
     $LastOAuthBodyBaseString = $acc_req->get_signature_base_string();
     $header = $acc_req->to_header();
     $header = $header . "\r\nContent-Type: " . $content_type . "\r\n";
     if ($more_headers === false) {
         $more_headers = array();
     }
     foreach ($more_headers as $more) {
         $header = $header . $more . "\r\n";
     }
     return Net::doBody($endpoint, $method, $body, $header);
 }