$callback_url , 'oauth_consumer_key' => $consumer_key , 'oauth_nonce' => md5( microtime() ) , 'oauth_signature_method' => 'HMAC-SHA1' , 'oauth_timestamp' => time() , 'oauth_version' => '1.0' , ); // ã¢ã¯ã»ã¹ãã¼ã¯ã³ãªã©åå¾æã¨ããã¼ã¿åå¾æã§ã®å·®ç°ãã¡ããã¡ããã¨èª¿æ´ãã if( isset( $params_b['oauth_token'] ) ) { $params_a['oauth_token'] = $params_b['oauth_token'] ; unset( $params_b['oauth_token'] , $params_a['oauth_callback'] ) ; } if( isset( $params_b['oauth_token_secret'] ) ) { $oauth_token_secret = $params_b['oauth_token_secret'] ; unset( $params_b['oauth_token_secret'] ) ; } else { $oauth_token_secret = '' ; } if( isset($params_b['oauth_verifier']) ) { $params_a['oauth_verifier'] = $params_b['oauth_verifier'] ; unset( $params_b['oauth_verifier'] ) ; } // ãªã¯ã¨ã¹ãããã£ã®å®æ $request_body = http_build_query( $params_b ) ; // ãã¼ãä½æãã $signature_key = rawurlencode( $secret_key ) . '&' . rawurlencode( $oauth_token_secret ) ; // [$params_a]ã¨[$params_b]ãç½²åä½æã®ããåä½ $params_c = array_merge( $params_a , $params_b ) ; // [$params_c]ãã¢ã«ãã¡ãããé ã«ä¸¦ã³æ¿ãã ksort( $params_c ) ; // é å[$params_c]ã[ãã¼=å¤&ãã¼=å¤...]ã®æååã«å¤æ $signature_params = str_replace( array( '+' , '%7E' ) , array( '%20' , '~' ) , http_build_query( $params_c , '' , '&' ) ) ; // ãªã¯ã¨ã¹ãã¡ã½ããããªã¯ã¨ã¹ãURLããã©ã¡ã¼ã¿ããURLã¨ã³ã³ã¼ããã¦ãã[&]ã§ç¹ãããã¼ã¿ãä½æãã $signature_data = rawurlencode( $method ) . '&' . rawurlencode( $request_url ) . '&' . rawurlencode( $signature_params ) ; // ãã¼[$signature_key]ã¨ãã¼ã¿[$signature_data]ãHMAC-SHA1æ¹å¼ã®ããã·ã¥å¤ã«å¤æããbase64ã¨ã³ã³ã¼ããã¦ãç½²åãä½æãã $signature = base64_encode( hash_hmac( 'sha1' , $signature_data , $signature_key , true ) ) ; // [$params_a]ã«ç½²åã追å ãã $params_a['oauth_signature'] = $signature ; // ãããã¼ãä½æãã $header_params = http_build_query( $params_a , '' , ',' ) ; // GETã®å ´åã[$params_b]ããªã¯ã¨ã¹ãURLã®æ«å°¾ã«ä»ãã if( $params_b && $method=='GET' ) { $request_url .= '?' . http_build_query( $params_b , '' , '&' ) ; } // ã³ã³ããã¹ããç¨æ $context = array( 'http' => array( 'method' => $method , 'header' => array( 'Authorization: OAuth ' . $header_params , ), ) ) ; // POSTã¡ã½ããã®å ´åãã³ã³ããã¹ãã«ãªã¯ã¨ã¹ãããã£ãå ãã if( $request_body && $method != 'GET' ) { $context['http']['content'] = $request_body ; } // CURLã§ãªã¯ã¨ã¹ã $curl = curl_init() ; // ãªãã·ã§ã³ã®ã»ãã curl_setopt( $curl , CURLOPT_URL , $request_url ) ; curl_setopt( $curl , CURLOPT_HEADER, 1 ) ; curl_setopt( $curl , CURLOPT_CUSTOMREQUEST , $method ) ; curl_setopt( $curl , CURLOPT_SSL_VERIFYPEER , false ) ; // 証ææ¸ã®æ¤è¨¼ãè¡ããªã curl_setopt( $curl , CURLOPT_RETURNTRANSFER , true ) ; // curl_execã®çµæãæååã§è¿ã curl_setopt( $curl , CURLOPT_HTTPHEADER , $context['http']['header'] ) ; // ãããã¼ if( isset($context['http']['content']) && !empty($context['http']['content']) ) // ãã㣠(POSTæ) { curl_setopt( $curl , CURLOPT_POSTFIELDS , $context['http']['content'] ) ; } curl_setopt( $curl , CURLOPT_TIMEOUT , 5 ) ; // ã¿ã¤ã ã¢ã¦ãã®ç§æ° // å®è¡ $res1 = curl_exec( $curl ) ; $res2 = curl_getinfo( $curl ) ; // çµäº curl_close( $curl ) ; // åå¾ãããã¼ã¿ $response = substr( $res1, $res2['header_size'] ) ; // åå¾ãããã¼ã¿(JSONãªã©) $header = substr( $res1, 0, $res2['header_size'] ) ; // ã¬ã¹ãã³ã¹ãããã¼ (æ¤è¨¼ã«å©ç¨ãããå ´åã«ã©ãã) // åå¾ãããã¼ã¿ãè¿å´ return ( !$response_header ) ? $response : array( $response , $header ) ; } // GETã¯ã¨ãªå½¢å¼ã®æååãé åã«å¤æããé¢æ° function get_query( $data = '' ) { // æååã[&]ã§åºåã£ã¦é åã«å¤æãã $ary = explode( '&' , $data ) ; // [&]ãå«ã¾ãã¦ããªãå ´åã¯çµäº if( 2 > count( $ary ) ) { return false ; } // æååãé åã«æ´å½¢ãã foreach( $ary as $items ) { $item = explode( '=' , $items ) ; $query[ $item[0] ] = $item[1] ; } // è¿å´ return $query ; }