




已阅读5页,还剩13页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
测试环境:IIS5.1 + PHP5.2.12 + MySQL5.0.88本程序使用的是PDO,所以php.ini中的extension=php_pdo.dll和extension=php_pdo_mysql.dll必须打开。首先安装UCenter1.5,路径:http:/localhost/ucenter然后进入后台添加一个新的应用,安装方式选择“自定义安装”;应用名称:我的应用1;应用URL:http:/localhost/myapp1;应用IP:;通信密钥先不用管;应用类型:其他;同步登录:是;接收通知:是。添加成功之后返回应用列表,可以看到“我的应用1”通信失败,暂时不用管。在http:/localhost所在的目录下新建一个文件夹,命名为myapp1,拷贝一份UCenter的客户端(uc_client)到myapp1目录下。在http:/localhost/myapp1所在的目录下新建一个文件夹,命名为api,拷贝一份UCenter的api(uc.php)到api目录下,官方Example中10KB的那个文件(但还是有点问题)。在http:/localhost/myapp1所在的目录下新建一个文件夹,命名为include,拷贝一份Discuz的db_mysql.class.php和db_mysql_error.inc.php到include目录下。在http:/localhost/myapp1所在的目录下新建一个config.inc.php文件,这是本应用的配置文件。在数据库里建立本应用的数据表,一般都需要有自己的数据表。准备工作完成了,下面详细介绍各个模块的代码。本应用程序的配置文件:config.inc.phpquery(set names gbk);/*define(UC_CONNECT, mysql);define(UC_DBHOST, localhost);define(UC_DBUSER, yutiedun);define(UC_DBPW, 11111111);define(UC_DBNAME, discuz);define(UC_DBCHARSET, gbk);define(UC_DBTABLEPRE, discuz.uc_);define(UC_DBCONNECT, 0);define(UC_KEY, 4961DYjLak6oE0cJq9jNDbxNUzSalwMXq6qp1X0);define(UC_API, http:/localhost/ucenter);define(UC_CHARSET, gbk);define(UC_IP, );define(UC_APPID, 5); /根据具体情况设置define(UC_PPP, 20);/*?UCenter接口文件:uc.php 3600) exit(Authracation has expiried);if(empty($get) exit(Invalid Request);$action = $getaction;require_once DISCUZ_ROOT./uc_client/lib/xml.class.php;$post = xml_unserialize(file_get_contents(php:/input);if(in_array($getaction, array(test, deleteuser, renameuser, gettag, synlogin, synlogout, updatepw, updatebadwords, updatehosts, updateapps, updateclient, updatecredit, getcreditsettings, updatecreditsettings) require_once DISCUZ_ROOT./include/db_mysql.class.php;$GLOBALSdb = new dbstuff;$GLOBALSdb-connect($dbhost, $dbuser, $dbpw, $dbname, $pconnect, true, $dbcharset);$GLOBALStablepre = $tablepre;unset($dbhost, $dbuser, $dbpw, $dbname, $pconnect);$uc_note = new uc_note();exit($uc_note-$getaction($get, $post); else exit(API_RETURN_FAILED);/note include 通知方式 else require_once DISCUZ_ROOT./config.inc.php;require_once DISCUZ_ROOT./include/db_mysql.class.php;$GLOBALSdb = new dbstuff;$GLOBALSdb-connect($dbhost, $dbuser, $dbpw, $dbname, $pconnect, true, $dbcharset);$GLOBALStablepre = $tablepre;unset($dbhost, $dbuser, $dbpw, $dbname, $pconnect);class uc_note var $dbconfig = ;var $db = ;var $tablepre = ;var $appdir = ;function _serialize($arr, $htmlon = 0) if(!function_exists(xml_serialize) include_once DISCUZ_ROOT./uc_client/lib/xml.class.php;return xml_serialize($arr, $htmlon);function uc_note() $this-appdir = substr(dirname(_FILE_), 0, -3);$this-dbconfig = $this-appdir./config.inc.php;$this-db = $GLOBALSdb;$this-tablepre = $GLOBALStablepre;function test($get, $post) return API_RETURN_SUCCEED;function deleteuser($get, $post) $uids = $getids;!API_DELETEUSER & exit(API_RETURN_FORBIDDEN);return API_RETURN_SUCCEED;function renameuser($get, $post) $uid = $getuid;$usernameold = $getoldusername;$usernamenew = $getnewusername;if(!API_RENAMEUSER) return API_RETURN_FORBIDDEN;return API_RETURN_SUCCEED;function gettag($get, $post) $name = $getid;if(!API_GETTAG) return API_RETURN_FORBIDDEN;$return = array();return $this-_serialize($return, 1);function synlogin($get, $post) $uid = $getuid;$username = $getusername;if(!API_SYNLOGIN) return API_RETURN_FORBIDDEN;/note 同步登入 API 接口header(P3P: CP=CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR);_setcookie(loginstat, _authcode($uid.t.$username, ENCODE);function synlogout($get, $post) if(!API_SYNLOGOUT) return API_RETURN_FORBIDDEN;/note 同步登出 API 接口header(P3P: CP=CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR);_setcookie(loginstat, , -86400 * 365);function updatepw($get, $post) if(!API_UPDATEPW) return API_RETURN_FORBIDDEN;$username = $getusername;$password = $getpassword;return API_RETURN_SUCCEED;function updatebadwords($get, $post) if(!API_UPDATEBADWORDS) return API_RETURN_FORBIDDEN;$cachefile = $this-appdir./uc_client/data/cache/badwords.php;$fp = fopen($cachefile, w);$data = array();if(is_array($post) foreach($post as $k = $v) $datafindpattern$k = $vfindpattern;$datareplace$k = $vreplacement;$s = appdir./uc_client/data/cache/hosts.php;$fp = fopen($cachefile, w);$s = appdir./uc_client/data/cache/apps.php;$fp = fopen($cachefile, w);$s = appdir./config.inc.php) $configfile = trim(file_get_contents($this-appdir./config.inc.php);$configfile = substr($configfile, -2) = ? ? substr($configfile, 0, -2) : $configfile;$configfile = preg_replace(/define(UC_API,s*.*?);/i, define(UC_API, $UC_API);, $configfile);if($fp = fopen($this-appdir./config.inc.php, w) fwrite($fp, trim($configfile);fclose($fp);return API_RETURN_SUCCEED;function updateclient($get, $post) if(!API_UPDATECLIENT) return API_RETURN_FORBIDDEN;$cachefile = $this-appdir./uc_client/data/cache/settings.php;$fp = fopen($cachefile, w);$s = _serialize($credits);function updatecreditsettings($get, $post) if(!API_UPDATECREDITSETTINGS) return API_RETURN_FORBIDDEN;return API_RETURN_SUCCEED;/note 使用该函数前需要 require_once $this-appdir./config.inc.php;/*function _setcookie($var, $value, $life = 0, $prefix = 1) global $cookiepre, $cookiedomain, $cookiepath, $timestamp, $_SERVER;setcookie($prefix ? $cookiepre : ).$var, $value, $life ? $timestamp + $life : 0, $cookiepath, $cookiedomain, $_SERVERSERVER_PORT = 443 ? 1 : 0);*/function _setcookie($var, $value, $life = 0, $prefix = 0) global $cookiepre, $cookiedomain, $cookiepath, $timestamp, $_SERVER;setcookie($prefix ? $cookiepre : ).$var, $value, $life ? $timestamp + $life : 0, /, , $_SERVERSERVER_PORT = 443 ? 1 : 0);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(%010d, $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 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);function _stripslashes($string) if(is_array($string) foreach($string as $key = $val) $string$key = _stripslashes($val); else $string = stripslashes($string);return $string;?在UCenter后台应用列表中点击编辑“我的应用1”,将“应用的UCenter配置信息”拷贝至本应用的配置文件config.inc.php中,覆盖掉相应的内容。到这里UCenter就可以跟本应用通信成功了。如下图所示:应用程序主页:index.html无标题文档bodyfont-family:Times New Roman,宋体,Arial;font-size:14px;color:#333;.plunshowfont-size:14px;color:#333;margin:10px;.plunpagefont-size:12px;color:#333;margin:10px;Ajax函数:ajax_navagation.js/*Design By Xinge At 2007-05-22Demo:/test/ajax2/test.htm*/var please_wait = null;function open_url(url, target) var link;if (!document.getElementById) return false; if (please_wait != null) document.getElementById(target).innerHTML = please_wait; if (window.ActiveXObject) trylink = new ActiveXObject(Msxml2.XMLHTTP);catch(e)link = new ActiveXObject(Microsoft.XMLHTTP); else if (window.XMLHttpRequest) link = new XMLHttpRequest(); if (link = undefined) return false; link.onreadystatechange = function() response(link, url, target); link.open(GET, url, true); link.send(null);function response(link, url, target) /alert(link.readyState + - + target);/alert(link.readyState);if (link.readyState 4) document.getElementById(target).innerHTML = 载入中,请稍后.; else /document.getElementById(target).innerHTML = (link.status = 200) ? link.responseText : Ooops! A broken link! Please contact the webmaster of this website and give him the fallowing errorcode: + link.status;document.getElementById(target).innerHTML = (link.status = 200) ? link.responseText : Ooops! A broken link!;function set_loading_message(msg) please_wait = msg;登录状态检测:loginstat.phpquery($sql01) as $row01)$usernum=$row01usernum;if($usernum=0) echo .$uname. >> 激活 退出; else echo .$uname. >> 管理 退出; else echo 游客 >> 登录 注册 ?用户注册处理:register_ok.php?phpheader(expires: mon, 26 jul 1997 05:00:00 gmt);header(cache-control: no-cache, must-revalidate);header(pragma: no-cache);header(Content-type: text/html; charset=gbk);require_once config.inc.php;require_once uc_client/client.php;$username=trim($_POSTusername);$password=trim($_POSTpassword);$passwd2=md5($password);$email=trim($_POSTemail);$regtime=date(Y-m-d H:i:s);$comeurl=trim($_POSTcomeurl);if($comeurl=)$comeurl=index.php;/*session_start();$validate=;$validate=trim($_POSTverifcode);if($validate!=$_SESSIONverifcode) echo alert(验证码错误!);window.history.back();*/$uid = uc_user_register($username, $password, $email);if($uid = 0) if($uid = -1) echo 用户名不合法; elseif($uid = -2) echo 包含不允许注册的词语; elseif($uid = -3) echo 用户名已经存在; elseif($uid = -4) echo Email格式有误; elseif($uid = -5) echo Email不允许注册; elseif($uid = -6) echo 该Email已经被注册; else echo 未知错误; else try $sql01=insert into swt_users (username,password,email,regtime,totallogin,mmbf) values ($username,$passwd2,$email,$regtime,0,$password); $dbh-beginTransaction(); $dbh-exec($sql01); $dbh-commit(); catch (Exception $e) $dbh-rollBack(); echo Failed: . $e-getMessage(); setcookie(loginstat, uc_authcode($uid.t.$username, ENCODE);$ucsynlogin = uc_user_synlogin($uid);echo $ucsynlogin; /一定要输出到页面中echo 注册成功!请稍等.;header(Refresh: 5;url=.$comeurl);?用户登录处理:login_ok.php 0) setcookie(loginstat, uc_authcode($uid.t.$username, ENCODE);$ucsynlogin = uc_user_synlogin($uid);echo $ucsynlogin; /一定要输出到页面中$sql01=select count(username) as usernum from swt_users where username=$username;foreach ($dbh-query($sql01) as $row01)$usernum=$row01usernum;if($usernum=0) echo 您的帐号需要激活才能使用,点击这里激活。 暂不激活; else
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年网络安全工程师信息安全漏洞响应考试模拟试卷
- 2025年南宁事业单位招聘考试综合类公共基础知识真题模拟试卷
- 纪委监委消防知识培训课件
- 钦州二模数学试卷
- 全国高考体育生数学试卷
- 宁波慈溪一模数学试卷
- 宁波市镇海中学数学试卷
- 七上期末必考数学试卷
- 清北小学6年级数学试卷
- 供货合同法律效力分析
- 集团公司校园招聘计划实施方案
- 癫痫所致精神障碍
- 卫生部手术分级目录(2023年1月份修订)
- 电荷及其守恒定律、库仑定律巩固练习
- YY 0666-2008针尖锋利度和强度试验方法
- 小沈阳《四大才子》欢乐喜剧人台词
- 全套课件-水利工程管理信息技术
- 缝纫机线迹图示教学课件
- 2022年衡阳市南岳区社区工作者招聘笔试题库及答案解析
- 阀门解体检修及研磨(课堂PPT)
- T∕CVIA 41-2014 液晶电视屏主流尺寸规范
评论
0/150
提交评论