3
<?php
//のOauth基本構成phpを使用してアクセストークンとAccessTokenシークレットを取得するには?
$oauthbaseurl = "https://sandbox.woohoo.in/";
$requestTokenUrl = "https://sandbox.woohoo.in/oauth/initiate?oauth_callback=oob";
$accessTokenUrl = "https://sandbox.woohoo.in/oauth/token";
$consumerkey = "8af50260ae5444bdc34665c2b6e6daa9";
$consumersecret = "93c1d8f362749dd1fe0a819ae8b5de95";
$callbackUrl = "https://sandbox.woohoo.in/";
// OAuthのライブラリファイルが
include_once "../../library/OAuthStore.php";
include_once "../../library/OAuthRequester.php";
define("WOOHOO_CONSUMER_KEY", "8af50260ae5444bdc34665c2b6e6daa9"); //
define("WOOHOO_CONSUMER_SECRET", "93c1d8f362749dd1fe0a819ae8b5de95");
を含ま//定数、変数
OAuthStore 初期define("WOOHOO_OAUTH_HOST", "https://sandbox.woohoo.in/");
define("WOOHOO_REQUEST_TOKEN_URL", WOOHOO_OAUTH_HOST . "oauth/initiate?oauth_callback=oob");
define("WOOHOO_AUTHORIZE_URL", WOOHOO_OAUTH_HOST . "oauth/authorize/customerVerifier");
define("WOOHOO_ACCESS_TOKEN_URL", WOOHOO_OAUTH_HOST . "oauth/token");
define('OAUTH_TMP_DIR', function_exists('sys_get_temp_dir') ? sys_get_temp_dir() : realpath($_ENV["TMP"]));
//を定義します
$options = array(
'consumer_key' => WOOHOO_CONSUMER_KEY,
'consumer_secret' => WOOHOO_CONSUMER_SECRET,
'server_uri' => WOOHOO_OAUTH_HOST,
'request_token_uri' => WOOHOO_REQUEST_TOKEN_URL,
'access_token_uri' => WOOHOO_ACCESS_TOKEN_URL
);
// Note: do not use "Session" storage in production. Prefer a database
// storage, such as MySQL.
OAuthStore::instance("Session", $options);
try {
if (empty($_GET["oauth_token"])) {
$getAuthTokenParams = array(
'scope' => 'https://sandbox.woohoo.in/',
'xoauth_displayname' => 'Oauth test',
'oauth_callback' => 'https://sandbox.woohoo.in/'
);
// get a request token
$tokenResultParams = OAuthRequester::requestRequestToken(WOOHOO_CONSUMER_KEY, 0, $getAuthTokenParams);
//
echo "Token verrified response";
echo "<pre>";
print_r($woohoovery_response);
//exit;
$oauthTimestamp = time();
$characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$nonce = '';
for ($i = 0; $i < 32; $i++) {
$nonce .= $characters[mt_rand(0, strlen($characters) - 1)];
}
$oauthSignatureMethod = "HMAC-SHA1";
$oauthVersion = "1.0";
$params = array(
'oauth_consumer_key' => $consumerkey,
'oauth_signature_method' => 'HMAC-SHA1',
'oauth_timestamp' => $oauthTimestamp,
'oauth_nonce' => $nonce,
'oauth_verifier' => $verifier,
'oauth_token' => $tokenResultParams['token'],
'oauth_version' => '1.0'
);
echo "<pre>";
print_r($params);
//exit;
$post_string = urlencode('GET') . "&" . urlencode(WOOHOO_ACCESS_TOKEN_URL) . "?";
echo "<pre>";
print_r($post_string);
//exit;
foreach ($params as $key => $value) {
$stringPart = urlencode($key . "=" . $value . "&");
$post_string .= $stringPart;
}
//exit;
$post_string = rtrim($post_string, '%26');
$signatureKey = urlencode($consumersecret) . "&" . urlencode($tokenResultParams['token_secret']);
echo "<pre>";
print_r($signatureKey);
$signature = base64_encode(hash_hmac('sha1', $post_string, $signatureKey));
$signature = urlencode($signature);
//署名
echo "<pre>";
echo " signature ";
print_r($signature);
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => WOOHOO_ACCESS_TOKEN_URL . "?oauth_consumer_key=" . WOOHOO_CONSUMER_KEY . "&oauth_verifier=" . $verifier . "&oauth_token=" . $tokenResultParams['token'] . "&oauth_signature_method=" . $oauthSignatureMethod . "&oauth_signature=" . $signature . "&oauth_nonce=" . $nonce . "&oauth_timestamp=" . $oauthTimestamp . "&oauth_version=1.0",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"cache-control: no-cache"
)
));
$woohoospendresponse = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
を印刷検証を印刷
echo "Token obtain response";
echo "<pre>";
print_r($tokenResultParams);
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => WOOHOO_AUTHORIZE_URL . "?oauth_token=" . $tokenResultParams['token'] . "&[email protected]&[email protected]",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"cache-control: no-cache"
)
));
$woohoovery_response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $woohoovery_response;
}
$woohoovery = json_decode($woohoovery_response);
$verifier = $woohoovery->verifier;
// paramsはトークン結果を印刷
//プリント最終アクセストークン及び秘密鍵 ここで署名が無効なエラーになる
echo "<pre>";
print_r($woohoospendresponse);
exit;
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $woohoospendresponse;
}
}
}
catch (OAuthException2 $e) {
echo "OAuthException: " . $e->getMessage();
var_dump($e);
}
?>
この問題を助けてください。進歩をありがとう –