用了Discuz和Ucenter,在自己的程序注册并自动登录,却没有同步登录Discuz。 //测试版本:discuz! x3 理论也支持2.5//打开discuz/api/uc.php //synlogin方法(180行)处,往下找到 if(($member = getuserby
//测试版本:discuz! x3 理论也支持2.5 //打开discuz/api/uc.php //synlogin方法(180行)处,往下找到 if(($member = getuserbyuid($uid, 1))) { dsetcookie('auth', authcode("$member[password]\t$member[uid]", 'ENCODE'), $cookietime); } //改为 if(($member = getuserbyuid($uid, 1))) { dsetcookie('auth', authcode("$member[password]\t$member[uid]", 'ENCODE'), $cookietime); } else { if(!function_exists('uc_get_user')) { loaducenter(); } $user = uc_get_user($uid, 1); if($user) { $time = time(); DB::query("REPLACE INTO ".DB::table('common_member')." SET `uid`='{$user[0]}' , `username`='{$user[1]}' , `password`='".md5(random(10))."' , `email`='{$user[2]}' , `adminid`='0' , `groupid`='10' , `regdate`='{$time}' , `emailstatus`='0' , `credits`='0' , `timeoffset`='9999'"); DB::query("REPLACE INTO ".DB::table('common_member_status')." SET `uid`='{$user[0]}' , `regip`='{$_G['clientip']}' , `lastip`='{$_G['clientip']}' , `lastvisit`='{$time}' , `lastactivity`='' , `lastpost`='0' , `lastsendmail`='0'"); DB::query("REPLACE INTO ".DB::table('common_member_count')." SET `uid`='{$user[0]}' , `extcredits1`='0' , `extcredits2`='0' , `extcredits3`='0' , `extcredits4`='0' , `extcredits5`='0' , `extcredits6`='0' , `extcredits7`='0' , `extcredits8`='0'"); DB::query("REPLACE INTO ".DB::table('common_member_profile')." SET `uid`='{$user[0]}'"); DB::query("REPLACE INTO ".DB::table('common_member_field_forum')." SET `uid`='{$user[0]}'"); DB::query("REPLACE INTO ".DB::table('common_member_field_home')." SET `uid`='{$user[0]}'"); DB::query("UPDATE ".DB::table('common_stat')." SET `register`=`register`+1 WHERE `daytime` = '".date('Ymd', $time)."'"); if(($member = getuserbyuid($uid, 1))) { dsetcookie('auth', authcode("$member[password]\t$member[uid]", 'ENCODE'), $cookietime); } } }uc.php
init(); require DISCUZ_ROOT.'./config/config_ucenter.php'; $get = $post = array(); $code = @$_GET['code']; parse_str(authcode($code, 'DECODE', UC_KEY), $get); if(time() - $get['time'] > 3600) { exit('Authracation has expiried'); } if(empty($get)) { exit('Invalid Request'); } include_once DISCUZ_ROOT.'./uc_client/lib/xml.class.php'; $post = xml_unserialize(file_get_contents('php://input')); if(in_array($get['action'], array('test', 'deleteuser', 'renameuser', 'gettag', 'synlogin', 'synlogout', 'updatepw', 'updatebadwords', 'updatehosts', 'updateapps', 'updateclient', 'updatecredit', 'getcredit', 'getcreditsettings', 'updatecreditsettings', 'addfeed'))) { $uc_note = new uc_note(); echo call_user_func(array($uc_note, $get['action']), $get, $post); echo 2222; exit(); } else { exit(API_RETURN_FAILED); } } else { exit; } class uc_note { var $dbconfig = ''; var $db = ''; var $tablepre = ''; var $appdir = ''; function _serialize($arr, $htmlon = 0) { if(!function_exists('xml_serialize')) { include_once DISCUZ_ROOT.'./uc_client/lib/xml.class.php'; } return xml_serialize($arr, $htmlon); } function _construct() { } function test($get, $post) { return API_RETURN_SUCCEED; } function deleteuser($get, $post) { global $_G; if(!API_DELETEUSER) { return API_RETURN_FORBIDDEN; } $uids = str_replace("'", '', stripslashes($get['ids'])); $ids = array(); $ids = array_keys(C::t('common_member')->fetch_all($uids)); require_once DISCUZ_ROOT.'./source/function/function_delete.php'; $ids && deletemember($ids); return API_RETURN_SUCCEED; } function renameuser($get, $post) { global $_G; if(!API_RENAMEUSER) { return API_RETURN_FORBIDDEN; } $tables = array( 'common_block' => array('id' => 'uid', 'name' => 'username'), 'common_invite' => array('id' => 'fuid', 'name' => 'fusername'), 'common_member_verify_info' => array('id' => 'uid', 'name' => 'username'), 'common_mytask' => array('id' => 'uid', 'name' => 'username'), 'common_report' => array('id' => 'uid', 'name' => 'username'), 'forum_thread' => array('id' => 'authorid', 'name' => 'author'), 'forum_activityapply' => array('id' => 'uid', 'name' => 'username'), 'forum_groupuser' => array('id' => 'uid', 'name' => 'username'), 'forum_pollvoter' => array('id' => 'uid', 'name' => 'username'), 'forum_post' => array('id' => 'authorid', 'name' => 'author'), 'forum_postcomment' => array('id' => 'authorid', 'name' => 'author'), 'forum_ratelog' => array('id' => 'uid', 'name' => 'username'), 'home_album' => array('id' => 'uid', 'name' => 'username'), 'home_blog' => array('id' => 'uid', 'name' => 'username'), 'home_clickuser' => array('id' => 'uid', 'name' => 'username'), 'home_docomment' => array('id' => 'uid', 'name' => 'username'), 'home_doing' => array('id' => 'uid', 'name' => 'username'), 'home_feed' => array('id' => 'uid', 'name' => 'username'), 'home_feed_app' => array('id' => 'uid', 'name' => 'username'), 'home_friend' => array('id' => 'fuid', 'name' => 'fusername'), 'home_friend_request' => array('id' => 'fuid', 'name' => 'fusername'), 'home_notification' => array('id' => 'authorid', 'name' => 'author'), 'home_pic' => array('id' => 'uid', 'name' => 'username'), 'home_poke' => array('id' => 'fromuid', 'name' => 'fromusername'), 'home_share' => array('id' => 'uid', 'name' => 'username'), 'home_show' => array('id' => 'uid', 'name' => 'username'), 'home_specialuser' => array('id' => 'uid', 'name' => 'username'), 'home_visitor' => array('id' => 'vuid', 'name' => 'vusername'), 'portal_article_title' => array('id' => 'uid', 'name' => 'username'), 'portal_comment' => array('id' => 'uid', 'name' => 'username'), 'portal_topic' => array('id' => 'uid', 'name' => 'username'), 'portal_topic_pic' => array('id' => 'uid', 'name' => 'username'), ); if(!C::t('common_member')->update($get['uid'], array('username' => $get[newusername])) && isset($_G['setting']['membersplit'])){ C::t('common_member_archive')->update($get['uid'], array('username' => $get[newusername])); } loadcache("posttableids"); if($_G['cache']['posttableids']) { foreach($_G['cache']['posttableids'] AS $tableid) { $tables[getposttable($tableid)] = array('id' => 'authorid', 'name' => 'author'); } } foreach($tables as $table => $conf) { DB::query("UPDATE ".DB::table($table)." SET `$conf[name]`='$get[newusername]' WHERE `$conf[id]`='$get[uid]'"); } return API_RETURN_SUCCEED; } function gettag($get, $post) { global $_G; if(!API_GETTAG) { return API_RETURN_FORBIDDEN; } return $this->_serialize(array($get['id'], array()), 1); } function synlogin($get, $post) { global $_G; if(!API_SYNLOGIN) { return API_RETURN_FORBIDDEN; } header('P3P: CP="CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR"'); $cookietime = 31536000; $uid = intval($get['uid']); if(($member = getuserbyuid($uid, 1))) { dsetcookie('auth', authcode("$member[password]\t$member[uid]", 'ENCODE'), $cookietime); }else { if(!function_exists('uc_get_user')) { loaducenter(); } $user = uc_get_user($uid, 1); if($user) { $time = time(); DB::query("REPLACE INTO ".DB::table('common_member')." SET `uid`='{$user[0]}' , `username`='{$user[1]}' , `password`='".md5(random(10))."' , `email`='{$user[2]}' , `adminid`='0' , `groupid`='10' , `regdate`='{$time}' , `emailstatus`='0' , `credits`='0' , `timeoffset`='9999'"); DB::query("REPLACE INTO ".DB::table('common_member_status')." SET `uid`='{$user[0]}' , `regip`='{$_G['clientip']}' , `lastip`='{$_G['clientip']}' , `lastvisit`='{$time}' , `lastactivity`='' , `lastpost`='0' , `lastsendmail`='0'"); DB::query("REPLACE INTO ".DB::table('common_member_count')." SET `uid`='{$user[0]}' , `extcredits1`='0' , `extcredits2`='0' , `extcredits3`='0' , `extcredits4`='0' , `extcredits5`='0' , `extcredits6`='0' , `extcredits7`='0' , `extcredits8`='0'"); DB::query("REPLACE INTO ".DB::table('common_member_profile')." SET `uid`='{$user[0]}'"); DB::query("REPLACE INTO ".DB::table('common_member_field_forum')." SET `uid`='{$user[0]}'"); DB::query("REPLACE INTO ".DB::table('common_member_field_home')." SET `uid`='{$user[0]}'"); DB::query("UPDATE ".DB::table('common_stat')." SET `register`=`register`+1 WHERE `daytime` = '".date('Ymd', $time)."'"); if(($member = getuserbyuid($uid, 1))) { dsetcookie('auth', authcode("$member[password]\t$member[uid]", 'ENCODE'), $cookietime); } } } } function synlogout($get, $post) { global $_G; if(!API_SYNLOGOUT) { return API_RETURN_FORBIDDEN; } header('P3P: CP="CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR"'); dsetcookie('auth', '', -31536000); } function updatepw($get, $post) { global $_G; if(!API_UPDATEPW) { return API_RETURN_FORBIDDEN; } $username = $get['username']; $newpw = md5(time().rand(100000, 999999)); $uid = 0; if(($uid = C::t('common_member')->fetch_uid_by_username($username))) { $ext = ''; } elseif(($uid = C::t('common_member_archive')->fetch_uid_by_username($username))) { $ext = '_archive'; } if($uid) { C::t('common_member'.$ext)->update($uid, array('password' => $newpw)); } return API_RETURN_SUCCEED; } function updatebadwords($get, $post) { global $_G; if(!API_UPDATEBADWORDS) { return API_RETURN_FORBIDDEN; } $data = array(); if(is_array($post)) { foreach($post as $k => $v) { if(substr($v['findpattern'], 0, 1) != '/' || substr($v['findpattern'], -3) != '/is') { $v['findpattern'] = '/' . preg_quote($v['findpattern'], '/') . '/is'; } $data['findpattern'][$k] = $v['findpattern']; $data['replace'][$k] = $v['replacement']; } } $cachefile = DISCUZ_ROOT.'./uc_client/data/cache/badwords.php'; $fp = fopen($cachefile, 'w'); $s = " ' ? substr($configfile, 0, -2) : $configfile; $configfile = preg_replace("/define\('UC_API',\s*'.*?'\);/i", "define('UC_API', '".addslashes($UC_API)."');", $configfile); if($fp = @fopen(DISCUZ_ROOT.'./config/config_ucenter.php', 'w')) { @fwrite($fp, trim($configfile)); @fclose($fp); } } } return API_RETURN_SUCCEED; } function updateclient($get, $post) { global $_G; if(!API_UPDATECLIENT) { return API_RETURN_FORBIDDEN; } $cachefile = DISCUZ_ROOT.'./uc_client/data/cache/settings.php'; $fp = fopen($cachefile, 'w'); $s = " $amount)); C::t('common_credit_log')->insert(array('uid' => $uid, 'operation' => 'ECU', 'relatedid' => $uid, 'dateline' => time(), 'extcredits'.$credit => $amount)); return API_RETURN_SUCCEED; } function getcredit($get, $post) { global $_G; if(!API_GETCREDIT) { return API_RETURN_FORBIDDEN; } $uid = intval($get['uid']); $credit = intval($get['credit']); $_G['uid'] = $_G['member']['uid'] = $uid; return getuserprofile('extcredits'.$credit); } function getcreditsettings($get, $post) { global $_G; if(!API_GETCREDITSETTINGS) { return API_RETURN_FORBIDDEN; } $credits = array(); foreach($_G['setting']['extcredits'] as $id => $extcredits) { $credits[$id] = array(strip_tags($extcredits['title']), $extcredits['unit']); } return $this->_serialize($credits); } function updatecreditsettings($get, $post) { global $_G; if(!API_UPDATECREDITSETTINGS) { return API_RETURN_FORBIDDEN; } $outextcredits = array(); foreach($get['credit'] as $appid => $credititems) { if($appid == UC_APPID) { foreach($credititems as $value) { $outextcredits[$value['appiddesc'].'|'.$value['creditdesc']] = array( 'appiddesc' => $value['appiddesc'], 'creditdesc' => $value['creditdesc'], 'creditsrc' => $value['creditsrc'], 'title' => $value['title'], 'unit' => $value['unit'], 'ratiosrc' => $value['ratiosrc'], 'ratiodesc' => $value['ratiodesc'], 'ratio' => $value['ratio'] ); } } } $tmp = array(); foreach($outextcredits as $value) { $key = $value['appiddesc'].'|'.$value['creditdesc']; if(!isset($tmp[$key])) { $tmp[$key] = array('title' => $value['title'], 'unit' => $value['unit']); } $tmp[$key]['ratiosrc'][$value['creditsrc']] = $value['ratiosrc']; $tmp[$key]['ratiodesc'][$value['creditsrc']] = $value['ratiodesc']; $tmp[$key]['creditsrc'][$value['creditsrc']] = $value['ratio']; } $outextcredits = $tmp; $cachefile = DISCUZ_ROOT.'./uc_client/data/cache/creditsettings.php'; $fp = fopen($cachefile, 'w'); $s = "