PHP 8.5.0 Released!

OAuth::generateSignature

(No version information available, might only be in Git)

OAuth::generateSignatureシグネチャを生成する

説明

public OAuth::generateSignature(string $http_method, string $url, mixed $extra_parameters = ?): string|false

最後の HTTP メソッド、URL そしてパラメータ文字列あるいは配列にもとづいてシグネチャを生成します。

パラメータ

http_method

リクエストの HTTP メソッド。

url

リクエストの URL。

extra_parameters

パラメータ文字列あるいは配列。

戻り値

生成されたシグネチャを文字列で返します。失敗した場合に false を返します

add a note

User Contributed Notes 1 note

up
-1
vk221000 at gmail dot com
3 years ago
<?php
/**
     * Get signature for the request Oauth 1.0
     *
     * @param string      $url url to send request to.
     * @param string      $consumer_key consumer key for the request credential.
     * @param string      $consumer_secret consumer secret for the request credential.
     * @param string      $method GET, POST etc methods.
     * @param array|false $params parameters to send during the request.
     * @since 1.0.0
     * @return string
     */
    public function get_signature( $url, $consumer_key, $consumer_secret, $method = 'GET', $params = false ) {
            $nonce     = mt_rand();
            $timestamp = time();
            $oauth     = new \OAuth( $consumer_key, $consumer_secret );
            $oauth->setTimestamp( $timestamp );
            $oauth->setNonce( $nonce );
            $sig = $oauth->generateSignature( $method, $url, $params );
      
            $header = 'OAuth ' .
                'oauth_consumer_key=' . $consumer_key .
                ',oauth_signature_method="HMAC-SHA1"' .
                ',oauth_nonce="'. $nonce . '"' .
                ',oauth_timestamp="' . $timestamp . '"'.
                ',oauth_version="1.0"'.                   
                ',oauth_signature="' . urlencode( $sig ) . '"'
                ;
            return $header;
    }
?>
To Top