Skip to content

Instantly share code, notes, and snippets.

@kawahara
Created May 25, 2010 07:03
Show Gist options
  • Save kawahara/412862 to your computer and use it in GitHub Desktop.
Save kawahara/412862 to your computer and use it in GitHub Desktop.
<?php
include_once './oauth/OAuth.php';
// change these consts
define('CONSUMER_KEY', '#CONSUMER_KEY#');
define('CONSUMER_SECRET', '#CONSUMER_SECRET#');
define('BASE_URL', '#SNS_URL#');
// bigin check signature
class OAuthSignatureMethod_RSA_SHA1_opOpenSocialPlugin extends OAuthSignatureMethod_RSA_SHA1
{
protected function fetch_private_cert(&$request) {
}
protected function fetch_public_cert(&$request) {
return <<<EOT
#PUBLIC_CERT#
Replace public cert of OpenSocial-container
EOT;
}
}
$request = OAuthRequest::from_request(null, null, null);
$signature_method = new OAuthSignatureMethod_RSA_SHA1_opOpenSocialPlugin();
if (!$signature_method->check_signature($request, null, null, $request->get_parameter('oauth_signature')))
{
header('HTTP/1.1 403 Forbidden');
exit;
}
// end check signature
$consumer = new OAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET);
$request = OAuthRequest::from_consumer_and_token(
$consumer,
null,
'GET',
BASE_URL.'/api.php/social/rest/people/@me/@self'
);
$request->set_parameter('xoauth_requestor_id', $_GET['opensocial_owner_id']);
$request->sign_request(new OAuthSignatureMethod_HMAC_SHA1(), $consumer, null);
$res = do_get($request->get_normalized_http_url(), $request->to_postdata());
$json = json_decode($res, true);
if (null === $json)
{
header('HTTP/1.1 500 Internal Server Error');
exit;
}
?>
<?php echo "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja" dir="ltr">
<head>
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=UTF-8" />
<title>私です</title>
<style type="text/css">
<![CDATA[
a:link{color:#ffffff;}
a:visited{color:#ffffff;}
a:focus{}
*{
font-size:x-small;
color:#ffd83d;
}
]]>
</style>
</head>
<body>
<?php
if (1 == $_GET['refid'])
{
echo 'あなたのIDは'.$json['entry']['id'].'です。<br>';
echo "<img src=\"".$json['entry']['thumbnailUrl']."\"><br>";
echo "<a href=\"?url=".urlencode("http://happyturn/mobile.php")."\">画面遷移!</a><br>";
echo "<a href=\"invite:friends?callback=".urlencode('http://happyturn/mobile.php?refid=1')."\">このアプリにフレンドを招待とかする</a><br>";
}
else
{
echo $json['entry']['displayName']."さんこんにちは<br>";
echo "<a href=\"invite:friends?callback=".urlencode('http://happyturn/mobile.php?refid=1')."\">招待ページ</a><br>";
echo "<a href=\"?url=".urlencode("http://happyturn/mobile.php?refid=1&p=1&p=2")."&guid=ON\">画面遷移!</a><br>";
}
?>
<form action="?url=<?php echo urlencode('http://happyturn/mobile.php?p=1') ?>" method="POST">
<input type="text" name="hoge">
<input type="submit">
</form>
</body>
</html>
<?php
function do_get($uri, $data = '')
{
$h = curl_init();
curl_setopt($h, CURLOPT_URL, $uri.'?'.$data);
curl_setopt($h, CURLOPT_POST, false);
curl_setopt($h, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($h);
curl_close($h);
return $result;
}
function do_post($uri, $params, $oauthrequest, $data)
{
$h = curl_init();
curl_setopt($h, CURLOPT_URL, $uri.'?'.http_build_query($params));
curl_setopt($h, CURLOPT_POST, true);
curl_setopt($h, CURLOPT_HTTPHEADER, array('Content-Type: application/json', $oauthrequest->to_header()));
curl_setopt($h, CURLOPT_POSTFIELDS, $data);
curl_setopt($h, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($h);
curl_close($h);
return $result;
}
function do_delete($uri, $params, $oauthrequest, $data)
{
$h = curl_init();
curl_setopt($h, CURLOPT_URL, $uri.'?'.http_build_query($params));
curl_setopt($h, CURLOPT_CUSTOMREQUEST, 'DELETE');
curl_setopt($h, CURLOPT_HTTPHEADER, array('Content-Type: application/json', $oauthrequest->to_header()));
curl_setopt($h, CURLOPT_POSTFIELDS, $data);
curl_setopt($h, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($h);
curl_close($h);
return $result;
}
<?xml version="1.0" encoding="UTF-8"?>
<Module>
<ModulePrefs title="Mobile Test - 1" description="Mobile Test" author="Shogo Kawahara" />
<Content type="url" view="mobile" href="http://happyturn/mobile.php" />
</Module>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment