【discuz x3】uc_client/client.php接口文件分析

<?php

/*
	[UCenter] (C)2001-2099 Comsenz Inc.
	This is NOT a freeware, use is subject to license terms

	$Id: client.php 1079 2011-04-02 07:29:36Z zhengqingpeng $
*/

if(!defined('UC_API')) {
	exit('Access denied');
}

error_reporting(0);//不显示所有错误提示

define('IN_UC', TRUE);
define('UC_CLIENT_VERSION', '1.6.0');
define('UC_CLIENT_RELEASE', '20110501');
define('UC_ROOT', substr(__FILE__, 0, -10));//http://localhost/discuz3/uc_client/
define('UC_DATADIR', UC_ROOT.'./data/');
define('UC_DATAURL', UC_API.'/data');
define('UC_API_FUNC', UC_CONNECT == 'mysql' ? 'uc_api_mysql' : 'uc_api_post');
$GLOBALS['uc_controls'] = array();

function uc_addslashes($string, $force = 0, $strip = FALSE) {
	!defined('MAGIC_QUOTES_GPC') && define('MAGIC_QUOTES_GPC', get_magic_quotes_gpc());
	if(!MAGIC_QUOTES_GPC || $force) {
		if(is_array($string)) {
			foreach($string as $key => $val) {
				$string[$key] = uc_addslashes($val, $force, $strip);
			}
		} else {
			$string = addslashes($strip ? stripslashes($string) : $string);
		}
	}
	return $string;
}

if(!function_exists('daddslashes')) {
	function daddslashes($string, $force = 0) {
		return uc_addslashes($string, $force);
	}
}

function uc_stripslashes($string) {
	!defined('MAGIC_QUOTES_GPC') && define('MAGIC_QUOTES_GPC', get_magic_quotes_gpc());
	if(MAGIC_QUOTES_GPC) {
		return stripslashes($string);
	} else {
		return $string;
	}
}

//将数据通过socket发送到ucenter
//模拟浏览器访问
function uc_api_post($module, $action, $arg = array()) {
	$s = $sep = '';
	foreach($arg as $k => $v) {
		$k = urlencode($k);
		if(is_array($v)) {
			$s2 = $sep2 = '';
			foreach($v as $k2 => $v2) {
				$k2 = urlencode($k2);
				$s2 .= "$sep2{$k}[$k2]=".urlencode(uc_stripslashes($v2));
				$sep2 = '&';
			}
			$s .= $sep.$s2;
		} else {
			$s .= "$sep$k=".urlencode(uc_stripslashes($v));
		}
		$sep = '&';
	}
        //返回传递给index.php文件的参数字符串,做为http协议头信息的一部分
	$postdata = uc_api_requestdata($module, $action, $s);
        //向http://localhost/discuz3/uc_server/index.php文件传递post数据
	return uc_fopen2(UC_API.'/index.php', 500000, $postdata, '', TRUE, UC_IP, 20);
}
/*
 * $module:其实就是uc_server/control/下的控制器
 * $action:其实就是uc_server/control/下控制器中的方法
 */
function uc_api_requestdata($module, $action, $arg='', $extra='') {
	$input = uc_api_input($arg);
        //拼接http协议头
	$post = "m=$module&a=$action&inajax=2&release=".UC_CLIENT_RELEASE."&input=$input&appid=".UC_APPID.$extra;
	return $post;
}

function uc_api_url($module, $action, $arg='', $extra='') {
	$url = UC_API.'/index.php?'.uc_api_requestdata($module, $action, $arg, $extra);
	return $url;
}

function uc_api_input($data) {
        //define('UC_KEY', '10Eewf2cB5i9j5f833se1aL2k7w6T9L540seh2I9R4neQcqf4667q1E273Odkf2a');
	$s = urlencode(uc_authcode($data.'&agent='.md5($_SERVER['HTTP_USER_AGENT'])."&time=".time(), 'ENCODE', UC_KEY));
	return $s;
}

function uc_api_mysql($model, $action, $args=array()) {
	global $uc_controls;
	if(empty($uc_controls[$model])) {
		include_once UC_ROOT.'./lib/db.class.php';//数据库操作类
		include_once UC_ROOT.'./model/base.php';//基础类
		include_once UC_ROOT."./control/$model.php";//控制器类:1、继承base基础类 2、类名为{$model}control,如:usercontrol
		//创建一个控制器类,如:new usercontrol();
                eval("\$uc_controls['$model'] = new {$model}control();");
	}
	if($action{0} != '_') {
		$args = uc_addslashes($args, 1, TRUE);
		$action = 'on'.$action;//控制器中的方法:以on开头
		$uc_controls[$model]->input = $args;//将传递过来的参数以键值对形式赋值给控制器的input属性(数组形式)
		return $uc_controls[$model]->$action($args);//调用控制器中的方法,并返回结果
	} else {
		return '';
	}
}

//序列化数据
function uc_serialize($arr, $htmlon = 0) {
	include_once UC_ROOT.'./lib/xml.class.php';
	return xml_serialize($arr, $htmlon);
}

//反序列化数据
function uc_unserialize($s) {
	include_once UC_ROOT.'./lib/xml.class.php';
	return xml_unserialize($s);
}

/*
 * string:用来接收需要加密或解密的字符串
 * operation:用来设置我要进行加密(ENCODE)或者解密(DECODE),默认是解密
 * key:这是一个加密密钥,让使用者能根据自己的想法进行加密,如果不设置默认使用ucenter的通讯key的md5(key),这样做是问了尽可能的安全
 * expiry:明文key有效期 
 */
function uc_authcode($string, $operation = 'DECODE', $key = '', $expiry = 0) {

	$ckey_length = 4;//动态密匙长度,相同的明文会生成不同密文就是依靠动态密匙

	$key = md5($key ? $key : UC_KEY);//默认key为32位md5加密
	$keya = md5(substr($key, 0, 16));//将key的前后16位分开,密匙a会参与加解密
	$keyb = md5(substr($key, 16, 16));//密匙b会用来做数据完整性验证
	$keyc = $ckey_length ? ($operation == 'DECODE' ? substr($string, 0, $ckey_length): substr(md5(microtime()), -$ckey_length)) : '';//密匙c用于变化生成的密文

	$cryptkey = $keya.md5($keya.$keyc);//PHP加密解密函数authcode参与运算的密匙
	$key_length = strlen($cryptkey);
        
        //明文,前10位用来保存时间戳,解密时验证数据有效性,10到26位用来保存$keyb(密匙b),解密时会通过这个密匙验证数据完整性
        //如果是解码的话,会从第$ckey_length位开始,因为密文前$ckey_length位保存 动态密匙,以保证解密正确
	$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();
        //PHP加密解密函数authcode产生密匙簿
	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;
	}
        //PHP加密解密函数authcode核心加解密部分
	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;
                //PHP加密解密函数authcode从密匙簿得出密匙进行异或,再转成字符
		$result .= chr(ord($string[$i]) ^ ($box[($box[$a] + $box[$j]) % 256]));
	}

	if($operation == 'DECODE') {
                /*
                 * substr($result, 0, 10) == 0 验证数据有效性
                 * substr($result, 0, 10) - time() > 0 验证数据有效性
                 * substr($result, 10, 16) == substr(md5(substr($result, 26).$keyb), 0, 16) 验证数据完整性
                 */
		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 {
                //PHP加密解密函数authcode把动态密匙保存在密文里,这也是为什么同样的明文,生产不同密文后能解密的原因
                // 因为加密后的密文可能是一些特殊字符,复制过程可能会丢失,所以用base64编码
		return $keyc.str_replace('=', '', base64_encode($result));
	}
}

//uc_fopen2调用uc_fopen模拟浏览器进行访问
/** 
*  远程打开URL
*  @param string $url		打开的url, 如 http://www.baidu.com/123.htm 
*  @param int $limit		取返回的数据的长度 
*  @param string $post		要发送的 POST 数据,如uid=1&password=1234 
*  @param string $cookie	要模拟的 COOKIE 数据,如uid=123&auth=a2323sd2323 
*  @param bool $bysocket	TRUE/FALSE 是否通过SOCKET打开 
*  @param string $ip		IP地址 
*  @param int $timeout		连接超时时间 
*  @param bool $block		是否为阻塞模式 
*  @return			取到的字符串 
*/
function uc_fopen2($url, $limit = 0, $post = '', $cookie = '', $bysocket = FALSE, $ip = '', $timeout = 15, $block = TRUE) {
	$__times__ = isset($_GET['__times__']) ? intval($_GET['__times__']) + 1 : 1;
	if($__times__ > 2) {
		return '';
	}
	$url .= (strpos($url, '?') === FALSE ? '?' : '&')."__times__=$__times__";
        //uc_fopen使用fsockopen模拟浏览器访问
	return uc_fopen($url, $limit, $post, $cookie, $bysocket, $ip, $timeout, $block);
}

//uc_fopen使用fsockopen模拟浏览器进行访问
function uc_fopen($url, $limit = 0, $post = '', $cookie = '', $bysocket = FALSE, $ip = '', $timeout = 15, $block = TRUE) {//block为是否阻塞:1-为阻塞同步模式,0-为非阻塞异步模式
	$return = '';
	$matches = parse_url($url);
	!isset($matches['host']) && $matches['host'] = '';
	!isset($matches['path']) && $matches['path'] = '';
	!isset($matches['query']) && $matches['query'] = '';
	!isset($matches['port']) && $matches['port'] = '';
	$host = $matches['host'];//主机名
        //path:?之前的脚本名称,如:"/index.php";query:?之后的键值对参数列表,如:"参数1=值1&参数2=值2"
	$path = $matches['path'] ? $matches['path'].($matches['query'] ? '?'.$matches['query'] : '') : '/';
	$port = !empty($matches['port']) ? $matches['port'] : 80;//端口
	if($post) {//有post数据的情况
		$out = "POST $path HTTP/1.0\r\n";
		$out .= "Accept: */*\r\n";
		//$out .= "Referer: $boardurl\r\n";
		$out .= "Accept-Language: zh-cn\r\n";
		$out .= "Content-Type: application/x-www-form-urlencoded\r\n";
		$out .= "User-Agent: $_SERVER[HTTP_USER_AGENT]\r\n";
		$out .= "Host: $host\r\n";
		$out .= 'Content-Length: '.strlen($post)."\r\n";
		$out .= "Connection: Close\r\n";
		$out .= "Cache-Control: no-cache\r\n";
		$out .= "Cookie: $cookie\r\n\r\n";
		$out .= $post;
	} else {//无post数据的情况
		$out = "GET $path HTTP/1.0\r\n";
		$out .= "Accept: */*\r\n";
		//$out .= "Referer: $boardurl\r\n";
		$out .= "Accept-Language: zh-cn\r\n";
		$out .= "User-Agent: $_SERVER[HTTP_USER_AGENT]\r\n";
		$out .= "Host: $host\r\n";
		$out .= "Connection: Close\r\n";
		$out .= "Cookie: $cookie\r\n\r\n";
	}

	if(function_exists('fsockopen')) {//fsockopen()函数以socket模拟HTTP协议(POST)
		$fp = @fsockopen(($ip ? $ip : $host), $port, $errno, $errstr, $timeout);
	} elseif (function_exists('pfsockopen')) {//打开网络的socket持续链接
		$fp = @pfsockopen(($ip ? $ip : $host), $port, $errno, $errstr, $timeout);
	} else {
		$fp = false;
	}

	if(!$fp) {
		return '';
	} else {
		stream_set_blocking($fp, $block);//默认$block为TRUE 为阻塞状态,需要等待执行
		stream_set_timeout($fp, $timeout);//设置超时时间
		@fwrite($fp, $out);//模拟浏览器发送数据
                //获取句柄状态
		$status = stream_get_meta_data($fp);//跟stream_set_timeout配合使用,如果没有stream_set_timeout,那么stream_get_meta_data返回数组中time_out为空,反之为1
		if(!$status['timed_out']) {
			while (!feof($fp)) {//fgets()函数:逐行读取
				if(($header = @fgets($fp)) && ($header == "\r\n" ||  $header == "\n")) {
					break;
				}
			}

			$stop = false;
			while(!feof($fp) && !$stop) {
                                //读取服务端返回的8192字长
				$data = fread($fp, ($limit == 0 || $limit > 8192 ? 8192 : $limit));
				$return .= $data;//返回请求的数据
				if($limit) {
					$limit -= strlen($data);//自减已经读取的
					$stop = $limit <= 0;//limit是否小于等于零
				}
			}
		}
		@fclose($fp);//关闭socket流连接
		return $return;//返回请求的数据
	}
}

function uc_app_ls() {
        //调用uc_client/control/app.php控制器文件中的onls函数
	$return = call_user_func(UC_API_FUNC, 'app', 'ls', array());
	return UC_CONNECT == 'mysql' ? $return : uc_unserialize($return);
}

function uc_feed_add($icon, $uid, $username, $title_template='', $title_data='', $body_template='', $body_data='', $body_general='', $target_ids='', $images = array()) {
        //调用uc_client/control/feed.php控制器文件中的onadd函数
	return call_user_func(UC_API_FUNC, 'feed', 'add',
		array(  'icon'=>$icon,
			'appid'=>UC_APPID,
			'uid'=>$uid,
			'username'=>$username,
			'title_template'=>$title_template,
			'title_data'=>$title_data,
			'body_template'=>$body_template,
			'body_data'=>$body_data,
			'body_general'=>$body_general,
			'target_ids'=>$target_ids,
			'image_1'=>$images[0]['url'],
			'image_1_link'=>$images[0]['link'],
			'image_2'=>$images[1]['url'],
			'image_2_link'=>$images[1]['link'],
			'image_3'=>$images[2]['url'],
			'image_3_link'=>$images[2]['link'],
			'image_4'=>$images[3]['url'],
			'image_4_link'=>$images[3]['link']
		)
	);
}

function uc_feed_get($limit = 100, $delete = TRUE) {
        //调用uc_client/control/feed.php控制器文件中的onget函数
	$return = call_user_func(UC_API_FUNC, 'feed', 'get', array('limit'=>$limit, 'delete'=>$delete));
	return UC_CONNECT == 'mysql' ? $return : uc_unserialize($return);
}

function uc_friend_add($uid, $friendid, $comment='') {
        //调用uc_client/control/friend.php控制器文件中的onadd函数
	return call_user_func(UC_API_FUNC, 'friend', 'add', array('uid'=>$uid, 'friendid'=>$friendid, 'comment'=>$comment));
}

function uc_friend_delete($uid, $friendids) {
        //调用uc_client/control/friend.php控制器文件中的ondelete函数
	return call_user_func(UC_API_FUNC, 'friend', 'delete', array('uid'=>$uid, 'friendids'=>$friendids));
}

function uc_friend_totalnum($uid, $direction = 0) {
        //调用uc_client/control/friend.php控制器文件中的totalnum函数
	return call_user_func(UC_API_FUNC, 'friend', 'totalnum', array('uid'=>$uid, 'direction'=>$direction));
}

function uc_friend_ls($uid, $page = 1, $pagesize = 10, $totalnum = 10, $direction = 0) {
        //调用uc_client/control/friend.php控制器文件中的onls函数
	$return = call_user_func(UC_API_FUNC, 'friend', 'ls', array('uid'=>$uid, 'page'=>$page, 'pagesize'=>$pagesize, 'totalnum'=>$totalnum, 'direction'=>$direction));
	return UC_CONNECT == 'mysql' ? $return : uc_unserialize($return);
}

/*
 * 作用:本接口函数用于新用户的注册
 * username:用户名
 * password:密码
 * email:邮箱
 * questionid:安全提问索引
 * answer:安全提问答案
 * return:
 *      大于 0:返回用户 ID,表示用户注册成功
        -1:用户名不合法
        -2:包含不允许注册的词语
        -3:用户名已经存在
        -4:Email 格式有误
        -5:Email 不允许注册
        -6:该 Email 已经被注册
 */
function uc_user_register($username, $password, $email, $questionid = '', $answer = '', $regip = '') {
        //调用uc_client/control/user.php控制器文件中的onregister函数
	return call_user_func(UC_API_FUNC, 'user', 'register', array('username'=>$username, 'password'=>$password, 'email'=>$email, 'questionid'=>$questionid, 'answer'=>$answer, 'regip' => $regip));
}

function uc_user_login($username, $password, $isuid = 0, $checkques = 0, $questionid = '', $answer = '') {
	$isuid = intval($isuid);//0-用户名登录  1-uid登录
        /*
         * 回调函数:调用client.php文件中的uc_api_mysql函数
         * UC_API_FUNC:要调用的函数名,uc_api_mysql
         * user:控制器,传递给uc_api_mysql函数的参数1
         * login:控制器中要调用的方法,传递给uc_api_mysql函数的参数2
         * array():给控制器中要调用的方法传递参数,传递给uc_api_mysql函数的参数3
         */
        //调用uc_client/control/user.php控制器文件中的onlogin函数
	$return = call_user_func(UC_API_FUNC, 'user', 'login', array('username'=>$username, 'password'=>$password, 'isuid'=>$isuid, 'checkques'=>$checkques, 'questionid'=>$questionid, 'answer'=>$answer));
	return UC_CONNECT == 'mysql' ? $return : uc_unserialize($return);
}

function uc_user_synlogin($uid) {
	$uid = intval($uid);
        //载入应用缓存文件
	if(@include UC_ROOT.'./data/cache/apps.php') {
		if(count($_CACHE['apps']) > 1) {
                        //将数据通过socket发送到ucenter,即:http://localhost/discuz3/uc_server
                        //调用uc_server/control/user.php文件中的onsynlogin函数
			$return = uc_api_post('user', 'synlogin', array('uid'=>$uid));
		} else {
			$return = '';
		}
	}
	return $return;
}

function uc_user_synlogout() {
	if(@include UC_ROOT.'./data/cache/apps.php') {
		if(count($_CACHE['apps']) > 1) {
                        //调用uc_server/control/user.php文件中的onsynlogout函数
			$return = uc_api_post('user', 'synlogout', array());
		} else {
			$return = '';
		}
	}
	return $return;
}

function uc_user_edit($username, $oldpw, $newpw, $email, $ignoreoldpw = 0, $questionid = '', $answer = '') {
        //调用uc_client/control/user.php控制器文件中的onedit函数
	return call_user_func(UC_API_FUNC, 'user', 'edit', array('username'=>$username, 'oldpw'=>$oldpw, 'newpw'=>$newpw, 'email'=>$email, 'ignoreoldpw'=>$ignoreoldpw, 'questionid'=>$questionid, 'answer'=>$answer));
}

function uc_user_delete($uid) {
        //调用uc_client/control/user.php控制器文件中的ondelete函数
	return call_user_func(UC_API_FUNC, 'user', 'delete', array('uid'=>$uid));
}

function uc_user_deleteavatar($uid) {
        //调用uc_server/control/user.php控制器文件中的ondeleteavatar函数
	uc_api_post('user', 'deleteavatar', array('uid'=>$uid));
}

function uc_user_checkname($username) {
        //调用uc_client/control/user.php控制器文件中的oncheck_username函数
	return call_user_func(UC_API_FUNC, 'user', 'check_username', array('username'=>$username));
}

function uc_user_checkemail($email) {
        //调用uc_client/control/user.php控制器文件中的oncheck_email函数
	return call_user_func(UC_API_FUNC, 'user', 'check_email', array('email'=>$email));
}

function uc_user_addprotected($username, $admin='') {
        //调用uc_client/control/user.php控制器文件中的onaddprotected函数
	return call_user_func(UC_API_FUNC, 'user', 'addprotected', array('username'=>$username, 'admin'=>$admin));
}

function uc_user_deleteprotected($username) {
        //调用uc_client/control/user.php控制器文件中的ondeleteprotected函数
	return call_user_func(UC_API_FUNC, 'user', 'deleteprotected', array('username'=>$username));
}

function uc_user_getprotected() {
        //调用uc_client/control/user.php控制器文件中的ongetprotected函数
	$return = call_user_func(UC_API_FUNC, 'user', 'getprotected', array('1'=>1));
	return UC_CONNECT == 'mysql' ? $return : uc_unserialize($return);
}

function uc_get_user($username, $isuid=0) {
        //调用uc_client/control/user.php控制器文件中的onget_user函数
	$return = call_user_func(UC_API_FUNC, 'user', 'get_user', array('username'=>$username, 'isuid'=>$isuid));
	return UC_CONNECT == 'mysql' ? $return : uc_unserialize($return);
}

function uc_user_merge($oldusername, $newusername, $uid, $password, $email) {
        //调用uc_client/control/user.php控制器文件中的onmerge函数
	return call_user_func(UC_API_FUNC, 'user', 'merge', array('oldusername'=>$oldusername, 'newusername'=>$newusername, 'uid'=>$uid, 'password'=>$password, 'email'=>$email));
}

function uc_user_merge_remove($username) {
        //调用uc_client/control/user.php控制器文件中的onmerge_remove函数
	return call_user_func(UC_API_FUNC, 'user', 'merge_remove', array('username'=>$username));
}

function uc_user_getcredit($appid, $uid, $credit) {
        //调用uc_server/control/user.php控制器文件中的ongetcredit函数
	return uc_api_post('user', 'getcredit', array('appid'=>$appid, 'uid'=>$uid, 'credit'=>$credit));
}

function uc_pm_location($uid, $newpm = 0) {
        //调用uc_server/control/pm_client.php控制器文件中的onls函数
	$apiurl = uc_api_url('pm_client', 'ls', "uid=$uid", ($newpm ? '&folder=newbox' : ''));
	@header("Expires: 0");
	@header("Cache-Control: private, post-check=0, pre-check=0, max-age=0", FALSE);
	@header("Pragma: no-cache");
	@header("location: $apiurl");
}

function uc_pm_checknew($uid, $more = 0) {
        //调用uc_client/control/pm.php控制器文件中的oncheck_newpm函数
	$return = call_user_func(UC_API_FUNC, 'pm', 'check_newpm', array('uid'=>$uid, 'more'=>$more));
	return (!$more || UC_CONNECT == 'mysql') ? $return : uc_unserialize($return);
}

function uc_pm_send($fromuid, $msgto, $subject, $message, $instantly = 1, $replypmid = 0, $isusername = 0, $type = 0) {
	if($instantly) {//直接发送短消息
		$replypmid = @is_numeric($replypmid) ? $replypmid : 0;
                //调用uc_client/control/pm.php控制器文件中的onsendpm函数
		return call_user_func(UC_API_FUNC, 'pm', 'sendpm', array('fromuid'=>$fromuid, 'msgto'=>$msgto, 'subject'=>$subject, 'message'=>$message, 'replypmid'=>$replypmid, 'isusername'=>$isusername, 'type' => $type));
	} else {
		$fromuid = intval($fromuid);
		$subject = rawurlencode($subject);
		$msgto = rawurlencode($msgto);
		$message = rawurlencode($message);
		$replypmid = @is_numeric($replypmid) ? $replypmid : 0;
		$replyadd = $replypmid ? "&pmid=$replypmid&do=reply" : '';
                //调用uc_server/control/pm_client.php控制器文件中的onsend函数
		$apiurl = uc_api_url('pm_client', 'send', "uid=$fromuid", "&msgto=$msgto&subject=$subject&message=$message$replyadd");
		@header("Expires: 0");
		@header("Cache-Control: private, post-check=0, pre-check=0, max-age=0", FALSE);
		@header("Pragma: no-cache");
		@header("location: ".$apiurl);
	}
}

function uc_pm_delete($uid, $folder, $pmids) {
        //调用uc_client/control/pm.php控制器文件中的ondelete函数
	return call_user_func(UC_API_FUNC, 'pm', 'delete', array('uid'=>$uid, 'pmids'=>$pmids));
}

function uc_pm_deleteuser($uid, $touids) {
        //调用uc_client/control/pm.php文件中的ondeleteuser函数
	return call_user_func(UC_API_FUNC, 'pm', 'deleteuser', array('uid'=>$uid, 'touids'=>$touids));
}

function uc_pm_deletechat($uid, $plids, $type = 0) {
        //调用uc_client/control/pm.php文件中的ondeletechat函数
	return call_user_func(UC_API_FUNC, 'pm', 'deletechat', array('uid'=>$uid, 'plids'=>$plids, 'type'=>$type));
}

function uc_pm_readstatus($uid, $uids, $plids = array(), $status = 0) {
        //调用uc_client/control/pm.php文件中的onreadstatus函数
	return call_user_func(UC_API_FUNC, 'pm', 'readstatus', array('uid'=>$uid, 'uids'=>$uids, 'plids'=>$plids, 'status'=>$status));
}

function uc_pm_list($uid, $page = 1, $pagesize = 10, $folder = 'inbox', $filter = 'newpm', $msglen = 0) {
	$uid = intval($uid);
	$page = intval($page);
	$pagesize = intval($pagesize);
        //调用uc_client/control/pm.php文件中的onls函数
	$return = call_user_func(UC_API_FUNC, 'pm', 'ls', array('uid'=>$uid, 'page'=>$page, 'pagesize'=>$pagesize, 'filter'=>$filter, 'msglen'=>$msglen));
	return UC_CONNECT == 'mysql' ? $return : uc_unserialize($return);
}

function uc_pm_ignore($uid) {
	$uid = intval($uid);
        //调用uc_client/control/pm.php文件中的onignore函数
	return call_user_func(UC_API_FUNC, 'pm', 'ignore', array('uid'=>$uid));
}

function uc_pm_view($uid, $pmid = 0, $touid = 0, $daterange = 1, $page = 0, $pagesize = 10, $type = 0, $isplid = 0) {
	$uid = intval($uid);
	$touid = intval($touid);
	$page = intval($page);
	$pagesize = intval($pagesize);
	$pmid = @is_numeric($pmid) ? $pmid : 0;
        //调用uc_client/control/pm.php文件中的onview函数
	$return = call_user_func(UC_API_FUNC, 'pm', 'view', array('uid'=>$uid, 'pmid'=>$pmid, 'touid'=>$touid, 'daterange'=>$daterange, 'page' => $page, 'pagesize' => $pagesize, 'type'=>$type, 'isplid'=>$isplid));
	return UC_CONNECT == 'mysql' ? $return : uc_unserialize($return);
}

function uc_pm_view_num($uid, $touid, $isplid) {
	$uid = intval($uid);
	$touid = intval($touid);
	$isplid = intval($isplid);
        //调用uc_client/control/pm.php文件中的onviewnum函数
	return call_user_func(UC_API_FUNC, 'pm', 'viewnum', array('uid' => $uid, 'touid' => $touid, 'isplid' => $isplid));
}

function uc_pm_viewnode($uid, $type, $pmid) {
	$uid = intval($uid);
	$type = intval($type);
	$pmid = @is_numeric($pmid) ? $pmid : 0;
        //调用uc_client/control/pm.php文件中的onviewnode函数
	$return = call_user_func(UC_API_FUNC, 'pm', 'viewnode', array('uid'=>$uid, 'type'=>$type, 'pmid'=>$pmid));
	return UC_CONNECT == 'mysql' ? $return : uc_unserialize($return);
}

function uc_pm_chatpmmemberlist($uid, $plid = 0) {
	$uid = intval($uid);
	$plid = intval($plid);
        //调用uc_client/control/pm.php文件中的onchatpmmemberlist函数
	$return = call_user_func(UC_API_FUNC, 'pm', 'chatpmmemberlist', array('uid'=>$uid, 'plid'=>$plid));
	return UC_CONNECT == 'mysql' ? $return : uc_unserialize($return);
}

function uc_pm_kickchatpm($plid, $uid, $touid) {
	$uid = intval($uid);
	$plid = intval($plid);
	$touid = intval($touid);
        //调用uc_client/control/pm.php文件中的onkickchatpm函数
	return call_user_func(UC_API_FUNC, 'pm', 'kickchatpm', array('uid'=>$uid, 'plid'=>$plid, 'touid'=>$touid));
}

function uc_pm_appendchatpm($plid, $uid, $touid) {
	$uid = intval($uid);
	$plid = intval($plid);
	$touid = intval($touid);
        //调用uc_client/control/pm.php文件中的onappendchatpm函数
	return call_user_func(UC_API_FUNC, 'pm', 'appendchatpm', array('uid'=>$uid, 'plid'=>$plid, 'touid'=>$touid));
}

function uc_pm_blackls_get($uid) {
	$uid = intval($uid);
        //调用uc_client/control/pm.php文件中的onblackls_get函数
	return call_user_func(UC_API_FUNC, 'pm', 'blackls_get', array('uid'=>$uid));
}

function uc_pm_blackls_set($uid, $blackls) {
	$uid = intval($uid);
        //调用uc_client/control/pm.php文件中的onblackls_set函数
	return call_user_func(UC_API_FUNC, 'pm', 'blackls_set', array('uid'=>$uid, 'blackls'=>$blackls));
}

function uc_pm_blackls_add($uid, $username) {
	$uid = intval($uid);
        //调用uc_client/control/pm.php文件中的onblackls_add函数
	return call_user_func(UC_API_FUNC, 'pm', 'blackls_add', array('uid'=>$uid, 'username'=>$username));
}

function uc_pm_blackls_delete($uid, $username) {
	$uid = intval($uid);
        //调用uc_client/control/pm.php文件中的onblackls_delete函数
	return call_user_func(UC_API_FUNC, 'pm', 'blackls_delete', array('uid'=>$uid, 'username'=>$username));
}

function uc_domain_ls() {
        //调用uc_client/control/domain.php文件中的onls函数
	$return = call_user_func(UC_API_FUNC, 'domain', 'ls', array('1'=>1));
	return UC_CONNECT == 'mysql' ? $return : uc_unserialize($return);
}

function uc_credit_exchange_request($uid, $from, $to, $toappid, $amount) {
	$uid = intval($uid);
	$from = intval($from);
	$toappid = intval($toappid);
	$to = intval($to);
	$amount = intval($amount);
        //调用uc_server/control/credit.php文件中的onrequest函数
	return uc_api_post('credit', 'request', array('uid'=>$uid, 'from'=>$from, 'to'=>$to, 'toappid'=>$toappid, 'amount'=>$amount));
}

function uc_tag_get($tagname, $nums = 0) {
        //调用uc_client/control/tag.php文件中的ongettag函数
	$return = call_user_func(UC_API_FUNC, 'tag', 'gettag', array('tagname'=>$tagname, 'nums'=>$nums));
	return UC_CONNECT == 'mysql' ? $return : uc_unserialize($return);
}

//生成装载camera.swf的html代码
//本接口函数用于返回设置用户头像的html代码,html代码会输出一个flash
function uc_avatar($uid, $type = 'virtual', $returnhtml = 1) {//参数2,real-真实头像,virtual-虚拟头像
	$uid = intval($uid);
        //加密值
	$uc_input = uc_api_input("uid=$uid");
        //UC_API:'http://localhost/discuz3/uc_server'
        //UC_APPID:1
	$uc_avatarflash = UC_API.'/images/camera.swf?inajax=1&appid='.UC_APPID.'&input='.$uc_input.'&agent='.md5($_SERVER['HTTP_USER_AGENT']).'&ucapi='.urlencode(str_replace('http://', '', UC_API)).'&avatartype='.$type.'&uploadSize=2048';
	if($returnhtml) {//返回设置头像的html代码
		return '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="450" height="253" id="mycamera" align="middle">
			<param name="allowScriptAccess" value="always" />
			<param name="scale" value="exactfit" />
			<param name="wmode" value="transparent" />
			<param name="quality" value="high" />
			<param name="bgcolor" value="#ffffff" />
			<param name="movie" value="'.$uc_avatarflash.'" />
			<param name="menu" value="false" />
			<embed src="'.$uc_avatarflash.'" quality="high" bgcolor="#ffffff" width="450" height="253" name="mycamera" align="middle" allowScriptAccess="always" allowFullScreen="false" scale="exactfit"  wmode="transparent" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
		</object>';
	} else {//返回设置头像的flash调用数组
		return array(
			'width', '450',
			'height', '253',
			'scale', 'exactfit',
			'src', $uc_avatarflash,
			'id', 'mycamera',
			'name', 'mycamera',
			'quality','high',
			'bgcolor','#ffffff',
			'menu', 'false',
			'swLiveConnect', 'true',
			'allowScriptAccess', 'always'
		);
	}
}

function uc_mail_queue($uids, $emails, $subject, $message, $frommail = '', $charset = 'gbk', $htmlon = FALSE, $level = 1) {
        //调用uc_client/control/mail.php文件中的onadd函数
	return call_user_func(UC_API_FUNC, 'mail', 'add', array('uids' => $uids, 'emails' => $emails, 'subject' => $subject, 'message' => $message, 'frommail' => $frommail, 'charset' => $charset, 'htmlon' => $htmlon, 'level' => $level));
}

//检测头像是否存在
function uc_check_avatar($uid, $size = 'middle', $type = 'virtual') {
        //UC_API:http://localhost/discuz3/uc_server/
	$url = UC_API."/avatar.php?uid=$uid&size=$size&type=$type&check_file_exists=1";
	$res = uc_fopen2($url, 500000, '', '', TRUE, UC_IP, 20);
	if($res == 1) {
		return 1;//头像存在
	} else {
		return 0;//头像不存在
	}
}

function uc_check_version() {
        //调用uc_server/control/version.php文件中的oncheck函数
	$return = uc_api_post('version', 'check', array());
	$data = uc_unserialize($return);
	return is_array($data) ? $data : $return;
}

?>

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值