|
@@ 44-79 (lines=36) @@
|
| 41 |
|
return $result; |
| 42 |
|
} |
| 43 |
|
|
| 44 |
|
private static function verify() { |
| 45 |
|
$config = static::getConfig(); |
| 46 |
|
$oauthNonce = md5(uniqid(rand(), true)); |
| 47 |
|
$oauthTimestamp = time(); |
| 48 |
|
$oauth_token = $_GET['oauth_token']; |
| 49 |
|
$oauth_verifier = $_GET['oauth_verifier']; |
| 50 |
|
$oauth_token_secret = $_SESSION['oauth_token_secret']; |
| 51 |
|
//string |
| 52 |
|
$oauth_base_text = "GET&"; |
| 53 |
|
$oauth_base_text .= urlencode('https://api.twitter.com/oauth/access_token') . "&"; |
| 54 |
|
$oauth_base_text .= urlencode("oauth_consumer_key=" . $config['consumer_key'] . "&"); |
| 55 |
|
$oauth_base_text .= urlencode("oauth_nonce=" . $oauthNonce . "&"); |
| 56 |
|
$oauth_base_text .= urlencode("oauth_signature_method=HMAC-SHA1&"); |
| 57 |
|
$oauth_base_text .= urlencode("oauth_token=" . $oauth_token . "&"); |
| 58 |
|
$oauth_base_text .= urlencode("oauth_timestamp=" . $oauthTimestamp . "&"); |
| 59 |
|
$oauth_base_text .= urlencode("oauth_verifier=" . $oauth_verifier . "&"); |
| 60 |
|
$oauth_base_text .= urlencode("oauth_version=1.0"); |
| 61 |
|
|
| 62 |
|
$key = $config['consumer_secret'] . "&" . $oauth_token_secret; |
| 63 |
|
//request |
| 64 |
|
$oauth_signature = base64_encode(hash_hmac("sha1", $oauth_base_text, $key, true)); |
| 65 |
|
$url = 'https://api.twitter.com/oauth/access_token'; |
| 66 |
|
$url .= '?oauth_nonce=' . $oauthNonce; |
| 67 |
|
$url .= '&oauth_signature_method=HMAC-SHA1'; |
| 68 |
|
$url .= '&oauth_timestamp=' . $oauthTimestamp; |
| 69 |
|
$url .= '&oauth_consumer_key=' . $config['consumer_key']; |
| 70 |
|
$url .= '&oauth_token=' . urlencode($oauth_token); |
| 71 |
|
$url .= '&oauth_verifier=' . urlencode($oauth_verifier); |
| 72 |
|
$url .= '&oauth_signature=' . urlencode($oauth_signature); |
| 73 |
|
$url .= '&oauth_version=1.0'; |
| 74 |
|
|
| 75 |
|
|
| 76 |
|
$response = file_get_contents($url); |
| 77 |
|
parse_str($response, $result); |
| 78 |
|
return $result; |
| 79 |
|
} |
| 80 |
|
|
| 81 |
|
private static function getInfo($result) { |
| 82 |
|
$config = static::getConfig(); |
|
@@ 81-117 (lines=37) @@
|
| 78 |
|
return $result; |
| 79 |
|
} |
| 80 |
|
|
| 81 |
|
private static function getInfo($result) { |
| 82 |
|
$config = static::getConfig(); |
| 83 |
|
$oauth_nonce = md5(uniqid(rand(), true)); |
| 84 |
|
$oauth_timestamp = time(); |
| 85 |
|
|
| 86 |
|
$oauth_token = $result['oauth_token']; |
| 87 |
|
$oauth_token_secret = $result['oauth_token_secret']; |
| 88 |
|
$screen_name = $result['screen_name']; |
| 89 |
|
|
| 90 |
|
$oauth_base_text = "GET&"; |
| 91 |
|
$oauth_base_text .= urlencode('https://api.twitter.com/1.1/users/show.json') . '&'; |
| 92 |
|
$oauth_base_text .= urlencode('oauth_consumer_key=' . $config['consumer_key'] . '&'); |
| 93 |
|
$oauth_base_text .= urlencode('oauth_nonce=' . $oauth_nonce . '&'); |
| 94 |
|
$oauth_base_text .= urlencode('oauth_signature_method=HMAC-SHA1&'); |
| 95 |
|
$oauth_base_text .= urlencode('oauth_timestamp=' . $oauth_timestamp . "&"); |
| 96 |
|
$oauth_base_text .= urlencode('oauth_token=' . $oauth_token . "&"); |
| 97 |
|
$oauth_base_text .= urlencode('oauth_version=1.0&'); |
| 98 |
|
$oauth_base_text .= urlencode('screen_name=' . $screen_name); |
| 99 |
|
|
| 100 |
|
$key = $config['consumer_secret'] . '&' . $oauth_token_secret; |
| 101 |
|
$signature = base64_encode(hash_hmac("sha1", $oauth_base_text, $key, true)); |
| 102 |
|
|
| 103 |
|
|
| 104 |
|
$url = 'https://api.twitter.com/1.1/users/show.json'; |
| 105 |
|
$url .= '?oauth_consumer_key=' . $config['consumer_key']; |
| 106 |
|
$url .= '&oauth_nonce=' . $oauth_nonce; |
| 107 |
|
$url .= '&oauth_signature=' . urlencode($signature); |
| 108 |
|
$url .= '&oauth_signature_method=HMAC-SHA1'; |
| 109 |
|
$url .= '&oauth_timestamp=' . $oauth_timestamp; |
| 110 |
|
$url .= '&oauth_token=' . urlencode($oauth_token); |
| 111 |
|
$url .= '&oauth_version=1.0'; |
| 112 |
|
$url .= '&screen_name=' . $screen_name; |
| 113 |
|
|
| 114 |
|
$response = file_get_contents($url); |
| 115 |
|
|
| 116 |
|
return json_decode($response, true); |
| 117 |
|
} |
| 118 |
|
|
| 119 |
|
public static function auth() { |
| 120 |
|
$config = static::getConfig(); |