Discuz教程网

[插件制作] Discuz X2插件制作之UCenter接口

[复制链接]
authicon dly 发表于 2011-5-4 11:06:30 | 显示全部楼层 |阅读模式
目录
1 接口函数
1.1 用户接口
1.2 短消息接口
1.3 好友接口
1.4 积分接口
1.5 头像接口
1.6 标签接口
1.7 事件接口
1.8 应用接口
1.9 邮件接口
2 API接口
2.1 常量定义
2.2 通知方式判断以及初始化输入参数
2.3 接口代码段
2.4 函数定义
3 范例程序


接口函数
用户接口
此部分接口负责用户的注册、登录,可实现用户表的统一管理。
uc_user_register
用于新用户的注册
uc_user_login
用于用户的登录验证
uc_get_user
用于获取用户在 UCenter 的基本数据
uc_user_edit
用于更新用户资料
uc_user_delete
用于删除用户
uc_user_deleteavatar
用于删除用户头像
uc_user_synlogin
用于用户同步登录
uc_user_synlogout
用于用户同步退出
uc_user_checkemail
用于检查用户输入的 Email 的合法性
uc_user_checkname
用于检查用户输入的用户名的合法性
uc_user_addprotected
用于添加被保护的用户
uc_user_deleteprotected
用于删除被保护的用户
uc_user_getprotected
用于获得被保护的用户列表
uc_user_merge
用于把重名的用户合并到 UCenter
uc_user_merge_remove
用于移除重名用户记录中的指定记录
uc_user_getcredit
用于获取指定应用的指定用户积分



短消息接口
此部分接口负责用户间的短消息传输,可以跨应用间互相发送短消息。“短消息中心”的界面接口可以让应用只需一个函数接口即拥有短消息功能,对于高级用户 UCenter 也提供了丰富的收发接口函数供用户自己开发短消息系统。
uc_pm_location
本接口函数运行后会发送一个 header 的 location 请求,使当前页面跳转到短消息中心。
uc_pm_checknew
本接口函数会检查指定用户是否有新的短消息。
uc_pm_send
本接口函数用于发送短消息。
uc_pm_delete
本接口函数将删除指定文件夹中的指定消息 ID 的短消息。
uc_pm_deleteuser
本接口函数将删除和 uid 对话的 touids 中的所有短消息。
uc_pm_deletechat
本接口函数用于群聊短消息的退出和删除。
uc_pm_readstatus
本接口函数用于标记短消息的已读/未读状态。
uc_pm_list
本接口函数用于获取指定文件夹的短消息列表。
uc_pm_ignore
本接口函数用于直接忽略未读短消息的提示状态。
uc_pm_view
本接口函数用于返回指定用户的指定消息 ID 的消息。
uc_pm_view_num
本接口函数用于返回指定会话的消息数量。
uc_pm_viewnode
本接口函数用于查询单条短消息内容。
uc_pm_chatpmmemberlist
本接口函数用于返回群聊成员列表。
uc_pm_kickchatpm
本接口函数用于将指定用户踢出群聊会话。
uc_pm_appendchatpm
本接口函数用于添加群聊成员。
uc_pm_blackls_get
本接口函数返回用户的黑名单设置的内容。
uc_pm_blackls_set
本接口函数用于更新用户的黑名单列表数据。
uc_pm_blackls_add
本接口函数用于添加用户的黑名单项目。
uc_pm_blackls_delete
本接口函数用于删除用户的黑名单项目。



好友接口
此部分接口负责用户好友信息的共享。一个应用更新的好友资料其他应用都能够看到。
uc_friend_add
本函数接口用于把 friendid 添加为 uid 的好友。
uc_friend_delete
本函数接口用于删除指定用户的好友。
uc_friend_totalnum
本接口函数用于返回指定用户的好友数。
uc_friend_ls
本接口函数用于返回好友列表数据。



积分接口
此部分接口负责应用间的积分兑换。
uc_credit_exchange_request
本接口函数用于积分兑换处理。



头像接口
此部分接口提供了一套用户头像的编辑、显示的平台,可以让应用拥有用头像的编辑功能。
uc_avatar
本接口函数用于返回设置用户头像的 HTML 代码。
uc_check_avatar
本接口函数用于检测指定用户的头像是否存在。



标签接口
此部分接口负责应用间标签信息的聚合。
uc_tag_get
本接口会向用户中心发起一个请求,要求获取用户中心中所有应用的标签数据。



事件接口
此部分接口负责应用间信息的聚合。
uc_feed_add
本接口函数用于向 UCenter Home 添加事件。如果正确则返回事件的 ID。
uc_feed_get
本接口函数用于提取事件。如果正确则返回事件列表数组。



应用接口
此部分接口用于获取应用相关信息。
uc_app_ls
本接口获取 UCenter 中所有应用的列表数据。



邮件接口
此部分接口用来将邮件加入到邮件队列,或者直接发送邮件(当level为0时)。
uc_mail_queue
本函数用来将邮件加入到邮件队列,或者直接发送邮件(当level为0时)。



API接口
UCenter 的 API 接口文件必须存放于应用程序根目录的“api/”目录中,且文件名可以自定义,默认为 uc.php,即“api/uc.php”。文件结构可分为 4 部分,包含 12 个接口项目。第 1 部分为常量定义、第 2 部分为通知方式判断以及初始化输入参数、第 3 部分为接口类代码段、第 4 部分为函数定义。




常量定义
  1. define('UC_CLIENT_VERSION', '1.5.0');        //note UCenter 版本标识
  2. define('UC_CLIENT_RELEASE', '20081031');

  3. define('API_DELETEUSER', 1);                //note 用户删除 API 接口开关
  4. define('API_RENAMEUSER', 1);                //note 用户改名 API 接口开关
  5. define('API_GETTAG', 1);                //note 获取标签 API 接口开关
  6. define('API_SYNLOGIN', 1);                //note 同步登录 API 接口开关
  7. define('API_SYNLOGOUT', 1);                //note 同步登出 API 接口开关
  8. define('API_UPDATEPW', 1);                //note 更改用户密码 开关
  9. define('API_UPDATEBADWORDS', 1);        //note 更新关键字列表 开关
  10. define('API_UPDATEHOSTS', 1);                //note 更新域名解析缓存 开关
  11. define('API_UPDATEAPPS', 1);                //note 更新应用列表 开关
  12. define('API_UPDATECLIENT', 1);                //note 更新客户端缓存 开关
  13. define('API_UPDATECREDIT', 1);                //note 更新用户积分 开关
  14. define('API_GETCREDITSETTINGS', 1);        //note 向 UCenter 提供积分设置 开关
  15. define('API_GETCREDIT', 1);                //note 获取用户的某项积分 开关
  16. define('API_UPDATECREDITSETTINGS', 1);        //note 更新应用积分设置 开关

  17. define('API_RETURN_SUCCEED', '1');
  18. define('API_RETURN_FAILED', '-1');
  19. define('API_RETURN_FORBIDDEN', '-2');
复制代码

常量定义部分定义了接口所用到的 14 个接口项目的开关设置,“1”为开启“0”为关闭。如果开启,则代码段运行后返回 API_RETURN_SUCCEED,否则返回 API_RETURN_FORBIDDEN。接口运行失败则返回 API_RETURN_FAILED。

通知方式判断以及初始化输入参数
  1. if(!defined('IN_UC')) {

  2.         error_reporting(0);
  3.         set_magic_quotes_runtime(0);

  4.         define('DISCUZ_ROOT', substr(dirname(__FILE__), 0, -3));
  5.         defined('MAGIC_QUOTES_GPC') || define('MAGIC_QUOTES_GPC', get_magic_quotes_gpc());
  6.         require_once DISCUZ_ROOT.'./config.inc.php';

  7.         $_DCACHE = $get = $post = array();

  8.         $code = @$_GET['code'];
  9.         parse_str(_authcode($code, 'DECODE', UC_KEY), $get);
  10.         if(MAGIC_QUOTES_GPC) {
  11.                 $get = _stripslashes($get);
  12.         }

  13.         $timestamp = time();
  14.         if($timestamp - $get['time'] > 3600) {
  15.                 exit('Authracation has expiried');
  16.         }
  17.         if(empty($get)) {
  18.                 exit('Invalid Request');
  19.         }
  20.         $action = $get['action'];

  21.         require_once DISCUZ_ROOT.'./uc_client/lib/xml.class.php';
  22.         $post = xml_unserialize(file_get_contents('php://input'));

  23.         if(in_array($get['action'], array('test', 'deleteuser', 'renameuser', 'gettag', 'synlogin', 'synlogout', 'updatepw', 'updatebadwords', 'updatehosts', 'updateapps', 'updateclient', 'updatecredit', 'getcreditsettings', 'updatecreditsettings'))) {
  24.                 require_once DISCUZ_ROOT.'./include/db_'.$database.'.class.php';
  25.                 $GLOBALS['db'] = new dbstuff;
  26.                 $GLOBALS['db']->connect($dbhost, $dbuser, $dbpw, $dbname, $pconnect, true, $dbcharset);
  27.                 $GLOBALS['tablepre'] = $tablepre;
  28.                 unset($dbhost, $dbuser, $dbpw, $dbname, $pconnect);
  29.                 $uc_note = new uc_note();
  30.                 exit($uc_note->$get['action']($get, $post));
  31.         } else {
  32.                 exit(API_RETURN_FAILED);
  33.         }

  34. } else {

  35.         define('DISCUZ_ROOT', $app['extra']['apppath']);
  36.         require_once DISCUZ_ROOT.'./config.inc.php';
  37.         require_once DISCUZ_ROOT.'./include/db_'.$database.'.class.php';
  38.         $GLOBALS['db'] = new dbstuff;
  39.         $GLOBALS['db']->connect($dbhost, $dbuser, $dbpw, $dbname, $pconnect, true, $dbcharset);
  40.         $GLOBALS['tablepre'] = $tablepre;
  41.         unset($dbhost, $dbuser, $dbpw, $dbname, $pconnect);
  42. }
复制代码

通过常量 IN_UC 来判断接口文件是通过远程 HTTP 方式访问还是直接包含方式调用

接口代码段
接口类名称为 uc_note ,接口名称作为此类的一个方法,uc_note 代码结构大体如下:

  1. class uc_note {

  2.         var $dbconfig = '';
  3.         //var $db = '';
  4.         var $appdir = '';

  5.         function _serialize($arr, $htmlon = 0) {
  6.                 if(!function_exists('xml_serialize')) {
  7.                         include_once DISCUZ_ROOT.'./uc_client/lib/xml.class.php';
  8.                 }
  9.                 return xml_serialize($arr, $htmlon);
  10.         }

  11.         function uc_note() {
  12.                 $this->appdir = substr(dirname(__FILE__), 0, -3);
  13.                 $this->dbconfig = $this->appdir.'./config.inc.php';
  14.         }

  15.         function test($get, $post) {
  16.                 return API_RETURN_SUCCEED;
  17.         }

  18.         function deleteuser($get, $post) {
  19.                 /*代码省略*/
  20.                 return API_RETURN_SUCCEED;
  21.         }
  22.         
  23.         /* 更多接口项目 */

  24. }
复制代码

具体可以参考Discuz7.2代码中的/api/uc.php

test
此接口供仅测试连接。当 UCenter 发起 test 的接口请求时,如果成功获取到接口返回的 API_RETURN_SUCCEED 值,表示 UCenter 和应用通讯正常。
deleteuser
当 UCenter 删除一个用户时,会发起 deleteuser 的接口请求,通知所有应用程序删除相应的用户。
输入的参数放在 $get['ids'] 中,值为用逗号分隔的用户 ID。如果删除成功则输出 API_RETURN_SUCCEED。
deleteuser 接口示例 (PHP)
  1. $query = $db->query("DELETE FROM {$tablepre}members WHERE uid IN ($get[ids])");
  2. exit(API_RETURN_SUCCEED);
复制代码

renameuser
当 UCenter 更改一个用户的用户名时,会发起 renameuser 的接口请求,通知所有应用程序改名。
输入的参数 $get['uid'] 表示用户 ID,$get['oldusername'] 表示旧用户名,$get['newusername'] 表示新用户名。如果修改成功则输出 API_RETURN_SUCCEED。
renameuser 接口示例 (PHP)
  1. $uid = $get['uid'];
  2. $usernamenew = $get['newusername'];

  3. $db->query("UPDATE {$tablepre}members SET username='$usernamenew' WHERE uid='$uid'");
  4. exit(API_RETURN_SUCCEED);
复制代码

updatepw
当用户更改用户密码时,此接口负责接受 UCenter 发来的新密码。
输入的参数 $get['username'] 表示用户名,$get['password'] 表示新密码。如果修改成功则输出 API_RETURN_SUCCEED。
updatepw 接口示例 (PHP)
  1. $username = $get['username'];
  2. $password = md5($get['password']);
  3. $db->query("UPDATE members SET password='$password' WHERE username='$username'");
  4. exit(API_RETURN_SUCCEED);
复制代码

gettag
如果应用程序存在标签功能,可以通过此接口把应用程序的标签数据传递给 UCenter。
输入的参数放在 $get['id'] 中,值为标签名称。输出的数组需经过 uc_serialize 处理。
integer[0]  标签名称  
array[1]  标签数据 mixed['xxx'] 自定义
自定义多个数组项,索引名任意,一同返回给 UCenter。为了保证应用间数据的共享,您需要在“应用管理管理”的“标签单条显示模板”和“标签模板标记说明”设置模板和说明。模板中“{xxx}”表示标签数据的索引,代表相应的数据。如扩展数据模板中的“{image}”将显示“['image']”数组项的内容。  

gettag 接口示例 (PHP)
  1. $query = $db->query("SELECT * FROM threadtags WHERE tagname='$get[id]' ORDER BY dateline DESC LIMIT 10");
  2. $threadlist = array();
  3. while($data = $db->fetch_array($query)) {
  4.         $threadlist[] = array(
  5.                 'name' => $data['subject'],
  6.                 'uid' => $data['authorid'],
  7.                 'username' => $data['author'],
  8.                 'dateline' => $data['dateline'],
  9.                 'url' => 'http://www.yourwebsite.com/thread.php?id='.$data['id'],
  10.                 'image' => ''http://www.yourwebsite.com/threadimage.php?id='.$data['id'],
  11.                 );
  12.         }
  13. }

  14. $return = array($name, $threadlist);
  15. echo uc_serialize($return, 1);
复制代码

synlogin
如果应用程序需要和其他应用程序进行同步登录,此部分代码负责标记指定用户的登录状态。
输入的参数放在 $get['uid'] 中,值为用户 ID。此接口为通知接口,无输出内容。同步登录需使用 P3P 标准。
synlogin 接口示例 (PHP)
  1. $query = $db->query("SELECT uid, username FROM members WHERE uid='$get[uid]'");
  2. if($member = $db->fetch_array($query)) {
  3.         header('P3P: CP="CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR"');
  4.         dsetcookie('Example_auth', authcode($member['uid']."\t".$member['username'], 'ENCODE'), 86400 * 365);
  5. }
复制代码

synlogout
如果应用程序需要和其他应用程序进行同步退出登录,此部分代码负责撤销用户的登录的状态。
此接口为通知接口,无输入参数和输出内容。同步退出需使用 P3P 标准。
synlogout 接口示例 (PHP)
  1. header('P3P: CP="CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR"');
  2. dsetcookie('Example_auth', '', -86400 * 365);
复制代码

updatebadwords
当 UCenter 的词语过滤设置变更时,此接口负责通知所有应用程序更新后的词语过滤设置内容。
设置内容用 POST 方式提交到接口。接口运行完毕输出 API_RETURN_SUCCEED。
updatebadwords 接口示例 (PHP)
  1. $post = uc_unserialize(file_get_contents('php://input'));
  2. $cachefile = DISCUZ_ROOT.'./uc_client/data/cache/badwords.php';
  3. $fp = fopen($cachefile, 'w');
  4. $s = "<?php\r\n";
  5. $s .= '$_CACHE[\'badwords\'] = '.var_export($post, TRUE).";\r\n";
  6. fwrite($fp, $s);
  7. fclose($fp);
  8. exit(API_RETURN_SUCCEED);
复制代码

updatehosts
当 UCenter 的域名解析设置变更时,此接口负责通知所有应用程序更新后的域名解析设置内容。
设置内容用 POST 方式提交到接口。接口运行完毕输出 API_RETURN_SUCCEED。
updatehosts 接口示例 (PHP)
  1. $post = uc_unserialize(file_get_contents('php://input'));
  2. $cachefile = DISCUZ_ROOT.'./uc_client/data/cache/hosts.php';
  3. $fp = fopen($cachefile, 'w');
  4. $s = "<?php\r\n";
  5. $s .= '$_CACHE[\'hosts\'] = '.var_export($post, TRUE).";\r\n";
  6. fwrite($fp, $s);
  7. fclose($fp);
  8. exit(API_RETURN_SUCCEED);
复制代码

updateapps
当 UCenter 的应用程序列表变更时,此接口负责通知所有应用程序更新后的应用程序列表。
设置内容用 POST 方式提交到接口。接口运行完毕输出 API_RETURN_SUCCEED。
updateapps 接口示例 (PHP)
  1. $post = uc_unserialize(file_get_contents('php://input'));
  2. $cachefile = DISCUZ_ROOT.'./uc_client/data/cache/apps.php';
  3. $fp = fopen($cachefile, 'w');
  4. $s = "<?php\r\n";
  5. $s .= '$_CACHE[\'apps\'] = '.var_export($post, TRUE).";\r\n";
  6. fwrite($fp, $s);
  7. fclose($fp);
  8. exit(API_RETURN_SUCCEED);
复制代码

updateclient
当 UCenter 的基本设置信息变更时,此接口负责通知所有应用程序更新后的基本设置内容。
设置内容用 POST 方式提交到接口。接口运行完毕输出 API_RETURN_SUCCEED。
updateclient 接口示例 (PHP)
  1. $post = uc_unserialize(file_get_contents('php://input'));
  2. $cachefile = DISCUZ_ROOT.'./uc_client/data/cache/setting.php';
  3. $fp = fopen($cachefile, 'w');
  4. $s = "<?php\r\n";
  5. $s .= '$_CACHE[\'setting\'] = '.var_export($post, TRUE).";\r\n";
  6. fwrite($fp, $s);
  7. fclose($fp);
  8. exit(API_RETURN_SUCCEED);
复制代码

updatecredit
当某应用执行了积分兑换请求的接口函数 uc_credit_exchange_request() 后,此接口负责通知被兑换的目的应用程序所需修改的用户积分值。
输入的参数 $get['credit'] 表示积分编号,$get['amount'] 表示积分的增减值,$get['uid'] 表示用户 ID。
updatecredit 接口示例 (PHP)
  1. $credit = intval($get['credit']);
  2. $amount = intval($get['amount']);
  3. $uid = intval($get['uid']);

  4. $db->query("UPDATE members SET extcredits$credit=extcredits$credit+'$amount' WHERE uid='$uid'");
  5. exit(API_RETURN_SUCCEED);
复制代码

getcreditsettings
此接口负责把应用程序的积分设置传递给 UCenter,以供 UCenter 在积分兑换设置中使用。
此接口无输入参数。输出的数组需经过 uc_serialize 处理。
输出的数组单条结构:
key  类型  value  
n键值为积分编号  array  string [0] 积分名称
string [1] 积分单位  

如:
  1. array(
  2.         '1' => array('威望', ''),
  3.         '2' => array('金钱', '枚'),
  4. )
复制代码

getcreditsettings 接口示例 (PHP)
  1. $credits = array();
  2. foreach($_DCACHE['settings']['extcredits'] as $id => $extcredits) {
  3.         $credits[$id] = array($extcredits['title'], $extcredits['unit']);
  4. }
  5. echo uc_serialize($credits);
复制代码

updatecreditsettings
此接口负责接收 UCenter 积分兑换设置的参数。
输入的参数放在 $get['credit'] 中,值为设置的参数数组。接口运行完毕输出 API_RETURN_SUCCEED。
输入的数组单条结构:
key  类型  value  
appid 应用程序 ID  array  integer ['appiddesc'] 积分兑换的目标应用程序 ID
integer ['creditdesc'] 积分兑换的目标积分编号
integer ['creditsrc'] 积分兑换的源积分编号
string ['title'] 积分名称
string ['unit'] 积分单位
integer ['ratio'] 积分兑换比率  

如:
  1. array(
  2.         '1' => array(
  3.                 'appiddesc' => 2,
  4.                 'creditdesc' => 1,
  5.                 'creditsrc' => 1,
  6.                 'title' => '金钱',
  7.                 'unit' => '枚',
  8.                 'ratio' => 2,
  9.         ),
  10. )
复制代码

updatecreditsettings 接口示例 (PHP)
  1. $outextcredits = array();
  2. foreach($get['credit'] as $appid => $credititems) {
  3.         if($appid == UC_APPID) {
  4.                 foreach($credititems as $value) {
  5.                         $outextcredits[$value['appiddesc'].'|'.$value['creditdesc']] = array(
  6.                                 'creditsrc' => $value['creditsrc'],
  7.                                 'title' => $value['title'],
  8.                                 'unit' => $value['unit'],
  9.                                 'ratio' => $value['ratio']
  10.                         );
  11.                 }
  12.         }
  13. }

  14. $db->query("REPLACE INTO cdb_settings (variable, value) VALUES ('outextcredits', '".addslashes(serialize($outextcredits))."');", 'UNBUFFERED');
  15. exit(API_RETURN_SUCCEED);
复制代码


getcredit
此接口用于把应用程序中指定用户的积分传递给 UCenter。
输入的参数 $get['uid'] 为用户 ID,$get['credit'] 为积分编号。接口运行完毕输出积分值。
  1. getcredit 接口示例 (PHP)
  2. $uid = intval($get['uid']);
  3. $credit = intval($get['credit']);
  4. echo $db->result_first("SELECT extcredits$credit FROM members WHERE uid='$uid'");
复制代码




函数定义
接口函数中必须包含以下函数,否则无法正确对 UCenter 传递过来的数据进行解码。

  1. function authcode($string, $operation = 'DECODE', $key = '', $expiry = 0) {

  2.         $ckey_length = 4;

  3.         $key = md5($key ? $key : UC_KEY);
  4.         $keya = md5(substr($key, 0, 16));
  5.         $keyb = md5(substr($key, 16, 16));
  6.         $keyc = $ckey_length ? ($operation == 'DECODE' ? substr($string, 0, $ckey_length): substr(md5(microtime()), -$ckey_length)) : '';

  7.         $cryptkey = $keya.md5($keya.$keyc);
  8.         $key_length = strlen($cryptkey);

  9.         $string = $operation == 'DECODE' ? base64_decode(substr($string, $ckey_length)) : sprintf('%010d', $expiry ? $expiry + time() : 0).substr(md5($string.$keyb), 0, 16).$string;
  10.         $string_length = strlen($string);

  11.         $result = '';
  12.         $box = range(0, 255);

  13.         $rndkey = array();
  14.         for($i = 0; $i <= 255; $i++) {
  15.                 $rndkey[$i] = ord($cryptkey[$i % $key_length]);
  16.         }

  17.         for($j = $i = 0; $i < 256; $i++) {
  18.                 $j = ($j + $box[$i] + $rndkey[$i]) % 256;
  19.                 $tmp = $box[$i];
  20.                 $box[$i] = $box[$j];
  21.                 $box[$j] = $tmp;
  22.         }

  23.         for($a = $j = $i = 0; $i < $string_length; $i++) {
  24.                 $a = ($a + 1) % 256;
  25.                 $j = ($j + $box[$a]) % 256;
  26.                 $tmp = $box[$a];
  27.                 $box[$a] = $box[$j];
  28.                 $box[$j] = $tmp;
  29.                 $result .= chr(ord($string[$i]) ^ ($box[($box[$a] + $box[$j]) % 256]));
  30.         }

  31.         if($operation == 'DECODE') {
  32.                 if((substr($result, 0, 10) == 0 || substr($result, 0, 10) - time() > 0) && substr($result, 10, 16) == substr(md5(substr($result, 26).$keyb), 0, 16)) {
  33.                         return substr($result, 26);
  34.                 } else {
  35.                         return '';
  36.                 }
  37.         } else {
  38.                 return $keyc.str_replace('=', '', base64_encode($result));
  39.         }

  40. }

  41. function uc_serialize($arr, $htmlon = 0) {
  42.         include_once UC_CLIENT_ROOT.'./lib/xml.class.php';
  43.         return xml_serialize($arr, $htmlon);
  44. }

  45. function uc_unserialize($s) {
  46.         include_once UC_CLIENT_ROOT.'./lib/xml.class.php';
  47.         return xml_unserialize($s);
  48. }
复制代码

范例程序
为了方便开发,我们把所有的 UCenter 接口函数组合在一起,制作了范例程序。要运行此范例程序,您需要做的准备工作如下:

范例程序中默认不包含 client 目录,如果要运行此范例程序,请复制一份 UCenter 安装包中的 client 到范例程序根目录。
在 UCenter 添加一个应用,设置范例程序运行的 URL 等信息,通信密钥可随意填写,如“123456”。
打开范例程序的 config.inc.php 设置范例程序连接 UCenter 的方式,设置数据库连接等参数。“UC_KEY”填写在 UCenter 设置的通信密钥(上例的“12345”),“UC_APPID”填写刚才添加的应用 ID。

ucexample_1.php 为无用户表的范例程序主文件

ucexample_2.php 为有自己的用户表的范例程序主文件


具体目录结构请见下表:
client/ UCenter 客户端的文件目录,默认不包含此目录。
api/ API 接口目录
code/ 范例代码程序段目录
code/login_nodb.php ucexample_1.php 的用户登录范例代码,包含登录验证、同步登录的范例代码。让你了解到没有用户表也可以整合 UCenter。
code/login_db.php ucexample_2.php 的用户登录范例代码,包含登录验证、同步登录和用户激活的范例代码。
code/register_nodb.php ucexample_1.php 的用户注册范例代码,包含注册信息验证的范例代码。
code/register_db.php ucexample_2.php 的用户注册范例代码,包含注册信息验证、用户激活判断的范例代码。
code/pmwin.php 直接进入短消息中心的范例代码。
code/pmlist.php 自制短消息平台的范例代码,包含获取短消息的列表、内容以及发送短消息的范例代码。
code/friend.php 管理好友列表的范例代码
code/avatar.php 查看、编辑头像的范例代码
include/ 库文件文件
view/ 模板目录
config.inc.php 配置文件
ucexample_1.php 应用程序无用户表的范例程序主文件
ucexample_2.php 应用程序有自己的用户表的范例程序主文件
出自Discuz! 技术文库





上一篇:Discuz X2插件制作之UCenter 的简介和目录结构说明
下一篇:Discuz X2插件制作之缓存机制
authicon fhiejkl 发表于 2011-5-8 21:30:03 | 显示全部楼层
顶的就是你
authicon Pianissimo 发表于 2011-5-9 02:29:54 | 显示全部楼层
哦哦,发财了啊,看到好东西啦
authicon melody0721 发表于 2011-5-9 08:29:42 | 显示全部楼层
很好的,我喜欢
authicon haidideyu 发表于 2011-5-9 10:29:33 | 显示全部楼层
好东西,要下来看看
authicon icenna 发表于 2011-5-9 18:59:57 | 显示全部楼层
支持!好东西,拿走了!
authicon 皆无 发表于 2011-5-9 21:29:59 | 显示全部楼层
楼主真强大
authicon 蓝色天空k 发表于 2011-5-10 01:29:58 | 显示全部楼层
不错,谢谢分享
authicon YY大兔子 发表于 2011-5-13 08:59:36 | 显示全部楼层
好像不错的样子
authicon fantuanzi 发表于 2011-5-16 05:59:45 | 显示全部楼层
很好 很强大。。谢谢分享
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

1314学习网 ( 浙ICP备10214163号 )

GMT+8, 2025-5-2 12:24

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表