首页 > 电脑专区 > 互联网 >

ucenter使用教程

来源:互联网 2023-03-02 15:39:18 253

UCenter 的中文意思就是“用户中心”,其中的 U 代表 User 也代表 You ,取其中的含义就是“用户中心”,或者说“你(最终用户)的中心”。 UCenter 是 Comsenz 旗下各个产品之间信息直接传递的一个桥梁,通过 UCenter站长可以无缝整合 Comsenz 系列产品,实现用户的一站式注册、登录、退出以及社区其他数据的交互的php框架。VWL办公区 - 实用经验教程分享!

ucenter使用教程VWL办公区 - 实用经验教程分享!

工具/原料

  • 电脑 互联网 UCenter

方法/步骤

  • 1

    下载相应的软件VWL办公区 - 实用经验教程分享!

    CodeIgniter 2.1.4VWL办公区 - 实用经验教程分享!

    UCenter 1.6.0VWL办公区 - 实用经验教程分享!

    Discuz! X3VWL办公区 - 实用经验教程分享!

    简体 UTF-8,可以不下载 Discuz!,这里只是用来最后检验同步登录/登出是否成功。VWL办公区 - 实用经验教程分享!

    前置条件VWL办公区 - 实用经验教程分享!

    项目目录结构如下VWL办公区 - 实用经验教程分享!

    搭建服务器VWL办公区 - 实用经验教程分享!

    根目录指向 codeIgniter-ucenterVWL办公区 - 实用经验教程分享!

    我设置了 hostsVWL办公区 - 实用经验教程分享!

    127.0.0.1 ci.connect.ucVWL办公区 - 实用经验教程分享!

    这个任意的,这里只是为了突出主题。VWL办公区 - 实用经验教程分享!

    ucenter使用教程VWL办公区 - 实用经验教程分享!

  • 2

    开始集成VWL办公区 - 实用经验教程分享!

    VWL办公区 - 实用经验教程分享!

    安装 UcenterVWL办公区 - 实用经验教程分享!

    访问http://ci.connect.uc/uc,按照向导安装即可。VWL办公区 - 实用经验教程分享!

    VWL办公区 - 实用经验教程分享!

    安装 Discuz!XVWL办公区 - 实用经验教程分享!

    访问http://ci.connect.uc/discuz,按照向导,第二步时候选择只安装 Discuz!X,如下图,信息填写uc的安装信息VWL办公区 - 实用经验教程分享!

    配置 CodeIgniterVWL办公区 - 实用经验教程分享!

    配置 application/config.php, 为使用 Session 类,需要设置 encryption_key,值任意。VWL办公区 - 实用经验教程分享!

    $config['encryption_key'] = sha1('whatever it is!');VWL办公区 - 实用经验教程分享!

    修改默认控制器 welcome.php 如下:VWL办公区 - 实用经验教程分享!

    ?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class Welcome extends CI_Controller { public function index() { $this->load->library('session'); $data['user'] = $this->session->userdata('user'); $this->load->view('welcome_message', $data); } }VWL办公区 - 实用经验教程分享!

    VWL办公区 - 实用经验教程分享!

    修改 views/welcome_message.php 中的div#container如下:VWL办公区 - 实用经验教程分享!

    div id="container"> h1>Welcome to CodeIgniter!/h1> div id="body"> ?php if ($user): ?> 欢迎你, ?php echo $user['username']; ?>到a target="_blank" href="http://ci.connect.uc/discuz">DiscuzX/a>退出后再刷新这个页面吧!/ ?php else: ?> 尚未登录,到a target="_blank" href="http://ci.connect.uc/discuz">DiscuzX/a>登录后再刷新这个页面吧!/ ?php endif; ?> /div> p class="footer">Page rendered in strong>0.0455/strong> seconds//div>VWL办公区 - 实用经验教程分享!

    VWL办公区 - 实用经验教程分享!

    VWL办公区 - 实用经验教程分享!

    VWL办公区 - 实用经验教程分享!

    VWL办公区 - 实用经验教程分享!

    ucenter使用教程VWL办公区 - 实用经验教程分享!

    ucenter使用教程VWL办公区 - 实用经验教程分享!

  • 3

    在 UCenter 中添加新应用VWL办公区 - 实用经验教程分享!

    在 CI 目录 application/config/ 目录下新建文件 ucenter.phpVWL办公区 - 实用经验教程分享!

    内容为 UCenter 为新加应用生成的配置文件VWL办公区 - 实用经验教程分享!

    ?php define('UC_CONNECT', 'mysql'); define('UC_DBHOST', 'localhost'); define('UC_DBUSER', 'root'); define('UC_DBPW', 'root'); define('UC_DBNAME', 'ucenter'); define('UC_DBCHARSET', 'utf8'); define('UC_DBTABLEPRE', '`ucenter`.uc_'); define('UC_DBCONNECT', '0'); define('UC_KEY', 'whatever you wanna set!'); define('UC_API', 'http://ci.connect.uc/uc'); define('UC_CHARSET', 'utf-8'); define('UC_IP', ''); define('UC_APPID', '2'); define('UC_PPP', '20');VWL办公区 - 实用经验教程分享!

    从 UCenter 安装包中复制 uc_client 到 CI 根目录VWL办公区 - 实用经验教程分享!

    VWL办公区 - 实用经验教程分享!

    新增控制器 api/uc.phpVWL办公区 - 实用经验教程分享!

    内容如下:VWL办公区 - 实用经验教程分享!

    ?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');/*** Ucenter接口通知处理控制器** 本类根据ucenter提供的通知处理实例代码编写,具体处理部分需要根据不同应用的逻辑自行编写处理逻辑。* 具体请仔细阅读ucenter自带的手册。** @author chekun 234267695@qq.com>*/class Uc extends CI_Controller{ const UC_CLIENT_RELEASE = '20110501'; const UC_CLIENT_VERSION = '1.6.0'; const API_DELETEUSER = 1; const API_RENAMEUSER = 1; const API_GETTAG = 1; const API_SYNLOGIN = 1; const API_SYNLOGOUT = 1; const API_UPDATEPW = 1; const API_UPDATEBADWORDS = 1; const API_UPDATEHOSTS = 1; const API_UPDATEAPPS = 1; const API_UPDATECLIENT = 1; const API_UPDATECREDIT = 1; const API_GETCREDITSETTINGS = 1; const API_GETCREDIT = 1; const API_UPDATECREDITSETTINGS = 1; const API_RETURN_SUCCEED = 1; const API_RETURN_FAILED = -1; const API_RETURN_FORBIDDEN = -2; public function index() { include APPPATH.'config/ucenter.php'; $get = $post = array(); $code = $this->input->get('code', true); parse_str(self::authcode($code, 'DECODE', UC_KEY), $get); $timestamp = time(); if ($timestamp - $get['time'] > 3600) { echo '授权已过期'; return; } if (empty($get)) { echo '非法请求'; return; } $post = self::unserialize(file_get_contents('php://input')); if (in_array($get['action'], array( 'test', 'deleteuser', 'renameuser', 'gettag', 'synlogin', 'synlogout', 'updatepw', 'updatebadwords', 'updatehosts', 'updateapps', 'updateclient', 'updatecredit', 'getcreditsettings', 'updatecreditsettings'))) { echo $this->$get['action']($get, $post); return; } else { echo self::API_RETURN_FAILED; return; } } private function test($get, $post) { return self::API_RETURN_SUCCEED; } private function deleteuser($get, $post) { if ( ! self::API_DELETEUSER) { return self::API_RETURN_FORBIDDEN; } $uids = $get['ids']; //delete your users here return self::API_RETURN_SUCCEED; } private function gettag($get, $post) { if ( ! self::API_GETTAG) { return self::API_RETURN_FORBIDDEN; } // return self::API_RETURN_SUCCEED; } private function synlogin($get, $post) { if ( ! self::API_SYNLOGIN) { return self::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"'); $uid = $get['uid']; //同步登录的代码在这里处理 include APPPATH.'../uc_client/client.php'; if ($uc_user = uc_get_user($uid, 1)) { $this->load->library('session'); $this->session->set_userdata('user', array( 'uid' => $uid, 'username' => $uc_user[1] )); } return self::API_RETURN_SUCCEED; } private function synlogout($get, $post) { if ( ! self::API_SYNLOGOUT) { return self::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"'); $this->load->library('session'); $this->session->sess_destroy(); return self::API_RETURN_SUCCEED; } private function updatepw($get, $post) { if ( ! self::API_UPDATEPW) { return self::API_RETURN_FORBIDDEN; } //这里做修改密码操作 return self::API_RETURN_SUCCEED; } private function updatebadwords($get, $post) { if ( ! self::API_UPDATEBADWORDS) { return self::API_RETURN_FORBIDDEN; } $cachefile = APPPATH.'../uc_client/data/cache/badwords.php'; @unlink($cachefile); return self::API_RETURN_SUCCEED; } private function updatehosts($get, $post) { if ( ! self::API_UPDATEHOSTS) { return self::API_RETURN_FORBIDDEN; } $cachefile = APPPATH.'../uc_client/data/cache/hosts.php'; @unlink($cachefile); return self::API_RETURN_SUCCEED; } private function updateapps($get, $post) { if ( ! self::API_UPDATEAPPS) { return self::API_RETURN_FORBIDDEN; } $cachefile = APPPATH.'../uc_client/data/cache/apps.php'; @unlink($cachefile); return self::API_RETURN_SUCCEED; } private function updateclient($get, $post) { if ( ! self::API_UPDATECLIENT) { return self::API_RETURN_FORBIDDEN; } $cachefile = APPPATH.'../uc_client/data/cache/settings.php'; @unlink($cachefile); return self::API_RETURN_SUCCEED; } private function updatecredit($get, $post) { if ( ! self::API_UPDATECREDIT) { return self::API_RETURN_FORBIDDEN; } return self::API_RETURN_SUCCEED; } private function getcredit($get, $post) { if ( ! self::API_GETCREDIT) { return self::API_RETURN_FORBIDDEN; } return self::API_RETURN_SUCCEED; } public static function authcode($string, $operation = 'DECODE', $key = '', $expiry = 0) { $ckey_length = 4; $key = md5($key ? $key : UC_KEY); $keya = md5(substr($key, 0, 16)); $keyb = md5(substr($key, 16, 16)); $keyc = $ckey_length ? ($operation == 'DECODE' ? substr($string, 0, $ckey_length): substr(md5(microtime()), -$ckey_length)) : ''; $cryptkey = $keya.md5($keya.$keyc); $key_length = strlen($cryptkey); $string = $operation == 'DECODE' ? base64_decode(substr($string, $ckey_length)) : sprintf('0d', $expiry ? $expiry time() : 0).substr(md5($string.$keyb), 0, 16).$string; $string_length = strlen($string); $result = ''; $box = range(0, 255); $rndkey = array(); for($i = 0; $i = 255; $i ) { $rndkey[$i] = ord($cryptkey[$i % $key_length]); } for($j = $i = 0; $i 256; $i ) { $j = ($j $box[$i] $rndkey[$i]) % 256; $tmp = $box[$i]; $box[$i] = $box[$j]; $box[$j] = $tmp; } for($a = $j = $i = 0; $i $string_length; $i ) { $a = ($a 1) % 256; $j = ($j $box[$a]) % 256; $tmp = $box[$a]; $box[$a] = $box[$j]; $box[$j] = $tmp; $result .= chr(ord($string[$i]) ^ ($box[($box[$a] $box[$j]) % 256])); } if($operation == 'DECODE') { if((substr($result, 0, 10) == 0 || substr($result, 0, 10) - time() > 0) && substr($result, 10, 16) == substr(md5(substr($result, 26).$keyb), 0, 16)) { return substr($result, 26); } else { return ''; } } else { return $keyc.str_replace('=', '', base64_encode($result)); } } public static function serialize($arr, $htmlOn = 0) { if ( ! function_exists('xml_serialize')) { require APPPATH.'../uc_client/lib/xml.class.php'; } return xml_serialize($arr, $htmlOn); } public static function unserialize($xml, $htmlOn = 0) { if ( ! function_exists('xml_serialize')) { require APPPATH.'../uc_client/lib/xml.class.php'; } return xml_unserialize($xml, $htmlOn); } public static function gbk2utf8($string) { return iconv("GB2312", "UTF-8//IGNORE", $string); } public static function utf82gbk($string) { return iconv("UTF-8", "GB2312//IGNORE", $string); }}VWL办公区 - 实用经验教程分享!

    VWL办公区 - 实用经验教程分享!

    ucenter使用教程VWL办公区 - 实用经验教程分享!

  • 4

    运行VWL办公区 - 实用经验教程分享!

    VWL办公区 - 实用经验教程分享!

    打开http://ci.connect.uc/ciVWL办公区 - 实用经验教程分享!

    VWL办公区 - 实用经验教程分享!

    VWL办公区 - 实用经验教程分享!

    点击页面链接进行登录操作VWL办公区 - 实用经验教程分享!

    刷新即可看到已登录VWL办公区 - 实用经验教程分享!

    ucenter使用教程VWL办公区 - 实用经验教程分享!

    ucenter使用教程VWL办公区 - 实用经验教程分享!

    ucenter使用教程VWL办公区 - 实用经验教程分享!

    ucenter使用教程VWL办公区 - 实用经验教程分享!

  • 5

    点击页面链接进行退出操作VWL办公区 - 实用经验教程分享!

    再次刷新即可看到已退出VWL办公区 - 实用经验教程分享!

    ucenter使用教程VWL办公区 - 实用经验教程分享!

    ucenter使用教程VWL办公区 - 实用经验教程分享!

  • 以上方法由办公区教程网编辑摘抄自百度经验可供大家参考!VWL办公区 - 实用经验教程分享!


    标签: 软件互联网

    办公区 Copyright © 2016-2023 www.bgqu.net. Some Rights Reserved. 备案号:湘ICP备2020019561号统计代码