多程序整合UCenter首次注冊同步登錄
$this->db->query("INSERT INTO `dbname`.pre_common_member SET uid='$uid', username='$username', password='$password', email='$email', adminid='0', groupid='10', regdate='".$this->base->time."', credits='0', timeoffset='9999'"); $this->db->query("INSERT INTO `dbname`.pre_common_member_status SET uid='$uid', regip='$regip', lastip='$regip', lastvisit='".$this->base->time."', lastactivity='".$this->base->time."', lastpost='0', lastsendmail='0'"); $this->db->query("INSERT INTO `dbname`.pre_common_member_profile SET uid='$uid'"); $this->db->query("INSERT INTO `dbname`.pre_common_member_field_forum SET uid='$uid'"); $this->db->query("INSERT INTO `dbname`.pre_common_member_field_home SET uid='$uid'"); $this->db->query("INSERT INTO `dbname`.pre_common_member_count SET uid='$uid', extcredits1='0', extcredits2='0', extcredits3='0', extcredits4='0', extcredits5='0', extcredits6='0', extcredits7='0', extcredits8='0'");Discuz 的參數比較多,`dbname` 是數據庫名,.pre_ 是表前綴,按自己的情況修改,注意需要在 MySQL 設置相應的權限,假設 Discuz X 和 UCenter 是在不同的數據庫且不同數據庫用戶,Discuz X 數據庫和用戶是 discuz,UCenter 的數據庫和用戶是 ucenter,那么需要設置 ucenter 擁有數據庫 discuz 的 insert 權限。(如果是同一數據庫、同一用戶則忽略這些步驟)
function add_user($username, $password, $email, $uid = 0, $questionid = '', $answer = '', $regip = '') { $regip = empty($regip) ? $this->base->onlineip : $regip; $salt = substr(uniqid(rand()), -6); $password = md5(md5($password).$salt); $sqladd = $uid ? "uid='".intval($uid)."'," : ''; $sqladd .= $questionid > 0 ? " secques='".$this->quescrypt($questionid, $answer)."'," : " secques='',"; $this->db->query("INSERT INTO ".UC_DBTABLEPRE."members SET $sqladd username='$username', password='$password', email='$email', regip='$regip', regdate='".$this->base->time."', salt='$salt'"); $uid = $this->db->insert_id(); $this->db->query("INSERT INTO ".UC_DBTABLEPRE."memberfields SET uid='$uid'"); // BEGIN $this->db->query("INSERT INTO `dbname`.pre_common_member SET uid='$uid', username='$username', password='$password', email='$email', adminid='0', groupid='10', regdate='".$this->base->time."', credits='0', timeoffset='9999'"); $this->db->query("INSERT INTO `dbname`.pre_common_member_status SET uid='$uid', regip='$regip', lastip='$regip', lastvisit='".$this->base->time."', lastactivity='".$this->base->time."', lastpost='0', lastsendmail='0'"); $this->db->query("INSERT INTO `dbname`.pre_common_member_profile SET uid='$uid'"); $this->db->query("INSERT INTO `dbname`.pre_common_member_field_forum SET uid='$uid'"); $this->db->query("INSERT INTO `dbname`.pre_common_member_field_home SET uid='$uid'"); $this->db->query("INSERT INTO `dbname`.pre_common_member_count SET uid='$uid', extcredits1='0', extcredits2='0', extcredits3='0', extcredits4='0', extcredits5='0', extcredits6='0', extcredits7='0', extcredits8='0'"); // END return $uid; }其它的程序就比較簡單了,打開程序的數據庫的用戶表,對比一下就知道了,下面提供幾個參考:
// ecmall $this->db->query("INSERT INTO `ecmall`.ecm_member SET user_id='$uid', user_name='$username', email='$email', password='$password', gender='0', reg_time='".$this->base->time."', last_login='".$this->base->time."', last_ip='$regip', logins='1', ugrade='0', outer_id='0'"); // ecshop $this->db->query("INSERT INTO `ecshop`.ecs_users SET user_id='$uid', email='$email', user_name='$username', password='$password', reg_time='".$this->base->time."', last_login='".$this->base->time."', last_ip='$regip'"); // thinksns $this->db->query("INSERT INTO ts_user SET email='$email', password='$password', uname='$username', is_active='1', is_init='1'"); $tsuid = $this->db->insert_id();//獲取最新插入的thinksns的ID號 $this->db->query("INSERT INTO ts_ucenter_user_link SET uid='$tsuid', uc_uid='$uid', uc_username='$username',uc_email='$email'"); $this->db->query("INSERT INTO ts_user_online SET uid='$tsuid', ctime='".$this->base->time."'");
thinksns的index.php最開頭要加上session_start(); 不然用戶是不能同步登錄的,因為session是在thinksns里面uc通過api/uc_client/common.php文件下面的如下代碼同步的
//同步登錄ThinkSNS
function ts_synclogin($user){
session_start();
$uid = $user['uid'];
// 注冊session
$_SESSION['mid'] = intval($uid);
$_SESSION['SITE_KEY'] = ts_get_site_key();
(需要說明的是部分程序的登錄機制不同使得此方法的首次注冊同步登錄無法實現)
推薦文章
2025-01-18
2024-11-28
2024-11-09
2024-10-25
2024-06-25
2024-01-04
2023-11-06
2023-10-30
2023-10-13
2023-10-10
穩定
產品高可用性高并發貼心
項目群及時溝通專業
產品經理1v1支持快速
MVP模式小步快跑承諾
我們選擇聲譽堅持
10年專注高端品質開發