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或用户名处理注册,登陆本应用
}
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的问题
标签: thinkphpdiscuzucenter论坛同步