Пример #1
0
 public function oauthSign($url, $secret, $token = null)
 {
     if (!class_exists(__NAMESPACE__ . '\\OAuthSignatureMethod_HMAC_SHA1')) {
         $this->loadClass('OAuthSignatureMethod');
         $this->loadClass('OAuthSignatureMethod_HMAC_SHA1');
     }
     $oauth = new OAuthSignatureMethod_HMAC_SHA1();
     $sign = $oauth->build_signature($url, $secret, $token);
     return $sign;
 }
Пример #2
0
$ms_key = "[your onsite app key]";
$ms_secret = "[your onsite app secret]";
print "Hello, this is an onsite app using the MySpaceID PHP SDK.<br>";
//print $_SERVER['REQUEST_URI'] . "<br>";
//print $_GET . "<br>";
//print_r($_GET) . "<br>";
//
// Compute signature of request to verify
//
$method = $_SERVER["REQUEST_METHOD"];
$req = OAuthRequest::from_request($method, $http_url);
$req->del_parameter('oauth_signature');
//print "<br>Req = " . $req;
$sigMethod = new OAuthSignatureMethod_HMAC_SHA1();
$consumer = new OAuthConsumer($ms_key, $ms_secret);
$signature = $sigMethod->build_signature($req, $consumer);
print "<br>Base string = " . $req . base_string;
print "<br>Built Signature = " . $signature . "";
print "<br>Passed in Signature = " . $_GET['oauth_signature'] . "<br>";
if (strcmp($_GET['oauth_signature'], $signature) != 0) {
    print "Signatures don't match!  Exiting.<br>";
} else {
    print "Signatures match!";
    // Send notification
    $userId = @$_GET['opensocial_viewer_id'];
    $ms = new MySpace($ms_key, $ms_secret, null, null, false);
    $templateParameters = array('content' => 'Test notification content from php sdk', 'button0_surface' => 'canvas', 'button0_label' => 'Go To App Canvas', 'button1_surface' => 'appProfile', 'button1_label' => 'Go To App Profile');
    $rc = $ms->sendNotification('129910', '454304609,28568917', $templateParameters, 'http://api.myspace.com/v1/users/296768296');
    echo '<br><br>sendNotification returned ' . $rc;
    $profileInfo = $ms->getProfile($userId);
    displayProfileInfo($profileInfo);