Thinkphp整合ucenter同步登录注册退出

Thinkphp整合ucenter完全可以双向同步登陆、退出、删用户、自动激活DZX用户、发消失、推动态、改密码等的。
ucente同步登陆演试,比如把下面的代码放到你网站的登陆控制器里
$uc = new \Ucenter\Client\UcApi(); 
$uc_user = $uc->uc_get_user($user['username'], 0); //根据用户名检查用户是否存在 
if ($uc_user['0'] > 0) { 
$uc_uid = $uc_user['0']; //记录用户uid 
} else { 
$uc_uid = $uc->uc_user_register($user['username'], '12345678', $user['email'] ? $user['email'] : $uid . '@qq.com'); //注册用户 

if ($uc_uid > 0) { 
echo $uc->uc_user_synlogin($uc_uid); //同步登陆;一定要输出这段代码,你可以跳转时输出$this->success($uc->uc_user_synlogin($uc_uid)); 
} else { 
//todo 错误自己写 


/*ucente同步退出演试,比如把下面的代码放到你网站的退出控制器里*/ 
$uc = new \Ucenter\Client\UcApi(); 
echo $uc->uc_user_synlogout(); //同步退出;一定要输出这段代码,你可以跳转时输出$this->success($uc->uc_user_synlogout()); 



++++++++++++++++++++++++++++++++++++++++++++++其它应用同步登陆、同步退出到本应用+++++++++++++++++++++++++++++++++++++++++++ 
手册地址:http://faq.comsenz.com/library/UCenter/api/api_index.htm 
原理:其它应用登陆、退出、发消息等,都会触发本应用Ucenter\Controller\ApiController.class.php里相应的事件函数,所以你只需要在这个文件里添加你要登陆、退出到本应用的代码就可以了 
比如其它应用登陆时,会触发ApiController.class.php里的synlogin函数,同时会将其它应用的UID和用户名都传过来 

//里面的函数如下 
private function synlogin($get, $post) { 
$uid = intval($get['uid']); 
$username = $get['username']; 
//自己根据UID或用户名处理注册,登陆本应用 
}
DZX自动激活方法.txt
打开discuz/api/uc.php,然后找到:
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); 


}
ucenter 验证码cccc 和出现通信不稳定
若是ucenter通信不稳定的话,时而失败,时而成功 
那可能是你的服务器配置问题(字符串中的 空格 自动转换成 “+”) 
更改方法 
步骤一: 
/source/function/function_core.php 
138行中 
function authcode($string, $operation = 'DECODE', $key = '', $expiry = 0) { 
//添加代码: 
$string=rawurldecode(str_replace(" ","+",$string)); 
步骤二: 
/uc_server/model/base.php 
145行中 
function authcode($string, $operation = 'DECODE', $key = '', $expiry = 0) { 
//添加代码: 
$string=rawurldecode(str_replace(" ","+",$string)); 

这样就可以让 + 改成空格 
也会解决ucenter 验证码 cccc的问题

资源、代码下载:http://www.erdangjiade.com/js/829.html

转载于:https://my.oschina.net/u/3200119/blog/818950

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值