RPX提供了OpenID的托管服务,你所要做的,只是在网页中插入几行代码,剩下的全部由它来完成。

但是RPX提供的PHP示例代码,我想很多人未必会用,写的有点菜,我就没有用的起来。下面是我自己写的一个示例代码,供大家学习:)


<script src="https://rpxnow.com/openid/v2/widget"
type="text/javascript"></script>
<script type="text/javascript">
RPXNOW.token_url = "http://freebapp.org/tools/openid/rpx.php";
RPXNOW.realm = "freebapp";
RPXNOW.overlay = true;
RPXNOW.language_preference = 'en';
</script>

<?php
if(!empty($_REQUEST['token'])){
$post['token'] = $_REQUEST['token'];
$post['apiKey'] = 'a21e795ea614c12f549660ab15f93de30451d338';
$post['format'] = 'json';

$curl = curl_init();
$url = 'https://rpxnow.com/api/v2/auth_info?token_url='.urlencode('http://freebapp.org/tools/openid/rpx.php');
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $post);
curl_setopt($curl, CURLOPT_URL, $url);

$data = curl_exec($curl);
echo('<pre>');
print_r(json_decode($data));
echo('</pre>');
curl_close($curl);
}
?>

大家把上例的apiKey和token_url换成自己的就可以了!

示例演示

2 Comments

  • 4weeee@gmail.com

    这个能用中文不?好郁闷

  • 王炜

    我对这个没有多少研究,帮不到你,不好意思!

Leave a Reply