找回密码
 立即注册
搜索
查看: 202|回复: 0

[内置扩展] Discuz x3.5 核心文件 uc_client/client.php 函数注释

[复制链接]
 楼主| 发表于 2024-3-27 21:23:01 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区

您需要 登录 才可以下载或查看,没有账号?立即注册

×
[PHP] 纯文本查看 复制代码
<?php

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

	$Id: client.php 1179 2014-11-03 07:11:25Z hypowang $
*/

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

error_reporting(0);

define('IN_UC', TRUE);
define('UC_ROOT', substr(__FILE__, 0, -10));
require UC_ROOT.'./release/release.php';
define('UC_DATADIR', UC_ROOT.'./data/');
define('UC_DATAURL', UC_API.'/data');
define('UC_API_FUNC', ((defined('UC_CONNECT') && UC_CONNECT == 'mysql') || UC_STANDALONE) ? 'uc_api_mysql' : 'uc_api_post');
$uc_controls = array();
/**
 * 添加反斜线,支持数组递归处理
 *
 * @param mixed $string 要处理的字符串或数组
 * @param int $force 强制处理标志,默认为0
 * @param bool $strip 先去除斜线再添加,默认为FALSE
 * @return mixed 处理后的字符串或数组
 */
function uc_addslashes($string, $force = 0, $strip = FALSE) {
    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;
}

/**
 * 代理函数,用于添加反斜线
 *
 * @param string $string 要处理的字符串
 * @param int $force 强制处理标志,默认为0
 * @return string 处理后的字符串
 */
if(!function_exists('daddslashes')) {
    function daddslashes($string, $force = 0) {
        return uc_addslashes($string, $force);
    }
}

/**
 * 转义HTML特殊字符,支持数组递归处理
 *
 * @param string|array $string 要处理的字符串或数组
 * @param int|null $flags HTML转义标志,默认为null
 * @return string|array 处理后的字符串或数组
 */
if(!function_exists('dhtmlspecialchars')) {
    function dhtmlspecialchars($string, $flags = null) {
        if(is_array($string)) {
            foreach($string as $key => $val) {
                $string[$key] = dhtmlspecialchars($val, $flags);
            }
        } else {
            if($flags === null) {
                $string = str_replace(array('&', '"', '<', '>'), array('&', '"', '<', '>'), $string);
                if(strpos($string, '&#') !== false) {
                    $string = preg_replace('/&((#(\d{3,5}|x[a-fA-F0-9]{4}));)/', '&\\1', $string);
                }
            } else {
                if(PHP_VERSION < '5.4.0') {
                    $string = htmlspecialchars($string, $flags);
                } else {
                    if(strtolower(CHARSET) == 'utf-8') {
                        $charset = 'UTF-8';
                    } else {
                        $charset = 'ISO-8859-1';
                    }
                    $string = htmlspecialchars($string, $flags, $charset);
                }
            }
        }
        return $string;
    }
}

/**
 * 代理函数,用于打开socket连接
 *
 * @param string $hostname 目标主机名
 * @param int $port 目标端口号,默认为80
 * @param int &$errno 用于存储错误码的引用
 * @param string &$errstr 用于存储错误信息的引用
 * @param int $timeout 连接超时时间,默认为15秒
 * @return resource 返回socket连接资源,失败返回false
 */
if(!function_exists('fsocketopen')) {
    function fsocketopen($hostname, $port = 80, &$errno = null, &$errstr = null, $timeout = 15) {
        $fp = '';
        if(function_exists('fsockopen')) {
            $fp = @fsockopen($hostname, $port, $errno, $errstr, $timeout);
        } elseif(function_exists('pfsockopen')) {
            $fp = @pfsockopen($hostname, $port, $errno, $errstr, $timeout);
        } elseif(function_exists('stream_socket_client')) {
            $fp = @stream_socket_client($hostname.':'.$port, $errno, $errstr, $timeout);
        }
        return $fp;
    }
}

/**
 * 发送API请求,通过POST方法
 *
 * @param string $module API模块
 * @param string $action API操作
 * @param array $arg 请求参数
 * @return string 请求结果
 */
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($v2);
                $sep2 = '&';
            }
            $s .= $sep.$s2;
        } else {
            $s .= "$sep$k=".urlencode($v);
        }
        $sep = '&';
    }
    $postdata = uc_api_requestdata($module, $action, $s);
    return uc_fopen2(UC_API.'/index.php', 500000, $postdata, '', TRUE, UC_IP, 20);
}
/**
 * 向UCenter发送请求的数据
 *
 * @param string $module 模块名
 * @param string $action 动作名
 * @param string $arg 请求的参数
 * @param string $extra 额外的参数
 * @return string 构造的请求数据
 */
function uc_api_requestdata($module, $action, $arg='', $extra='') {
	$input = uc_api_input($arg, $module, $action);
	$post = "m=$module&a=$action&inajax=2&release=".UC_CLIENT_RELEASE."&input=$input&appid=".UC_APPID.$extra;
	return $post;
}

/**
 * 获取向UCenter发送请求的URL
 *
 * @param string $module 模块名
 * @param string $action 动作名
 * @param string $arg 请求的参数
 * @param string $extra 额外的参数
 * @return string 请求的URL
 */
function uc_api_url($module, $action, $arg='', $extra='') {
	$url = UC_API.'/index.php?'.uc_api_requestdata($module, $action, $arg, $extra);
	return $url;
}

/**
 * 对请求的数据进行编码
 *
 * @param string $data 要编码的数据
 * @param string $module 模块名
 * @param string $action 动作名
 * @return string 编码后的数据
 */
function uc_api_input($data, $module, $action) {
	$data = $data."&m=$module&a=$action&appid=".UC_APPID;
	$s = urlencode(uc_authcode($data.'&agent='.md5($_SERVER['HTTP_USER_AGENT'])."&time=".time(), 'ENCODE', UC_KEY));
	return $s;
}

/**
 * 执行与UCenter的通信操作
 *
 * @param string $model 模型名
 * @param string $action 动作名
 * @param array $args 请求参数
 * @return mixed 执行结果
 */
function uc_api_mysql($model, $action, $args=array()) {
	global $uc_controls;
	if(empty($uc_controls[$model])) {
		// 加载必要的类文件
		include_once UC_ROOT.'./lib/dbi.class.php';
		include_once UC_ROOT.'./model/base.php';
		include_once UC_ROOT."./control/$model.php";
		$modelname = $model.'control';
		$uc_controls[$model] = new $modelname();
	}
	if($action[0] != '_') {
		$args = uc_addslashes($args, 1, TRUE);
		$action = 'on'.$action;
		$uc_controls[$model]->input = $args;
		return $uc_controls[$model]->$action($args);
	} else {
		return '';
	}
}

/**
 * 序列化数据
 *
 * @param array $arr 要序列化的数组
 * @param int $htmlon 是否输出html标签
 * @return string 序列化后的数据
 */
function uc_serialize($arr, $htmlon = 0) {
	include_once UC_ROOT.'./lib/xml.class.php';
	return xml_serialize($arr, $htmlon);
}

/**
 * 反序列化数据
 *
 * @param string $s 序列化的数据
 * @return array 反序列化后的数据
 */
function uc_unserialize($s) {
	include_once UC_ROOT.'./lib/xml.class.php';
	return xml_unserialize($s);
}

/**
 * 对数据进行加密或解密
 *
 * @param string $string 要处理的字符串
 * @param string $operation 加密还是解密操作
 * @param string $key 加密密钥
 * @param int $expiry 密码的有效期
 * @return string 处理后的字符串
 */
function uc_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 < $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(((int)substr($result, 0, 10) == 0 || (int)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));
	}
}

/**
 * 通过URL打开资源,支持GET和POST请求,可设置请求限制、发送cookie、通过指定IP强制路由等。
 *
 * @param string $url 请求的URL地址
 * @param int $limit 返回数据的最大限制字节数,0表示无限制
 * @param string $post 发送的POST数据,为空则执行GET请求
 * @param string $cookie 要发送的cookie信息
 * @param bool $bysocket 是否通过socket连接
 * @param string $ip 指定的IP地址,用于强制路由
 * @param int $timeout 连接和读取的超时时间(秒)
 * @param bool $block 是否设置为阻塞模式
 * @param string $encodetype POST数据的编码类型,'URLENCODE'或其它(用于多文件上传)
 * @param bool $allowcurl 是否允许使用curl发起请求
 * @return string|void 返回请求到的数据,请求失败则返回空
 */
function uc_fopen2($url, $limit = 0, $post = '', $cookie = '', $bysocket = FALSE, $ip = '', $timeout = 15, $block = TRUE, $encodetype  = 'URLENCODE', $allowcurl = TRUE) {
    // 防止循环请求
    $__times__ = isset($_GET['__times__']) ? intval($_GET['__times__']) + 1 : 1;
    if($__times__ > 2) {
        return '';
    }
    // 添加请求次数参数到URL中
    $url .= (strpos($url, '?') === FALSE ? '?' : '&')."__times__=$__times__";
    // 递归调用uc_fopen函数完成实际请求
    return uc_fopen($url, $limit, $post, $cookie, $bysocket, $ip, $timeout, $block, $encodetype, $allowcurl);
}

/**
 * 实际执行HTTP请求的函数
 *
 * @param string $url 请求的URL地址
 * @param int $limit 返回数据的最大限制字节数,0表示无限制
 * @param string $post 发送的POST数据,为空则执行GET请求
 * @param string $cookie 要发送的cookie信息
 * @param bool $bysocket 是否通过socket连接
 * @param string $ip 指定的IP地址,用于强制路由
 * @param int $timeout 连接和读取的超时时间(秒)
 * @param bool $block 是否设置为阻塞模式
 * @param string $encodetype POST数据的编码类型,'URLENCODE'或其它(用于多文件上传)
 * @param bool $allowcurl 是否允许使用curl发起请求
 * @return string|void 返回请求到的数据,请求失败则返回空
 */
function uc_fopen($url, $limit = 0, $post = '', $cookie = '', $bysocket = FALSE, $ip = '', $timeout = 15, $block = TRUE, $encodetype  = 'URLENCODE', $allowcurl = TRUE) {
    $return = '';
    // 解析URL
    $matches = parse_url($url);
    $scheme = strtolower($matches['scheme']);
    $host = $matches['host'];
    $path = !empty($matches['path']) ? $matches['path'].(!empty($matches['query']) ? '?'.$matches['query'] : '') : '/';
    $port = !empty($matches['port']) ? $matches['port'] : ($scheme == 'https' ? 443 : 80);

    // 尝试使用curl发送请求
    if(function_exists('curl_init') && function_exists('curl_exec') && $allowcurl) {
        $ch = curl_init();
        $ip && curl_setopt($ch, CURLOPT_HTTPHEADER, array("Host: ".$host));
        curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
        // 设置IP解析和请求URL
        if(!empty($ip) && filter_var($ip, FILTER_VALIDATE_IP) && !filter_var($host, FILTER_VALIDATE_IP) && version_compare(PHP_VERSION, '5.5.0', 'ge')) {
            curl_setopt($ch, CURLOPT_RESOLVE, array("$host:$port:$ip"));
            curl_setopt($ch, CURLOPT_URL, $scheme.'://'.$host.':'.$port.$path);
        } else {
            curl_setopt($ch, CURLOPT_URL, $scheme.'://'.($ip ? $ip : $host).':'.$port.$path);
        }
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        // 设置POST请求
        if($post) {
            curl_setopt($ch, CURLOPT_POST, 1);
            if($encodetype == 'URLENCODE') {
                curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
            } else {
                parse_str($post, $postarray);
                curl_setopt($ch, CURLOPT_POSTFIELDS, $postarray);
            }
        }
        // 设置cookie
        if($cookie) {
            curl_setopt($ch, CURLOPT_COOKIE, $cookie);
        }
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
        $data = curl_exec($ch);
        $status = curl_getinfo($ch);
        $errno = curl_errno($ch);
        curl_close($ch);
        // 处理请求错误
        if($errno || $status['http_code'] != 200) {
            return;
        } else {
            return !$limit ? $data : substr($data, 0, $limit);
        }
    }

    // 使用fopen和stream_socket_client发送请求
    if($post) {
        $out = "POST $path HTTP/1.0\r\n";
        $header = "Accept: */*\r\n";
        $header .= "Accept-Language: zh-cn\r\n";
        if($allowcurl) {
            $encodetype = 'URLENCODE';
        }
        $boundary = $encodetype == 'URLENCODE' ? '' : '; boundary='.trim(substr(trim($post), 2, strpos(trim($post), "\n") - 2));
        $header .= $encodetype == 'URLENCODE' ? "Content-Type: application/x-www-form-urlencoded\r\n" : "Content-Type: multipart/form-data$boundary\r\n";
        $header .= "User-Agent: {$_SERVER['HTTP_USER_AGENT']}\r\n";
        $header .= "Host: $host:$port\r\n";
        $header .= 'Content-Length: '.strlen($post)."\r\n";
        $header .= "Connection: Close\r\n";
        $header .= "Cache-Control: no-cache\r\n";
        $header .= "Cookie: $cookie\r\n\r\n";
        $out .= $header.$post;
    } else {
        $out = "GET $path HTTP/1.0\r\n";
        $header = "Accept: */*\r\n";
        $header .= "Accept-Language: zh-cn\r\n";
        $header .= "User-Agent: {$_SERVER['HTTP_USER_AGENT']}\r\n";
        $header .= "Host: $host:$port\r\n";
        $header .= "Connection: Close\r\n";
        $header .= "Cookie: $cookie\r\n\r\n";
        $out .= $header;
    }

    $fpflag = 0;
    $context = array();
    // 设置HTTPS请求的上下文选项
    if($scheme == 'https') {
        $context['ssl'] = array(
            'verify_peer' => false,
            'verify_peer_name' => false,
            'peer_name' => $host
        );
        if(version_compare(PHP_VERSION, '5.6.0', '<')) {
            $context['ssl']['SNI_enabled'] = true;
            $context['ssl']['SNI_server_name'] = $host;
        }
    }
    // 创建HTTP请求的上下文
    if(ini_get('allow_url_fopen')) {
        $context['http'] = array(
            'method' => $post ? 'POST' : 'GET',
            'header' => $header,
            'timeout' => $timeout
        );
        if($post) {
            $context['http']['content'] = $post;
        }
        $context = stream_context_create($context);
        $fp = @fopen($scheme.'://'.($ip ? $ip : $host).':'.$port.$path, 'b', false, $context);
        $fpflag = 1;
    } elseif(function_exists('stream_socket_client')) {
        $context = stream_context_create($context);
        $fp = @stream_socket_client(($scheme == 'https' ? 'ssl://' : '').($ip ? $ip : $host).':'.$port, $errno, $errstr, $timeout, STREAM_CLIENT_CONNECT, $context);
    } else {
        $fp = @fsocketopen(($scheme == 'https' ? 'ssl://' : '').($scheme == 'https' ? $host : ($ip ? $ip : $host)), $port, $errno, $errstr, $timeout);
    }

    if(!$fp) {
        return '';
    } else {
        stream_set_blocking($fp, $block);
        stream_set_timeout($fp, $timeout);
        if(!$fpflag) {
            @fwrite($fp, $out);
        }
        $status = stream_get_meta_data($fp);
        if(!$status['timed_out']) {
            // 读取HTTP响应头
            while (!feof($fp) && !$fpflag) {
                if(($header = @fgets($fp)) && ($header == "\r\n" ||  $header == "\n")) {
                    break;
                }
            }

            // 读取响应体
            $stop = false;
            while(!feof($fp) && !$stop) {
                $data = fread($fp, ($limit == 0 || $limit > 8192 ? 8192 : $limit));
                $return .= $data;
                if($limit) {
                    $limit -= strlen($data);
                    $stop = $limit <= 0;
                }
            }
        }
        @fclose($fp);
        return $return;
    }
}
/**
 * 获取应用列表
 */
function uc_app_ls() {
    $return = call_user_func(UC_API_FUNC, 'app', 'ls', array());
    return UC_CONNECT == 'mysql' ? $return : uc_unserialize($return);
}

/**
 * 添加Feed
 *
 * @param string $icon 图标链接
 * @param int $uid 用户ID
 * @param string $username 用户名
 * @param string $title_template 标题模板
 * @param string $title_data 标题数据
 * @param string $body_template 正文模板
 * @param string $body_data 正文数据
 * @param string $body_general 简化正文
 * @param string $target_ids 目标ID
 * @param array $images 图片数组
 * @return mixed 添加结果
 */
function uc_feed_add($icon, $uid, $username, $title_template='', $title_data='', $body_template='', $body_data='', $body_general='', $target_ids='', $images = array()) {
    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']
        )
    );
}

/**
 * 获取Feed列表
 *
 * @param int $limit 获取数量
 * @param bool $delete 是否删除已获取的Feed
 * @return mixed 返回Feed列表
 */
function uc_feed_get($limit = 100, $delete = TRUE) {
    $return = call_user_func(UC_API_FUNC, 'feed', 'get', array('limit'=>$limit, 'delete'=>$delete));
    return UC_CONNECT == 'mysql' ? $return : uc_unserialize($return);
}

/**
 * 添加好友
 *
 * @param int $uid 用户ID
 * @param int $friendid 好友ID
 * @param string $comment 添加好友时的备注信息
 * @return mixed 添加结果
 */
function uc_friend_add($uid, $friendid, $comment='') {
    return call_user_func(UC_API_FUNC, 'friend', 'add', array('uid'=>$uid, 'friendid'=>$friendid, 'comment'=>$comment));
}

/**
 * 删除好友
 *
 * @param int $uid 用户ID
 * @param array $friendids 好友ID数组
 * @return mixed 删除结果
 */
function uc_friend_delete($uid, $friendids) {
    return call_user_func(UC_API_FUNC, 'friend', 'delete', array('uid'=>$uid, 'friendids'=>$friendids));
}

/**
 * 获取好友总数
 *
 * @param int $uid 用户ID
 * @param int $direction 0代表获取好友数量,1代表获取请求数量
 * @return mixed 好友总数
 */
function uc_friend_totalnum($uid, $direction = 0) {
    return call_user_func(UC_API_FUNC, 'friend', 'totalnum', array('uid'=>$uid, 'direction'=>$direction));
}

/**
 * 获取好友列表
 *
 * @param int $uid 用户ID
 * @param int $page 页码
 * @param int $pagesize 每页数量
 * @param int $totalnum 总数
 * @param int $direction 0代表获取好友,1代表获取请求
 * @return mixed 返回好友列表
 */
function uc_friend_ls($uid, $page = 1, $pagesize = 10, $totalnum = 10, $direction = 0) {
    $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);
}

/**
 * 注册用户
 *
 * @param string $username 用户名
 * @param string $password 密码
 * @param string $email 邮箱
 * @param int $questionid 安全问题ID
 * @param string $answer 安全问题答案
 * @param string $regip 注册IP
 * @return mixed 注册结果
 */
function uc_user_register($username, $password, $email, $questionid = '', $answer = '', $regip = '') {
    return call_user_func(UC_API_FUNC, 'user', 'register', array('username'=>$username, 'password'=>$password, 'email'=>$email, 'questionid'=>$questionid, 'answer'=>$answer, 'regip' => $regip));
}

/**
 * 用户登录
 *
 * @param string $username 用户名
 * @param string $password 密码
 * @param int $isuid 是否使用UID登录
 * @param int $checkques 是否检查安全问题
 * @param string $questionid 安全问题ID
 * @param string $answer 安全问题答案
 * @param string $ip 登录IP
 * @param int $nolog 是否不记录登录
 * @return mixed 登录结果
 */
function uc_user_login($username, $password, $isuid = 0, $checkques = 0, $questionid = '', $answer = '', $ip = '', $nolog = 0) {
    $isuid = intval($isuid);
    $return = call_user_func(UC_API_FUNC, 'user', 'login', array('username'=>$username, 'password'=>$password, 'isuid'=>$isuid, 'checkques'=>$checkques, 'questionid'=>$questionid, 'answer'=>$answer, 'ip' => $ip, 'nolog' => $nolog));
    return UC_CONNECT == 'mysql' ? $return : uc_unserialize($return);
}

/**
 * 同步登录
 *
 * @param int $uid 用户ID
 * @return string 返回同步登录的代码
 */
function uc_user_synlogin($uid) {
    if(UC_STANDALONE) {
        return '';
    }
    $uid = intval($uid);
    if(@include UC_ROOT.'./data/cache/apps.php') {
        if(count($_CACHE['apps']) > 1) {
            $return = uc_api_post('user', 'synlogin', array('uid'=>$uid));
        } else {
            $return = '';
        }
    }
    return $return;
}

/**
 * 同步登出
 *
 * @return string 返回同步登出的代码
 */
function uc_user_synlogout() {
    if(UC_STANDALONE) {
        return '';
    }
    if(@include UC_ROOT.'./data/cache/apps.php') {
        if(count($_CACHE['apps']) > 1) {
            $return = uc_api_post('user', 'synlogout', array());
        } else {
            $return = '';
        }
    }
    return $return;
}

/**
 * 修改用户信息
 *
 * @param string $username 用户名
 * @param string $oldpw 旧密码
 * @param string $newpw 新密码
 * @param string $email 邮箱
 * @param int $ignoreoldpw 是否忽略旧密码
 * @param int $questionid 安全问题ID
 * @param string $answer 安全问题答案
 * @param string $secmobicc 验证码
 * @param string $secmobile 手机号码
 * @return mixed 修改结果
 */
function uc_user_edit($username, $oldpw, $newpw, $email, $ignoreoldpw = 0, $questionid = '', $answer = '', $secmobicc = '', $secmobile = '') {
    return call_user_func(UC_API_FUNC, 'user', 'edit', array('username'=>$username, 'oldpw'=>$oldpw, 'newpw'=>$newpw, 'email'=>$email, 'ignoreoldpw'=>$ignoreoldpw, 'questionid'=>$questionid, 'answer'=>$answer, 'secmobicc'=>$secmobicc, 'secmobile'=>$secmobile));
}

/**
 * 删除用户
 *
 * @param int $uid 用户ID
 * @return mixed 删除结果
 */
function uc_user_delete($uid) {
    return call_user_func(UC_API_FUNC, 'user', 'delete', array('uid'=>$uid, 'action'=>'delete'));
}

/**
 * 删除用户头像
 * @param $uid 用户ID
 */
function uc_user_deleteavatar($uid) {
    if(UC_STANDALONE) {
        @include_once UC_ROOT.'./extend_client.php';
        uc_note_handler::loadavatarpath();
        uc_api_mysql('user', 'deleteavatar', array('uid'=>$uid));
    } else {
        uc_api_post('user', 'deleteavatar', array('uid'=>$uid));
    }
}

/**
 * 检查用户名是否可用
 * @param $username 待检查的用户名
 * @return 检查结果
 */
function uc_user_checkname($username) {
    return call_user_func(UC_API_FUNC, 'user', 'check_username', array('username'=>$username));
}

/**
 * 检查邮箱是否可用
 * @param $email 待检查的邮箱地址
 * @return 检查结果
 */
function uc_user_checkemail($email) {
    return call_user_func(UC_API_FUNC, 'user', 'check_email', array('email'=>$email));
}

/**
 * 检查辅助手机号是否可用
 * @param $secmobicc 手机运营商编码
 * @param $secmobile 辅助手机号
 * @return 检查结果
 */
function uc_user_checksecmobile($secmobicc, $secmobile) {
    return call_user_func(UC_API_FUNC, 'user', 'check_secmobile', array('secmobicc'=>$secmobicc, 'secmobile'=>$secmobile));
}

/**
 * 添加受保护的用户名
 * @param $username 待添加的用户名
 * @param $admin 添加的管理员(可选)
 * @return 添加结果
 */
function uc_user_addprotected($username, $admin='') {
    return call_user_func(UC_API_FUNC, 'user', 'addprotected', array('username'=>$username, 'admin'=>$admin));
}

/**
 * 删除受保护的用户名
 * @param $username 待删除的用户名
 * @return 删除结果
 */
function uc_user_deleteprotected($username) {
    return call_user_func(UC_API_FUNC, 'user', 'deleteprotected', array('username'=>$username));
}

/**
 * 获取受保护的用户名列表
 * @return 受保护的用户名列表
 */
function uc_user_getprotected() {
    $return = call_user_func(UC_API_FUNC, 'user', 'getprotected', array('1'=>1));
    return UC_CONNECT == 'mysql' ? $return : uc_unserialize($return);
}

/**
 * 获取用户信息
 * @param $username 用户名
 * @param $isuid 是否为用户ID (0: 不是, 非0: 是)
 * @return 用户信息
 */
function uc_get_user($username, $isuid=0) {
    $return = call_user_func(UC_API_FUNC, 'user', 'get_user', array('username'=>$username, 'isuid'=>$isuid));
    return UC_CONNECT == 'mysql' ? $return : uc_unserialize($return);
}

/**
 * 更改用户名
 * @param $uid 用户ID
 * @param $newusername 新用户名
 * @return 更改结果
 */
function uc_user_chgusername($uid, $newusername) {
    return call_user_func(UC_API_FUNC, 'user', 'chgusername', array('uid'=>$uid, 'newusername'=>$newusername));
}

/**
 * 用户合并
 * @param $oldusername 老用户名
 * @param $newusername 新用户名
 * @param $uid 用户ID
 * @param $password 用户密码
 * @param $email 用户邮箱
 * @return 合并结果
 */
function uc_user_merge($oldusername, $newusername, $uid, $password, $email) {
    return call_user_func(UC_API_FUNC, 'user', 'merge', array('oldusername'=>$oldusername, 'newusername'=>$newusername, 'uid'=>$uid, 'password'=>$password, 'email'=>$email));
}

/**
 * 用户合并后删除老用户
 * @param $username 要删除的用户名
 * @return 删除结果
 */
function uc_user_merge_remove($username) {
    return call_user_func(UC_API_FUNC, 'user', 'merge_remove', array('username'=>$username));
}

/**
 * 获取用户积分
 * @param $appid 应用ID
 * @param $uid 用户ID
 * @param $credit 积分名称
 * @return 积分值
 */
function uc_user_getcredit($appid, $uid, $credit) {
    return uc_api_post('user', 'getcredit', array('appid'=>$appid, 'uid'=>$uid, 'credit'=>$credit));
}

/**
 * 检查用户登录状态
 * @param $username 用户名
 * @param $ip 用户IP
 * @return 登录检查结果
 */
function uc_user_logincheck($username, $ip) {
    return call_user_func(UC_API_FUNC, 'user', 'logincheck', array('username' => $username, 'ip' => $ip));
}

/**
 * 设置私信位置
 * @param $uid 用户ID
 * @param $newpm 是否只读 (0: 未读, 1: 已读)
 */
function uc_pm_location($uid, $newpm = 0) {
    $apiurl = uc_api_url('pm_client', 'ls', "uid=$uid&frontend=1", ($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");
}
/**
 * 检查用户是否有新私信
 *
 * @param int $uid 用户ID
 * @param int $more 是否返回更详细的信息,1为是,其他为否
 * @return mixed 返回新私信信息,格式取决于UC连接方式和$more参数
 */
function uc_pm_checknew($uid, $more = 0) {
    $return = call_user_func(UC_API_FUNC, 'pm', 'check_newpm', array('uid'=>$uid, 'more'=>$more));
    return (!$more || UC_CONNECT == 'mysql') ? $return : uc_unserialize($return);
}

/**
 * 发送私信
 *
 * @param int $fromuid 发送者ID
 * @param string|int $msgto 接收者ID或用户名
 * @param string $subject 私信主题
 * @param string $message 私信内容
 * @param int $instantly 是否立即发送,1为立即发送,其他为不立即发送
 * @param int $replypmid 回复的私信ID,0为新私信
 * @param int $isusername 是否使用用户名发送,1为是,其他为否
 * @param int $type 私信类型,0为普通私信,1为系统私信
 * @return mixed 发送结果,具体格式取决于发送方式
 */
function uc_pm_send($fromuid, $msgto, $subject, $message, $instantly = 1, $replypmid = 0, $isusername = 0, $type = 0) {
    if($instantly) {
        $replypmid = @is_numeric($replypmid) ? $replypmid : 0;
        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 {
        // 通过API URL方式发送
        $fromuid = intval($fromuid);
        $subject = rawurlencode($subject);
        $msgto = rawurlencode($msgto);
        $message = rawurlencode($message);
        $replypmid = @is_numeric($replypmid) ? $replypmid : 0;
        $replyadd = $replypmid ? "&pmid=$replypmid&do=reply" : '';
        $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);
    }
}

/**
 * 删除私信
 *
 * @param int $uid 用户ID
 * @param string $folder 私信文件夹,如inbox或outbox
 * @param array $pmids 要删除的私信ID数组
 * @return mixed 删除结果
 */
function uc_pm_delete($uid, $folder, $pmids) {
    return call_user_func(UC_API_FUNC, 'pm', 'delete', array('uid'=>$uid, 'pmids'=>$pmids));
}

/**
 * 删除用户私信
 *
 * @param int $uid 用户ID
 * @param array $touids 要删除私信的接收者ID数组
 * @return mixed 删除结果
 */
function uc_pm_deleteuser($uid, $touids) {
    return call_user_func(UC_API_FUNC, 'pm', 'deleteuser', array('uid'=>$uid, 'touids'=>$touids));
}

/**
 * 删除聊天记录
 *
 * @param int $uid 用户ID
 * @param array $plids 要删除的聊天记录ID数组
 * @param int $type 私信类型,0为普通私信,1为系统私信
 * @return mixed 删除结果
 */
function uc_pm_deletechat($uid, $plids, $type = 0) {
    return call_user_func(UC_API_FUNC, 'pm', 'deletechat', array('uid'=>$uid, 'plids'=>$plids, 'type'=>$type));
}

/**
 * 设置私信阅读状态
 *
 * @param int $uid 用户ID
 * @param array $uids 接收者ID数组
 * @param array $plids 私信ID数组
 * @param int $status 阅读状态,0为未读,1为已读
 * @return mixed 设置结果
 */
function uc_pm_readstatus($uid, $uids, $plids = array(), $status = 0) {
    return call_user_func(UC_API_FUNC, 'pm', 'readstatus', array('uid'=>$uid, 'uids'=>$uids, 'plids'=>$plids, 'status'=>$status));
}

/**
 * 获取私信列表
 *
 * @param int $uid 用户ID
 * @param int $page 页码
 * @param int $pagesize 每页数量
 * @param string $folder 文件夹名称,如inbox或outbox
 * @param string $filter 过滤条件,如newpm
 * @param int $msglen 截取私信内容长度,0为不截取
 * @return mixed 私信列表
 */
function uc_pm_list($uid, $page = 1, $pagesize = 10, $folder = 'inbox', $filter = 'newpm', $msglen = 0) {
    $uid = intval($uid);
    $page = intval($page);
    $pagesize = intval($pagesize);
    $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);
}

/**
 * 忽略某人发来的私信
 *
 * @param int $uid 用户ID
 * @return mixed 操作结果
 */
function uc_pm_ignore($uid) {
    $uid = intval($uid);
    return call_user_func(UC_API_FUNC, 'pm', 'ignore', array('uid'=>$uid));
}

/**
 * 查看私信
 *
 * @param int $uid 用户ID
 * @param int $pmid 私信ID,0为获取最新私信
 * @param int $touid 对方用户ID
 * @param int $daterange 查看范围,1为今天,2为三天内,3为一周内,0为不限制
 * @param int $page 页码
 * @param int $pagesize 每页数量
 * @param int $type 私信类型,0为普通私信,1为系统私信
 * @param int $isplid 是否为对话模式,1为是
 * @return mixed 私信内容
 */
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;
    $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);
}

/**
 * 获取某用户对另一用户的私信查看次数
 *
 * @param int $uid 用户ID
 * @param int $touid 对方用户ID
 * @param int $isplid 是否为对话模式,1为是
 * @return mixed 查看次数
 */
function uc_pm_view_num($uid, $touid, $isplid) {
    $uid = intval($uid);
    $touid = intval($touid);
    $isplid = intval($isplid);
    return call_user_func(UC_API_FUNC, 'pm', 'viewnum', array('uid' => $uid, 'touid' => $touid, 'isplid' => $isplid));
}

/**
 * 查看私信节点
 *
 * @param int $uid 用户ID
 * @param int $type 私信类型,0为普通私信,1为系统私信
 * @param int $pmid 私信ID
 * @return mixed 查看结果
 */
function uc_pm_viewnode($uid, $type, $pmid) {
    $uid = intval($uid);
    $type = intval($type);
    $pmid = @is_numeric($pmid) ? $pmid : 0;
    $return = call_user_func(UC_API_FUNC, 'pm', 'viewnode', array('uid'=>$uid, 'type'=>$type, 'pmid'=>$pmid));
    return UC_CONNECT == 'mysql' ? $return : uc_unserialize($return);
}

/**
 * 获取聊天私信成员列表
 *
 * @param int $uid 用户ID
 * @param int $plid 聊天私信ID
 * @return mixed 成员列表
 */
function uc_pm_chatpmmemberlist($uid, $plid = 0) {
    $uid = intval($uid);
    $plid = intval($plid);
    $return = call_user_func(UC_API_FUNC, 'pm', 'chatpmmemberlist', array('uid'=>$uid, 'plid'=>$plid));
    return UC_CONNECT == 'mysql' ? $return : uc_unserialize($return);
}
/**
 * 将用户从聊天中踢出
 * @param $plid 聊天室或对话的ID
 * @param $uid 当前操作用户的ID
 * @param $touid 被踢出用户的ID
 * @return 调用UC API后的返回结果
 */
function uc_pm_kickchatpm($plid, $uid, $touid) {
	$uid = intval($uid);
	$plid = intval($plid);
	$touid = intval($touid);
	return call_user_func(UC_API_FUNC, 'pm', 'kickchatpm', array('uid'=>$uid, 'plid'=>$plid, 'touid'=>$touid));
}

/**
 * 添加聊天信息
 * @param $plid 聊天室或对话的ID
 * @param $uid 当前操作用户的ID
 * @param $touid 发送消息给的目标用户ID
 * @return 调用UC API后的返回结果
 */
function uc_pm_appendchatpm($plid, $uid, $touid) {
	$uid = intval($uid);
	$plid = intval($plid);
	$touid = intval($touid);
	return call_user_func(UC_API_FUNC, 'pm', 'appendchatpm', array('uid'=>$uid, 'plid'=>$plid, 'touid'=>$touid));
}

/**
 * 获取用户的黑名单列表
 * @param $uid 当前操作用户的ID
 * @return 调用UC API后的返回结果
 */
function uc_pm_blackls_get($uid) {
	$uid = intval($uid);
	return call_user_func(UC_API_FUNC, 'pm', 'blackls_get', array('uid'=>$uid));
}

/**
 * 设置用户的黑名单列表
 * @param $uid 当前操作用户的ID
 * @param $blackls 黑名单用户数组
 * @return 调用UC API后的返回结果
 */
function uc_pm_blackls_set($uid, $blackls) {
	$uid = intval($uid);
	return call_user_func(UC_API_FUNC, 'pm', 'blackls_set', array('uid'=>$uid, 'blackls'=>$blackls));
}

/**
 * 添加用户到黑名单
 * @param $uid 当前操作用户的ID
 * @param $username 要添加到黑名单的用户名
 * @return 调用UC API后的返回结果
 */
function uc_pm_blackls_add($uid, $username) {
	$uid = intval($uid);
	return call_user_func(UC_API_FUNC, 'pm', 'blackls_add', array('uid'=>$uid, 'username'=>$username));
}

/**
 * 从黑名单中删除用户
 * @param $uid 当前操作用户的ID
 * @param $username 要从黑名单中删除的用户名
 * @return 调用UC API后的返回结果
 */
function uc_pm_blackls_delete($uid, $username) {
	$uid = intval($uid);
	return call_user_func(UC_API_FUNC, 'pm', 'blackls_delete', array('uid'=>$uid, 'username'=>$username));
}

/**
 * 获取域名列表
 * @return 调用UC API后的返回结果
 */
function uc_domain_ls() {
	$return = call_user_func(UC_API_FUNC, 'domain', 'ls', array('1'=>1));
	return UC_CONNECT == 'mysql' ? $return : uc_unserialize($return);
}
/**
 * 信用积分兑换请求
 *
 * @param int $uid 用户ID
 * @param int $from 起始积分类型
 * @param int $to 结束积分类型
 * @param int $toappid 目标应用ID
 * @param int $amount 兑换数量
 * @return mixed 兑换结果,通常是API返回的数据
 */
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);
    return uc_api_post('credit', 'request', array('uid'=>$uid, 'from'=>$from, 'to'=>$to, 'toappid'=>$toappid, 'amount'=>$amount));
}

/**
 * 获取指定标签信息
 *
 * @param string $tagname 标签名
 * @param int $nums 需要返回的标签数量,默认为0,表示全部
 * @return mixed 返回标签信息,格式取决于UC连接方式
 */
function uc_tag_get($tagname, $nums = 0) {
    $return = call_user_func(UC_API_FUNC, 'tag', 'gettag', array('tagname'=>$tagname, 'nums'=>$nums));
    return UC_CONNECT == 'mysql' ? $return : uc_unserialize($return);
}

/**
 * 获取用户头像
 *
 * @param int $uid 用户ID
 * @param string $type 头像类型,默认为'virtual'
 * @param int $returnhtml 是否返回HTML代码,默认为1(返回HTML代码)
 * @return mixed 根据$returnhtml参数返回HTML代码或头像信息数组
 */
function uc_avatar($uid, $type = 'virtual', $returnhtml = 1) {
    $uid = intval($uid);
    $uc_input = uc_api_input("uid=$uid&frontend=1", "user", "rectavatar");
    $avatarpath = UC_STANDALONE ? UC_AVTAPI : UC_API;
    $uc_avatarflash = UC_API.'/images/camera.swf?inajax=1&appid='.UC_APPID.'&input='.$uc_input.'&agent='.md5($_SERVER['HTTP_USER_AGENT']).'&ucapi='.urlencode(UC_API).'&avatartype='.$type.'&uploadSize=2048';
    $uc_avatarhtml5 = UC_API.'/index.php?m=user&a=camera&width=450&height=253&appid='.UC_APPID.'&input='.$uc_input.'&agent='.md5($_SERVER['HTTP_USER_AGENT']).'&ucapi='.urlencode(UC_API).'&avatartype='.$type.'&uploadSize=2048';
    $uc_avatarstl = $avatarpath.'/index.php?m=user&inajax=1&a=rectavatar&appid='.UC_APPID.'&input='.$uc_input.'&agent='.md5($_SERVER['HTTP_USER_AGENT']).'&avatartype='.$type.'&base64=yes';
    if($returnhtml) {
        $flash = '<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>';
        $html5 = '<iframe src="' . $uc_avatarhtml5 . '" width="450" marginwidth="0" height="253" marginheight="0" scrolling="no" frameborder="0" id="mycamera" name="mycamera" align="middle"></iframe>';
        return '<script type="text/javascript">document.write(document.createElement("Canvas").getContext ? \'' . $html5 . '\' : \'' . $flash . '\');</script>';
    } else {
        return array(
            'width', '450',
            'height', '253',
            'scale', 'exactfit',
            'src', $uc_avatarflash,
            'html5_src', $uc_avatarhtml5,
            'stl_src', $uc_avatarstl,
            'id', 'mycamera',
            'name', 'mycamera',
            'quality','high',
            'bgcolor','#ffffff',
            'menu', 'false',
            'swLiveConnect', 'true',
            'allowScriptAccess', 'always'
        );
    }
}

/**
 * 处理用户头像切边
 *
 * @param int $uid 用户ID
 * @return mixed 处理结果,通常是API返回的数据
 */
function uc_rectavatar($uid) {
    return uc_api_mysql('user', 'rectavatar', array('uid' => $uid));
}

/**
 * 邮件队列添加
 *
 * @param array $uids 用户ID数组
 * @param array $emails 邮箱地址数组
 * @param string $subject 邮件主题
 * @param string $message 邮件正文
 * @param string $frommail 发件邮箱,默认为空
 * @param string $charset 编码,默认为'gbk'
 * @param bool $htmlon 是否为HTML邮件,默认为FALSE
 * @param int $level 邮件级别,默认为1
 * @return mixed 添加结果,通常是API返回的数据
 */
function uc_mail_queue($uids, $emails, $subject, $message, $frommail = '', $charset = 'gbk', $htmlon = FALSE, $level = 1) {
    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));
}

/**
 * 检查用户头像是否存在
 *
 * @param int $uid 用户ID
 * @param string $size 头像尺寸,默认为'middle'
 * @param string $type 头像类型,默认为'virtual'
 * @return int 检查结果,1表示头像存在,0表示不存在
 */
function uc_check_avatar($uid, $size = 'middle', $type = 'virtual') {
    if(UC_STANDALONE && @include UC_ROOT.'./extend_client.php') {
        $uc_chk = new uc_note_handler();
        $res = $uc_chk->checkavatar(array('uid' => $uid, 'size' => $size, 'type' => $type), array());
    } else {
        $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;
    }
}

/**
 * 检查UCenter版本信息
 *
 * @return mixed 版本检查结果,通常是API返回的数据
 */
function uc_check_version() {
    $return = uc_api_post('version', 'check', array());
    $data = uc_unserialize($return);
    return is_array($data) ? $data : $return;
}

?>

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|新秀网络验证系统API ( 豫ICP备2021033257号-1 )

GMT+8, 2024-4-29 11:12 , Processed in 0.220220 second(s), 63 queries , Redis On.

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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