用户
 找回密码
 入住 CI 中国社区
搜索
查看: 5189|回复: 5
收起左侧

[库 Library] CI与UC整合方式----library整合

[复制链接]
发表于 2014-6-6 16:41:09 | 显示全部楼层 |阅读模式
本帖最后由 kinwyb 于 2014-6-6 16:46 编辑

     之前HEX大神就发表了CI与UC的整合方法,通过控制器来整合UC,这样只能在这个控制器中使用,存在一定的不便性。在此之前本人整合UC的方式是用一个library来实现的,没有公开共享代码,但是在HEX大神的帖子提了一句,发现已经有好几个网友来问我library的实现方式。现在我把代码发出来大家参考参考吧!

     1. UC的安装配置,我这里就不介绍了。具体参考HEX的帖子:http://codeigniter.org.cn/forums ... 17569&extra=&page=1

     2、Library代码(其实了解过UC的应该都能实现,和HEX差不多,只不过把代码移动到了library里)
  
PHP复制代码
<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Ucapi
{
    function __construct()
    {
        include_once './config.inc.php';
        include_once './uc_client/client.php';
    }
   
    function check_login()
    {
        if(!empty($_COOKIE['minpin_auth'])) {
            list($user['uid'], $user['username']) = explode("\t", uc_authcode($_COOKIE['minpin_auth'], 'DECODE'));
        } else {
            $user['uid'] = $user['username'] = '';
        }
        !empty($user['username']) AND $user['username']=iconv('gbk', 'utf-8', $user['username']);
        return $user;
    }
   
    function user_info($id)
    {
        $r=uc_get_user($id,1);
        $r[0]?$user['uid']=$r[0]:$user['uid']='';
        $r[1]?$user['username']=iconv("gbk","utf-8",$r[1]):$user['username']='';
        $r[2]?$user['email']=$r[2]:$user['email']='';
        $user['litpic']=UC_API.'/avatar.php?uid='.$id;
        $user['home']=UCENTER_URL.'/home.php?mod=space&uid='.$id;
        $user['pm_url']= uc_pm_location_url($id);
        $user['newpm'] = uc_pm_checknew($id);
        return $user;
    }
   
    function checkname($username)
    {
        $username=iconv('utf-8', 'gbk', $username);
        return uc_user_checkname($username);
    }
   
    function checkemail($email)
    {
        return uc_user_checkemail($email);
    }
   
    function synlogin($uid)
    {
        return uc_user_synlogin($uid);
    }
   
    function register($username,$password,$email)
    {
        $username=iconv('utf-8', 'gbk', $username);
        return uc_user_register($username,$password,$email);
    }
   
    function synlogout($uid)
    {
        return uc_user_synlogout($uid);
    }
   
    function login($username,$password)
    {
        $username=iconv('utf-8', 'gbk', $username);
        return uc_user_login($username, $password);
    }
   
    function uc_get_user($username)
    {
        $username=iconv('utf-8', 'gbk', $username);
        $username=uc_get_user($username);
        $username[1]=iconv('gbk', 'utf-8', $username[1]);
        return $username;
    }
   
    function uc_user_edit($username,$password)
    {
        $username=iconv('utf-8', 'gbk', $username);
        return uc_user_edit($username,"123",$password,"",1);
    }
}
复制代码

注:文件存放路径===在与应用的index.php同目录下,添加:uc_client及先关的文件。config.inc.php 配置文件。

     3.调用方式:和普通的library调用方式一样。
PHP复制代码
 
$this->load->library("ucapi");
//用户登入返回数组
$this->ucapi->login($username, $password);
//同步登入(UC会返回一串js代码,把js代码添加到页面,运行js实现同步登入。)
$ucsynlogin = $this->ucapi->synlogin($row['ucuid']);
echo $ucsynlogin;
 
复制代码

上面是简单的调用介绍。。具体UC功能,参考UC文档。。

Library的好处就是可以随便调用。。。。上面代码仅供参。不同环境可能会存在差异,比如(此代码中存在编码转换,但UC版本也是UTF8的时候这就不需要了)。

评分

参与人数 1威望 +5 收起 理由
Hex + 5 赞一个!

查看全部评分

发表于 2014-6-11 15:51:59 | 显示全部楼层
水平有限,用你这个也没有成功
发表于 2014-6-11 15:52:14 | 显示全部楼层
还是要谢谢
发表于 2014-7-1 08:46:30 | 显示全部楼层
这种方法在ucenter里面配置应用时的URL怎么填写呀
请大侠指点
 楼主| 发表于 2014-7-3 08:56:32 | 显示全部楼层
bai615 发表于 2014-7-1 08:46
这种方法在ucenter里面配置应用时的URL怎么填写呀
请大侠指点

正常填写主url就可以了。
发表于 2014-9-4 23:26:12 | 显示全部楼层
具体测试的时候遇到了如下问题:

        include_once './config.inc.php';
        include_once './uc_client/client.php';

这句include正确吗?model里正确的语句是:

include APPPATH.'config/ucenter.php';
include APPPATH.'../client/ucenter.php';

本版积分规则