codeigniter集成ucenter1.6双向通信的解决办法

2019-11-16,,,,

用codeigniter开发一个子网站,之后想和原来的论坛进行同步,包括同步登陆和双向通信


先装好ucenter,然后新建一个other的应用,把生成的代码拷出来,新建一个config.ini.php到你的uc_client,ucenter会产生一个yourdomain.com/api/uc.php的请求,/api/uc.php不需要填写,要保证ucenter请求正确位置,才能做到双向通信


把uc_client复制到你的网站,目录可以自己定,就根目录吧。如果你把api目录放到uc_client目录低下,那么应用的请求路径yourdomain.com/uc_client,如果api也放在根目录请求地址uc_client可以去掉


建一个libraries/Ucenter.php内容是


复制代码 代码如下:<?php
class Ucenter {
    function __construct() {
        require_once FCPATH . './api/uc_client/config.inc.php';
        require_once FCPATH . './api/uc_client/client.php';
    }


    function getUserId() {
        return $this->_uid;
    }


    function getUserName() {
        return ucwords(strtolower($this->_username));
    }


    function login($username, $password) {
        return uc_user_login($username, $password);
    }
    function synlogin($uid) {
        return uc_user_synlogin($uid);
    }


    function login_out() {
        return uc_user_synlogout();
    }


    function regediter($username, $password, $email) {
        return uc_user_register($username, $password, $email);
    }
}
?>


具体要反回哪些函数,可以在上面代码加上,可以打开uc_client/client.php看,可以加上你需要的函数,返回即可。


调用方法:


复制代码 代码如下:$username = $this->input->post('username');
$password = $this->input->post('password');
$this->load->library('ucenter');
list($uid, $username, $password, $email) = $this->ucenter->login($username, $password);
if(!empty($uid)){
    //生成同步登录的代码
    $ucsynlogin = $this->ucenter->synlogin($uid);
}

《codeigniter集成ucenter1.6双向通信的解决办法.doc》

下载本文的Word格式文档,以方便收藏与打印。