$text, 'desp' => $desp ); $opts = array( 'http' => array( 'method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded', 'content' => http_build_query($postdata) ), // 解决SSL证书验证失败的问题 'ssl' => array( 'verify_peer' => false, 'verify_peer_name' => false, ) ); $context = stream_context_create($opts); $result = file_get_contents('http://iyuu.cn/'.$token.'.send', false, $context); return $result; } /** * 获取全局唯一的UUID * @param int $pid * @return string */ function getUUID(int $pid = 0):string { if (function_exists('posix_getpid')) { $pid = posix_getpid(); } return sprintf('pid%d_%s', $pid, uniqid()); } /** * 粗略验证字符串是否为IYUU的token * @param string $token * @return bool */ function check_token($token = ''):bool { return (strlen($token) < 60) && (strpos($token, 'IYUU') === 0) && (strpos($token, 'T') < 15); } /** * 异步执行命令 * @descr 原理为php的程序执行函数后台执行 * @param string $cmd */ function run_exec($cmd = '') { if(DIRECTORY_SEPARATOR === '\\') { pclose(popen('start /B '.$cmd, 'r')); } else { pclose(popen($cmd, 'r')); } } /** * 转换成易读的容量格式(包含小数) * @param int|float $bytes 字节 * @param string $delimiter 分隔符 [  |
] * @param int $decimals 保留小数点 * @return string */ function dataSize($bytes, string $delimiter = '', int $decimals = 2):string { $type = array('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'); $i = 0; while($bytes >= 1024) { $bytes /= 1024; $i++; } return number_format($bytes, $decimals) . $delimiter . $type[$i]; } /** * 大写 PP 调试函数(CLI使用) * @param mixed $data * @param bool $echo * @return string */ function PP($data, bool $echo = false) { $hr = PHP_EOL.'******************************'.\date('Y-m-d H:i:s').PHP_EOL; $str = $hr; switch (true) { case is_bool($data): $show_data = $data ? 'true' : 'false'; break; case is_null($data): $show_data = 'null'; break; default: $show_data = print_r($data, true); break; } $str .= $show_data; $str .= $hr; if ($echo) { echo $str; return ''; } return $str; }