登录 |

PHP+CURL登录人人(校内)网passport

2009年09月27日 下午 56:55 | 作者:

由于人人网(renren.com)和开心网(kaixin.com)对接,新建了个passport服务,用于统一验证,模拟登录的方式也改了,请看通行证登录原理:

1.应用提交验证信息给passport:
email/password
origURL/domain
2.passport分配全局SessionID:
XNESSESSIONID=c3b27ade6716;
3.passport验证帐号/密码
4.用户验证成功,Location 回应用的 callbackUrl:
http://login.renren.com/callback.do?t=ad34b89977d3a45a7bd0b49ea568ad436&origURL=http%3A%2F%2Fwww.renren.com%2FSysHome.do
5.应用的callbackUrl负责获取用户信息,并分配当前的UID:
xnsid=48863dc
6.跳转到应用的首页origURL
function xiaonei_login($email, $password){
$url = ‘http://passport.renren.com/PLogin.do’;
$opt = array(
// LOCATION(自动跳转1次)
CURLOPT_MAXREDIRS => 1,
CURLOPT_FOLLOWLOCATION => 1,
CURLOPT_AUTOREFERER => 1,
// POST(提交验证数据)
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => “email=$email&password=$password&origURL=http%3A%2F%2Fwww.renren.com%2FSysHome.do&domain=renren.com”,
// COOKIE(保存cookie)
CURLOPT_COOKIEJAR => ‘./cookie’,
CURLOPT_COOKIEFILE => ‘./cookie’,
);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt_array($ch, $opt);
curl_exec($ch);
curl_close($ch);

}