浏览 5053 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2010-02-09
最后修改:2010-02-27
登陆google
public function googleLogin($email,$password){ $session = UserOper::openSession();//如果已经登陆,直接返回 if($session['googleAuth']){ $session->close(); return true; } $data = array( 'accountType' => 'GOOGLE', 'Email' => $email, 'Passwd' => $password, 'service' => 'cp', //google 一系列api 的简写,在google 上能找到,可以换成你想要的服务简写 'source' => 'test-oauth-1.0', //给你自己的应用程序命名 ); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "https://www.google.com/accounts/ClientLogin"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); $output = curl_exec($ch); $info = curl_getinfo($ch); preg_match('/Auth=.+/',$output,$tempArray); if($info['http_code']!=200 or empty($tempArray)){ return false; } $auth = 'Authorization: GoogleLogin auth='.substr($tempArray[0],5); $session['googleAuth'] = $auth; return true; } 获取联系人信息(atom格式数据源)
public function getGoogleResource($url){ $session = UserOper::openSession(); if(!$session['googleAuth']){ $session->close(); return false; } $session->close(); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_HTTPHEADER,array($session['googleAuth'])); $output = curl_exec($ch); $info = curl_getinfo($ch); if($info['http_code']!=200) return false; return $output; } 解析数据源,读取联系人email地址(使用 php DOMDocument)
public function getGoogleFriends(){ $url = 'http://www.google.com/m8/feeds/contacts/default/full'; $source = $this->getGoogleResource($url); $friends = array(); if($source){ $dom = new DOMDocument(); $dom->loadXML($source); $entries = $dom->getElementsByTagName('entry'); foreach ( $entries as $entry ){ $email = $entry->getElementsByTagName('email'); $value = $email->item(0)->getAttributeNode("address")->value; $friends[$value] = $value; } return $friends; } return false; } 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2010-05-04
想知道,楼主调试CURL模拟登陆邮件的时候,用了哪些方便的软件吗?上次写CURL模拟登陆SOHU抓邮箱好友,只会用FF下的FireBug,感觉挺麻烦的。
|
|
返回顶楼 | |