Пример #1
0
function sendOAuthBody($method, $endpoint, $oauth_consumer_key, $oauth_consumer_secret, $content_type, $body, $more_headers = false, $more_oauth = false)
{
    $hash = base64_encode(sha1($body, TRUE));
    $parms = array('oauth_body_hash' => $hash);
    if ($more_oauth !== false) {
        $parms = array_merge($more_oauth, $parms);
    }
    $test_token = '';
    $oauth_signature_method = isset($parms['oauth_signature_method']) ? $parms['oauth_signature_method'] : false;
    $hmac_method = new OAuthSignatureMethod_HMAC_SHA1();
    if ($oauth_signature_method == "HMAC-SHA256") {
        $hmac_method = new OAuthSignatureMethod_HMAC_SHA256();
    }
    $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 do_body($endpoint, $method, $body, $header);
}
Пример #2
0
function sendOAuthBody($method, $endpoint, $oauth_consumer_key, $oauth_consumer_secret, $content_type, $body)
{
    $hash = base64_encode(sha1($body, TRUE));
    $parms = array('oauth_body_hash' => $hash);
    $test_token = '';
    $hmac_method = new OAuthSignatureMethod_HMAC_SHA1();
    $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";
    return do_body($endpoint, $method, $body, $header);
}