|
本帖最后由 xiaozhuaisnow 于 2012-10-31 11:22 编辑
最近看了看腾讯的iweibo,由于公司需求更改如下几个方面
1、调用微博授权跳转相应网站页面(有人会问直接用oauth不久行了吗,但是没办法,需求就是这样)
2、绑定和注册页面跳转相应网站
3、与ucenter通信做到用户登录同步
根据需求和iweibo分析得到主要分为两部分
1、绑定和注册
2、oauth授权(已绑定用户登录)
下面是iweibo的修改
1、登录授权部分(oauth)在application/controller/index/login.php的rAction头部加入
PHP复制代码
if (isset($_GET['url']) && !empty($_GET['url'])){
$_SESSION['get_url']=$_GET['url'];
}
复制代码
rAction是启动oauth授权的。
在application/core/fun.php修改showmsg
修改如下:
PHP复制代码
public static function showmsg ( $msg , $gourl=-1 , $time = null , $button=false )
{
if (isset($_SESSION['get_url']) && !empty($_SESSION['get_url'])){
//echo $_SESSION['get_url'];
$redict_url=$_SESSION['get_url'];
unset($_SESSION['get_url']);
}
if ($time === null)
{
$time = Core_Config ::get ('showtime' , 'basic' , 3);
}
$time > 1000 && $time = intval ($time / 1000);
$seogourl = $gourl;
if ($gourl == -1)
{
$seogourl = $gourl = empty($_SERVER['HTTP_REFERER'])? self::getUrlroot():$_SERVER['HTTP_REFERER'];
// $seogourl = $gourl = 'javascript:history.go(-1)';
}
elseif (!preg_match ('#^(https?|ftp)://#' , $gourl) && !preg_match ('/^javascript/' , $gourl))
{
$seogourl = Core_Template ::seoChange ($gourl);
if(!preg_match('/^\//', $gourl))
{
$gourl = '/' . $gourl;
}
}
if (!$time)
{ #立即跳转
if (!preg_match ('/^javascript/' , $gourl))
{
//echo "立即跳转";die();
if (!empty($redict_url) && isset($redict_url)){
header ('Location: ' . $seogourl.'?redict_url='.$redict_url);
echo $meta = "<meta http-equiv=\"refresh\" content=\"{$time};url={$seogourl}\" />";
}else{
header ('Location: ' . $seogourl);
echo $meta = "<meta http-equiv=\"refresh\" content=\"{$time};url={$seogourl}\" />";
}
}
else
{
//echo "no立即跳转";die();
if (!empty($redict_url) && isset($redict_url)){
$seogourl=$seogourl.'?redict_url='.$redict_url;
$redict_url1=explode('"',$seogourl);
//print_r($redict_url1);
$redict_url_end=str_replace(';','',$redict_url1[2]);
$redict_urls=$redict_url1[0].'"'.$redict_url1[1].$redict_url_end.'"';
//echo str_replace("javascript:","",$redict_urls);die();
//localhost/upload/index.php/u/xiaozhu19891002"
echo "<script>" , str_replace("javascript:","",$redict_urls) , "</script>";
}else{
echo "<script>" , str_replace("javascript:","",$seogourl) , "</script>";
}
}
} else {
#延迟跳转
// echo "延迟跳转";//die();
Core_Template ::assignvar('gourl' , $gourl);
Core_Template ::assignvar('seogourl' , $seogourl);
Core_Template ::assignvar('__msg' , $msg);
Core_Template ::assignvar('msg' , $msg);
Core_Template ::assignvar('time' , $time);
Core_Template ::assignvar('button' , $button);
Core_Template ::assignvar('_resource', Core_Config ::get('resource_path','basic','/'));
Core_Template ::assignvar('site_url', Core_Config ::get('site_url','basic',false));
if (Core_Controller_Front ::getInstance()->getModelName () == 'admin')
{
Core_Template ::render ('admin/showmsg.tpl');
}
else
{
Core_Template ::render ('index/showmsg.tpl');
}
}
exit;
}
复制代码
showmsg是iweibo负责跳转的
2、更改注册和绑定
注册和绑定是经过rAction后程序判定微博用户是否是网站用户,如果为否则调用注册和绑定
绑定是login.php/lAction 注册时reg.php/jAction
以上他们都有一个共同点,就是都会经过showmsg跳转到u.php/index
所以只要在u.php/index做好控制就可以
PHP复制代码
private function index ($name)
{
/*Controller_Api_Uc::indexAction();
return;*/
$msgCode = intval($this->getParam('msg'));
$msgCode && $this->assign('showmsg', Core_Comm_Modret ::getMsg($msgCode));
if(Core_Config ::get('useuc', 'basic', false) && isset($_SESSION['ucsynlogin']) && $_SESSION['ucsynlogin'])
{
//生成同步登录的代码
$ucsynlogin = Core_Outapi_Uc ::call('user_synlogin', $_SESSION['uid']);
$this->assign('ucsynlogin', $ucsynlogin);
unset($_SESSION['ucsynlogin']);
}
//个人认证设置
$local = Core_Config ::get('localauth', 'certification.info');
$platform = Core_Config ::get('platformauth', 'certification.info');
$localtext = Core_Config ::get('localauthtext', 'certification.info');
$authInfo = array('local' => $local, 'platform' => $platform, 'localtext' => $localtext);
$this->assign('auth', $authInfo);
if(strtolower($name) == strtolower($this->userInfo["name"])) //跳我的主页
{
$get_msg=$this->userInfo;
//主栏组件
$this->assign('mainComponent', Model_Componentprocessunit ::getComponentWithHtml(1, 'main'));
//右栏组件
$this->assign('rightComponent', Model_Componentprocessunit ::getComponentWithHtml(1, 'right'));
//如需拉取多个类型请|上(1|2) 得到3,type=3即可,填零表示拉取所有类型
$utype = Core_Comm_Validator ::getNumArg($this->getParam("utype"), 0, 64, 0);
//Contenttype:内容过滤 填零表示所有类型 1-带文本 2-带链接 4图片 8-带视频 0x10-带音频
$ctype = Core_Comm_Validator ::getNumArg($this->getParam("ctype"), 0, 16, 0);
$this->assign('utype', $utype);
$this->assign('ctype', $ctype);
Core_Lib_Base ::clearNewMsgInfo(5);
//获取填充tbody
$this->getBody('index');
if (isset($_GET['redict_url']) && !empty($_GET['redict_url'])){
//print_r($_GET['redict_url']);die();
//echo $_GET['redict_url'];
//$this->assign('redict_url', $_GET['redict_url']);
echo $ucsynlogin;
echo '<script type="text/javascript">window.location.href="'.'http://'.$_GET['redict_url'];
echo '"; </script>';
return;
}
//激活样式
$this->assign('active', 'index');
// echo 'sb';die();
$this->display('user/index_test_timeline.tpl');
}
else //他人页
{
//获取显示用户资料
$guest = Model_User_Util ::getFullInfo($name);
if(isset($guest['errormsg']))
{
Core_Fun ::showmsg($guest['errormsg'],-1);
}
$guest['head'] = Core_Lib_Base ::formatHead($guest['head'],120);
//拉取偶像列表, 只拉13个
$p = array("n" => $name, "num" => 12, "start" => 0, "type" => 1);
//获取偶像
$friendObj = Model_Friend ::singleton();
$idols = $friendObj->getMyfriend($p);
$idollist = $idols["data"]["info"];
foreach($idollist as &$u)
{
$u['head'] = Core_Lib_Base ::formatHead($u['head'], 50);
}
$this->getBody('guest', $name);
$utype = Core_Comm_Validator ::getTidArg($this->getParam('utype'), '0');
$ctype = Core_Comm_Validator ::getTidArg($this->getParam('ctype'), '0');
$url = '/u/' . $name;
//时间线类型
$filterlist = array(array('url' => $url, 'name' => '全部', 'utype' => '0'),
array('url' => $url . '/utype/1', 'name' => '原创', 'utype' => '1'),
array('url' => $url . '/utype/2', 'name' => '转播', 'utype' => '2'),
array('url' => $url . '/ctype/4', 'name' => '图片', 'ctype' => '4'),
array('url' => $url . '/ctype/8', 'name' => '视频', 'ctype' => '8'),
array('url' => $url . '/ctype/16', 'name' => '音乐', 'ctype' => '16'));
$this->assign('idollist', $idollist);
$this->assign('guest', $guest);
$this->assign('utype', $utype);
$this->assign('ctype', $ctype);
$this->assign('filterlist', $filterlist);
//激活样式
$this->assign('active', 'guest');
$this->display('index/guest_timeline.tpl');
}
}
复制代码
u.php/index加入
if (isset($_GET['redict_url']) && !empty($_GET['redict_url'])){
//print_r($_GET['redict_url']);die();
//echo $_GET['redict_url'];
//$this->assign('redict_url', $_GET['redict_url']);
echo $ucsynlogin;
echo '<script type="text/javascript">window.location.href="'.'http://'.$_GET['redict_url'];
echo '"; </script>';
return;
}
其中 echo $ucsynlogin;是告诉程序与ucenter通信 具体$ucsynlogin; 是什么,去看看源码就知道了
整体就这些,看起来很简单,流程我简化了许多,其中详细流程还是有点操蛋的。
发的比较匆忙,又不好之处勿喷!
|
|