页面发送信息01在网易搜寻里输出qq内部空间,找出官方网站步入。 02步入后,若是笔记本电脑发送信息有qq,会自动检测,弹出方便快捷发送信息,点选两个要发送信息的qq。 ......
2023-10-24 170
UCenter 的中文意思就是“用户中心”,其中的 U 代表 User 也代表 You ,取其中的含义就是“用户中心”,或者说“你(最终用户)的中心”。 UCenter 是 Comsenz 旗下各个产品之间信息直接传递的一个桥梁,通过 UCenter站长可以无缝整合 Comsenz 系列产品,实现用户的一站式注册、登录、退出以及社区其他数据的交互的php框架。
下载相应的软件
CodeIgniter 2.1.4
UCenter 1.6.0
Discuz! X3
简体 UTF-8,可以不下载 Discuz!,这里只是用来最后检验同步登录/登出是否成功。
前置条件
项目目录结构如下
搭建服务器
根目录指向 codeIgniter-ucenter
我设置了 hosts
127.0.0.1 ci.connect.uc
这个任意的,这里只是为了突出主题。
开始集成
安装 Ucenter
访问http://ci.connect.uc/uc,按照向导安装即可。
安装 Discuz!X
访问http://ci.connect.uc/discuz,按照向导,第二步时候选择只安装 Discuz!X,如下图,信息填写uc的安装信息
配置 CodeIgniter
配置 application/config.php, 为使用 Session 类,需要设置 encryption_key,值任意。
$config['encryption_key'] = sha1('whatever it is!');
修改默认控制器 welcome.php 如下:
?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); } }
修改 views/welcome_message.php 中的div#container如下:
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>
在 UCenter 中添加新应用
在 CI 目录 application/config/ 目录下新建文件 ucenter.php
内容为 UCenter 为新加应用生成的配置文件
?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');
从 UCenter 安装包中复制 uc_client 到 CI 根目录
新增控制器 api/uc.php
内容如下:
?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); }}
运行
打开http://ci.connect.uc/ci
点击页面链接进行登录操作
刷新即可看到已登录
点击页面链接进行退出操作
再次刷新即可看到已退出
以上方法由办公区教程网编辑摘抄自百度经验可供大家参考!
相关文章
页面发送信息01在网易搜寻里输出qq内部空间,找出官方网站步入。 02步入后,若是笔记本电脑发送信息有qq,会自动检测,弹出方便快捷发送信息,点选两个要发送信息的qq。 ......
2023-10-24 170
很多讨厌ACG的小伙伴们大体上单厢采用P站,不过有天数是P站会难以恒定登入,这时如果什么样是好呢?接下去他们一起来看一看如果什么样登入Pixiv站操作方式01具体来说他们须......
2023-10-24 151
随著北欧国家中国经济和信息技术的产业发展,天数就显得至关重要以是当他们在QQ应用程序里看某一页面时我甘心优先选择听而并非去看那你晓得什么样才能在QQ应用程序迈入......
2023-10-24 153