1. 程式人生 > >ucenter及discuz整合,雙向同步註冊及登入注意事項2016年9月13

ucenter及discuz整合,雙向同步註冊及登入注意事項2016年9月13

如果遇到介面除錯問題,可以參考我的其它教程.

http://blog.csdn.net/viqecel/article/details/52492081

http://blog.csdn.net/viqecel/article/details/52485774

後臺修改方法


注意


 所有涉及檔案修改的,不管什麼結尾的,只要是文字類的檔案,都需要用專業的程式設計軟體開啟.比如notepad++ 工具.
 否則,會導致網站錯位,亂碼等,因為會產生bom頭問題.具體可以搜尋下






一,先進論壇後臺,站長,ucenter設定,選擇允許直接啟用
二,進ucenter ,應用管理,新建立應用.型別選其它,名稱填book,主url填你的網站主頁網址.比如http://123.com
通訊金鑰隨便填一個密碼,最下面同步登入填是.其它不用填,儲存.


三,修改要整合的第三方應用網站的資料庫配置.方便從第三方網站上,同步插入會員資料到ucenter中.
有些可能需要在後臺配置,或直接修改檔案,要具體分析.
這個檔案裡面的內容.其實就是ucenter後臺,book應用,編輯後,拉到最下面,看到配置資訊,把他全部複製後,填在uc.php中的對應位置,儲存,上傳,替換原檔案即可..


四,去論壇的安裝目錄中,找uc_client/data/cache/apps.php 開啟,裡面有你uc後臺的所有應用,如果沒有.說明不正常.把裡面所有內容.複製,填到book網站對應的uc_client\data\cache\apps.php中,儲存上傳
這兩個檔案要一致,才能同步.




五,實現論壇上註冊會員後,直接在所有應用中自動登入,而不必登入,再登入一次才同步.
方法
修改論壇目錄中對應的,\uc_client\model\user.php 中的function add_user 函式


把大約131行的


$salt = substr(uniqid(rand()), -6);




整體替換為


$salt = substr(uniqid(rand()), -6);
$password2 = md5($password);

然後,在return $uid;
 
 
 的上面增加下面這段程式碼
 
 
 
$time2=date('Y-m-d H:i:s',$this->base->time);
$this->db->query("INSERT INTO admin_book.hbdx_users  SET uc_id='$uid',user_mail='$email',user_name='$username',user_group='同步註冊會員',user_displayname='$username',registerdate='$time2',user_pass='$password2',user_integration='10'");






/////注意,其中,admin_book 表示book網站對應的資料庫名,hbdx_users 表示表名,可以相應修改為正在使用的.


六,同時,修改論壇目錄中的.
\source\class\class_member.php


找到大約926行的








   $extra = array(
        'showid' => 'succeedmessage',
        'extrajs' => '<script type="text/javascript">'.
    'setTimeout("window.location.href =\''.$href.'\';", 3000);'.
    '$(\'succeedmessage_href\').href = \''.$href.'\';'.
    '$(\'main_message\').style.display = \'none\';'.
    '$(\'main_succeed\').style.display = \'\';'.
    '$(\'succeedlocation\').innerHTML = \''.lang('message', $locationmessage).'\';'.
        '</script>',
        'striptags' => false,
);










整體替換為






$ucsynlogin = '';
                        if($_G['setting']['allowsynlogin']) {
                                loaducenter();
                                $ucsynlogin = uc_user_synlogin($_G['uid']);
                        }
$extra = array(
'showid' => 'succeedmessage',
'extrajs' => '<script type="text/javascript">'.
'setTimeout("window.location.href =\''.$href.'\';", '.$refreshtime.');'.
'$(\'succeedmessage_href\').href = \''.$href.'\';'.
'$(\'main_message\').style.display = \'none\';'.
'$(\'main_succeed\').style.display = \'\';'.
'$(\'succeedlocation\').innerHTML = \''.lang('message', $locationmessage).'\';'.
'</script>'.$ucsynlogin,
'striptags' => false,
);



//其實主要是在後面增加了這一句
//.$ucsynlogin ,從而實現論壇上初次註冊的會員,就可以直接同步到另一站,不需要退出再登入一次.





七,如果論壇中已經存在以前註冊的使用者,如果他論壇上登入後,想同步註冊到本站,則還需要在論壇目錄中,增加個email引數.這樣,本應用的api/uc.php中就能得到這個引數.
具體為
\uc_server\control\user.php,要修改本檔案的onsynlogin()

下面這個函式直接替換原來的就行.裡面增加了email








function onsynlogin() {
$this->init_input();
$uid = $this->input('uid');
if($this->app['synlogin']) {
if($this->user = $_ENV['user']->get_user_by_uid($uid)) {
$synstr = '';
foreach($this->cache['apps'] as $appid => $app) {
if($app['synlogin']) {
if($app['appid'] != $this->app['appid']) {
$synstr .= '<script type="text/javascript" src="'.$app['url'].'/api/'.$app['apifilename'].'?time='.$this->time.'&code='.urlencode($this->authcode('action=synlogin&username='.$this->user['username'].'&uid='.$this->user['uid'].'&email='.$this->user['email'] .'&password='.$this->user['password']."&time=".$this->time,'ENCODE', $app['authkey'])).'" reload="1"></script>';
}
if(is_array($app['extra']['extraurl'])) foreach($app['extra']['extraurl'] as $extraurl) {
$synstr .= '<script type="text/javascript" src="'.$extraurl.'/api/'.$app['apifilename'].'?time='.$this->time.'&code='.urlencode($this->authcode('action=synlogin&username='.$this->user['username'].'&uid='.$this->user['uid'].'&email='.$this->user['email'].'&password='.$this->user['password']."&time=".$this->time,'ENCODE', $app['authkey'])).'" reload="1"></script>';
}
}
}
return $synstr;
}
}
return '';
}






//函式結束