2052 lines
56 KiB
PHP
2052 lines
56 KiB
PHP
<?php
|
||
|
||
use yii\helpers\VarDumper;
|
||
use yii\web\UploadedFile;
|
||
use \PhpOffice\PhpSpreadsheet\IOFactory;
|
||
use \PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||
//打印封装
|
||
function dd($data, $exit = 0)
|
||
{
|
||
VarDumper::dump($data, 10, true);
|
||
if ($exit) {
|
||
exit;
|
||
}
|
||
}
|
||
//打印数据
|
||
function ddSql($sql){
|
||
$newSql=$sql->createCommand()->getRawSql();
|
||
return $newSql;
|
||
}
|
||
//微擎用户密码加密方式 获取用户密码加密后的密码
|
||
function getPassword($password){
|
||
$salt=Yii::$app->params['salt'];
|
||
$authkeys=Yii::$app->params['authkey'];
|
||
$new_password = sha1("{$password}-{$salt}-{$authkeys}");
|
||
return $new_password;
|
||
}
|
||
//查询条件筛选
|
||
function filter_array($array){
|
||
if(!is_array($array)){
|
||
throw new Exception('must a array','110');
|
||
}
|
||
foreach ($array as $k=>$v){
|
||
if(!$v||$v=='null'){
|
||
unset($array[$k]);
|
||
}
|
||
}
|
||
return $array;
|
||
}
|
||
/*****************************************************
|
||
* 拼装的curl万能函数
|
||
*****************************************************/
|
||
//参数1:访问的URL,参数2:post数据(不填则为GET),参数3:提交的$cookies,参数4:是否返回$cookies
|
||
function curl_request($url,$post_data=null){
|
||
$ch = curl_init();
|
||
|
||
curl_setopt($ch, CURLOPT_URL, $url);
|
||
// 执行后不直接打印出来
|
||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||
// 设置请求方式为post
|
||
curl_setopt($ch, CURLOPT_POST, true);
|
||
// post的变量
|
||
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
|
||
|
||
// 跳过证书检查
|
||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||
// 不从证书中检查SSL加密算法是否存在
|
||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
||
|
||
$output = curl_exec($ch);
|
||
curl_close($ch);
|
||
|
||
return $output;
|
||
}
|
||
|
||
function randomAESKey($length, $chars = '0123456789') {
|
||
$hash = '';
|
||
$max = strlen($chars) - 1;
|
||
for ($i = 0; $i < $length; $i++) {
|
||
$hash .= $chars[mt_rand(0, $max)];
|
||
}
|
||
return $hash;
|
||
}
|
||
/*****************************************************
|
||
* 生成随机字符串 - 最长为32位字符串
|
||
*****************************************************/
|
||
function wxNonceStr($length = 16, $type = FALSE,$chars="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789") {
|
||
$str = "";
|
||
for ($i = 0; $i < $length; $i++) {
|
||
$str .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);
|
||
}
|
||
if($type == TRUE){
|
||
return strtoupper(md5(time() . $str));
|
||
}
|
||
else {
|
||
return $str;
|
||
}
|
||
}
|
||
/**
|
||
* 将xml转为array
|
||
* @param string $xml
|
||
* @throws WxPayException
|
||
*/
|
||
function FromXml($xml){
|
||
// if(!$xml){
|
||
// throw new Exception("xml数据异常!");
|
||
// }
|
||
//将XML转为array
|
||
//禁止引用外部xml实体
|
||
libxml_disable_entity_loader(true);
|
||
$arr = json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true);
|
||
return $arr;
|
||
}
|
||
//遍历文件夹的文件
|
||
/**
|
||
* PHP高效遍历文件夹(大量文件不会卡死)
|
||
* @param string $path 目录路径
|
||
* @param integer $level 目录深度
|
||
*/
|
||
function list_file($dir) {
|
||
$files = [];
|
||
if(@$handle = opendir($dir)) {
|
||
while(($file = readdir($handle)) !== false) {
|
||
if($file != ".." && $file != ".") {
|
||
if(is_dir($dir . "/" . $file)) { //如果是子文件夹,进行递归
|
||
$files[$file] = list_file($dir . "/" . $file);
|
||
} else {
|
||
$files[] = $file;
|
||
}
|
||
}
|
||
}
|
||
closedir($handle);
|
||
}
|
||
return $files;
|
||
}
|
||
|
||
//对象转数组
|
||
function object_array($array) {
|
||
if(is_object($array)) {
|
||
$array = (array)$array;
|
||
}
|
||
if(is_array($array)) {
|
||
foreach($array as $key=>$value) {
|
||
$array[$key] = object_array($value);
|
||
}
|
||
}
|
||
return $array;
|
||
}
|
||
|
||
//短信验证码生成规则
|
||
function generate_code($length = 6) {
|
||
$min = pow(10 , ($length - 1));
|
||
$max = pow(10, $length) - 1;
|
||
return rand($min, $max);
|
||
}
|
||
//curl远程下载压缩包
|
||
function getFile($url, $save_dir = '', $filename = '', $type = 0) {
|
||
if (trim($url) == '') {
|
||
return false;
|
||
}
|
||
if (trim($save_dir) == '') {
|
||
$save_dir = './';
|
||
}
|
||
if (0 !== strrpos($save_dir, '/')) {
|
||
$save_dir.= '/';
|
||
}
|
||
//创建保存目录
|
||
if (!file_exists($save_dir) && !mkdir($save_dir, 0777, true)) {
|
||
return false;
|
||
}
|
||
//获取远程文件所采用的方法
|
||
$ch = curl_init();
|
||
curl_setopt ($ch, CURLOPT_URL, $url);
|
||
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
|
||
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT,10);
|
||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||
$content = curl_exec($ch);
|
||
if(curl_error($ch)){
|
||
echo json_encode(['code'=>2,'msg'=>curl_error($ch)]);die;
|
||
}
|
||
//文件大小
|
||
$fp2 = @fopen($save_dir . $filename, 'a');
|
||
fwrite($fp2, $content);
|
||
fclose($fp2);
|
||
unset($content, $url);
|
||
return array(
|
||
'file_name' => $filename,
|
||
'save_path' => $save_dir . $filename
|
||
);
|
||
}
|
||
// 生成纯字母字符串函数
|
||
function rand_string($length) {
|
||
$randstr = "";
|
||
for ($i = 0; $i < (int) $length; $i ++) {
|
||
$randnum = mt_rand(0, 51);
|
||
if ($randnum < 26) {
|
||
$randstr .= chr($randnum + 65); // A-Z之间字符
|
||
} else {
|
||
$randstr .= chr($randnum + 71); // a-z之间字符
|
||
}
|
||
}
|
||
|
||
return $randstr;
|
||
}
|
||
//获取访客ip
|
||
function getIps(){
|
||
if (isset($_SERVER)) {
|
||
if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
|
||
$arr = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
|
||
foreach ($arr as $ip) {
|
||
$ip = trim($ip);
|
||
|
||
if ($ip != 'unknown') {
|
||
$realip = $ip;
|
||
break;
|
||
}
|
||
}
|
||
} else if (isset($_SERVER['HTTP_CLIENT_IP'])) {
|
||
$realip = $_SERVER['HTTP_CLIENT_IP'];
|
||
} else if (isset($_SERVER['REMOTE_ADDR'])) {
|
||
$realip = $_SERVER['REMOTE_ADDR'];
|
||
} else {
|
||
$realip = '0.0.0.0';
|
||
}
|
||
} else if (getenv('HTTP_X_FORWARDED_FOR')) {
|
||
$realip = getenv('HTTP_X_FORWARDED_FOR');
|
||
} else if (getenv('HTTP_CLIENT_IP')) {
|
||
$realip = getenv('HTTP_CLIENT_IP');
|
||
} else {
|
||
$realip = getenv('REMOTE_ADDR');
|
||
}
|
||
preg_match('/[\\d\\.]{7,15}/', $realip, $onlineip);
|
||
$realip = (!empty($onlineip[0]) ? $onlineip[0] : '0.0.0.0');
|
||
return $realip;
|
||
}
|
||
function randoms($length){
|
||
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
||
$randomString = '';
|
||
for ($i = 0; $i < $length; $i++) {
|
||
$randomString .= $characters[rand(0, strlen($characters) - 1)];
|
||
}
|
||
return $randomString;
|
||
}
|
||
|
||
function axios_request(){
|
||
if(Yii::$app->request->isPost){
|
||
$postData = file_get_contents('php://input');
|
||
$requests = !empty($postData) ? json_decode($postData, true) : array();
|
||
$requests=$requests?$requests:$_POST;
|
||
return $requests;
|
||
}else{
|
||
|
||
return Yii::$app->request->get();
|
||
}
|
||
}
|
||
|
||
//设置session
|
||
function setSession($key,$value){
|
||
Yii::$app->session->set($key,$value);
|
||
}
|
||
|
||
//获取session
|
||
function getSession($key){
|
||
$data=Yii::$app->session->get($key);
|
||
return $data;
|
||
}
|
||
//$pathname保存的路径 $filename提交的图片文件参数名
|
||
function uploadImage($filename,$pathname=null){
|
||
$pathname=$pathname?:date('Y') . "/" . date('m') . "/" . date('d');
|
||
$returnPath = '';
|
||
$path = 'web/static/'.$pathname;
|
||
if (!file_exists($path)) {
|
||
mkdir($path, 0777,true);
|
||
chmod($path, 0777);
|
||
|
||
}
|
||
$name=date("YmdHis") .rand(1111,9999). '.png';
|
||
//$patch = '../'.$path . '/' . $name;
|
||
$patch = $path . '/' . $name;
|
||
$tmp = UploadedFile::getInstanceByName($filename);
|
||
|
||
if ($tmp) {
|
||
|
||
$tmp->saveAs($patch);
|
||
$returnPath .= $path . '/' . $name;
|
||
}
|
||
|
||
return Yii::$app->request->hostInfo.'/'.$returnPath;
|
||
}
|
||
|
||
function recurDir($pathName)
|
||
{
|
||
//将结果保存在result变量中
|
||
$result = array();
|
||
$temp = array();
|
||
//判断传入的变量是否是目录
|
||
if(!is_dir($pathName) || !is_readable($pathName)) {
|
||
return null;
|
||
}
|
||
//取出目录中的文件和子目录名,使用scandir函数
|
||
$allFiles = scandir($pathName);
|
||
//遍历他们
|
||
foreach($allFiles as $fileName) {
|
||
//判断是否是.和..因为这两个东西神马也不是。。。
|
||
if(in_array($fileName, array('.', '..'))) {
|
||
continue;
|
||
}
|
||
//路径加文件名
|
||
$fullName = $pathName.'/'.$fileName;
|
||
//如果是目录的话就继续遍历这个目录
|
||
if(is_dir($fullName)) {
|
||
//将这个目录中的文件信息存入到数组中
|
||
$result[$fullName] = recurDir($fullName);
|
||
}else {
|
||
//如果是文件就先存入临时变量
|
||
$temp[] = $fullName;
|
||
}
|
||
}
|
||
//取出文件
|
||
if($temp) {
|
||
foreach($temp as $f) {
|
||
$result[] = $f;
|
||
}
|
||
}
|
||
return $result;
|
||
}
|
||
function checkPassWord($salt,$authkeys,$password){
|
||
$new_password = sha1("{$password}-{$salt}-{$authkeys}");
|
||
return $new_password;
|
||
}
|
||
function httpRequest($url, $data = null,$header=null) {
|
||
//echo 111;die;
|
||
$curl = curl_init();
|
||
curl_setopt($curl, CURLOPT_URL, $url);
|
||
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
|
||
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
|
||
|
||
if (!empty($data)) {
|
||
curl_setopt($curl, CURLOPT_POST, 1);
|
||
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
|
||
}
|
||
if($header) {
|
||
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
|
||
}
|
||
curl_setopt($curl, CURLOPT_HEADER, 0);//返回response头部信息
|
||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
||
//执行
|
||
$output = curl_exec($curl);
|
||
|
||
curl_close($curl);
|
||
return $output;
|
||
}
|
||
|
||
function get_server_ip(){
|
||
if(isset($_SERVER)){
|
||
if($_SERVER['SERVER_ADDR']){
|
||
$server_ip=$_SERVER['SERVER_ADDR'];
|
||
}else{
|
||
$server_ip=$_SERVER['LOCAL_ADDR'];
|
||
}
|
||
}else{
|
||
$server_ip = getenv('SERVER_ADDR');
|
||
}
|
||
return $server_ip;
|
||
}
|
||
|
||
function getVersion(){
|
||
$url=Yii::$app->params['domain_url'].'/admin/install/getdomainlist';
|
||
$data['domian_url']=Yii::$app->request->hostInfo;
|
||
$result=httpRequest($url,$data);
|
||
return json_decode($result,true);
|
||
}
|
||
function getFileArr($dir){
|
||
$file_data=list_file($dir);
|
||
$file_arr=[];
|
||
foreach ($file_data as $k=>$v){
|
||
if(is_array($v)){
|
||
foreach ($v as $ko=>$vo){
|
||
if(is_array($vo)){
|
||
foreach ($vo as $va){
|
||
$file_arr[]=$dir.'/'.$k.'/'.$ko.'/'.$va;
|
||
}
|
||
}else{
|
||
$file_arr[]=$dir.'/'.$k.'/'.$vo;
|
||
}
|
||
|
||
}
|
||
|
||
}
|
||
}
|
||
return $file_arr;
|
||
}
|
||
|
||
function getZipArr($filePath){
|
||
$zip = zip_open($filePath);
|
||
$zip_arr=[];
|
||
if ($zip){
|
||
while($zip_entry = zip_read($zip)){
|
||
$name = zip_entry_name($zip_entry);
|
||
$zip_arr[]=$name;
|
||
}
|
||
}
|
||
$new_zip=[];
|
||
foreach ($zip_arr as $v){
|
||
if(strpos($v,'.php') !==false){
|
||
$new_zip[]=$v;
|
||
}
|
||
}
|
||
return $new_zip;
|
||
}
|
||
|
||
|
||
function ybwmEncrypt($data, $key)
|
||
{
|
||
$key = md5($key);
|
||
$x = 0;
|
||
$len = strlen($data);
|
||
$l = strlen($key);
|
||
$char='';
|
||
for ($i = 0; $i < $len; $i++)
|
||
{
|
||
if ($x == $l)
|
||
{
|
||
$x = 0;
|
||
}
|
||
$char .= $key{$x};
|
||
$x++;
|
||
}
|
||
$str='';
|
||
for ($i = 0; $i < $len; $i++)
|
||
{
|
||
$str .= chr(ord($data[$i]) + (ord($char[$i])) % 256);
|
||
}
|
||
return base64_encode($str);
|
||
}
|
||
function ybwmDecrypt($data, $key)
|
||
{
|
||
$key = md5($key);
|
||
$x = 0;
|
||
$data = base64_decode($data);
|
||
$len = strlen($data);
|
||
$l = strlen($key);
|
||
$char='';
|
||
for ($i = 0; $i < $len; $i++)
|
||
{
|
||
if ($x == $l)
|
||
{
|
||
$x = 0;
|
||
}
|
||
$char .= substr($key, $x, 1);
|
||
$x++;
|
||
}
|
||
$str='';
|
||
for ($i = 0; $i < $len; $i++)
|
||
{
|
||
if (ord(substr($data, $i, 1)) < ord(substr($char, $i, 1)))
|
||
{
|
||
$str .= chr((ord(substr($data, $i, 1)) + 256) - ord(substr($char, $i, 1)));
|
||
}
|
||
else
|
||
{
|
||
$str .= chr(ord(substr($data, $i, 1)) - ord(substr($char, $i, 1)));
|
||
}
|
||
}
|
||
return $str;
|
||
}
|
||
|
||
|
||
function scanRoot($dir=''){
|
||
//忽略升级的文件夹
|
||
$ignore = [
|
||
'.',
|
||
'..',
|
||
'.git',
|
||
'.lock',
|
||
'icon.jpg',
|
||
'preview.jpg',
|
||
'merchantApi',
|
||
'layouts',
|
||
'.install',
|
||
'.gitignore',
|
||
'.idea',
|
||
'.user.ini',
|
||
'assets',
|
||
'delivery',
|
||
'extend',
|
||
'helpers',
|
||
'jobs',
|
||
'mail',
|
||
'path',
|
||
'payment',
|
||
'runtime',
|
||
'template',
|
||
'tests',
|
||
'vagrant',
|
||
'vendor',
|
||
'web',
|
||
'widgets',
|
||
'yii',
|
||
'yii.bat',
|
||
'README.md',
|
||
'LICENSE.md',
|
||
'composer.phar',
|
||
'composer.json',
|
||
'composer.lock',
|
||
'install.lock',
|
||
'version.json',
|
||
'Vagrantfile',
|
||
'wxapp.php',
|
||
'insert.php',
|
||
'update.php',
|
||
'site.php',
|
||
'say.html',
|
||
'runtimedemo.txt',
|
||
'requirements.php',
|
||
'openVoice.sh',
|
||
'module.php',
|
||
'manifest.xml',
|
||
'codeception.yml',
|
||
'.htaccess',
|
||
'developer.cer',
|
||
'docker-compose.yml',
|
||
'wechat.log',
|
||
'.htaccess',
|
||
'jpush.log',
|
||
'test.sh',
|
||
'db.php',
|
||
'.well-known'
|
||
];
|
||
$output = [];
|
||
$list = scandir(Yii::$app->basePath.'/'.$dir);
|
||
foreach ($list as $item) {
|
||
if (in_array($item, $ignore)) {
|
||
continue;
|
||
}
|
||
$_temPath = Yii::$app->basePath.'/'.$dir . $item;
|
||
//dd(is_dir($_temPath));die;
|
||
if (is_dir($_temPath)) {
|
||
//dd($_temPath);
|
||
$_temOutput = scanRoot($dir . $item . '/');
|
||
$output = array_merge($output, $_temOutput);
|
||
continue;
|
||
|
||
}
|
||
$temMd5 = md5(file_get_contents($_temPath));
|
||
|
||
$output[$dir . $item] = $temMd5;
|
||
}
|
||
return $output;
|
||
}
|
||
|
||
function zipFile($fileList,$filename){
|
||
|
||
$zip = new ZipArchive();
|
||
|
||
$bool=$zip->open($filename,ZipArchive::CREATE); //打开压缩包
|
||
//var_dump($bool);
|
||
foreach($fileList as $file){
|
||
$bool=$zip->addFile($file,basename($file)); //向压缩包中添加文件
|
||
// var_dump($bool);
|
||
}
|
||
|
||
$zip->close(); //关闭压缩包
|
||
}
|
||
|
||
function channelScanRoot($dir=''){
|
||
//忽略升级的文件夹
|
||
$ignore = [
|
||
'.',
|
||
'..',
|
||
'.git',
|
||
'.lock',
|
||
'icon.jpg',
|
||
'preview.jpg',
|
||
'merchant',
|
||
'merchantApi',
|
||
'layouts',
|
||
'.install',
|
||
'.gitignore',
|
||
'.idea',
|
||
'.user.ini',
|
||
'admin',
|
||
'assets',
|
||
'commands',
|
||
'config',
|
||
'delivery',
|
||
'extend',
|
||
'helpers',
|
||
'jobs',
|
||
'mail',
|
||
'path',
|
||
'payment',
|
||
'runtime',
|
||
'template',
|
||
'tests',
|
||
'vagrant',
|
||
'vendor',
|
||
'web',
|
||
'widgets',
|
||
'yii',
|
||
'yii.bat',
|
||
'README.md',
|
||
'LICENSE.md',
|
||
'composer.phar',
|
||
'composer.json',
|
||
'composer.lock',
|
||
'install.lock',
|
||
'version.json',
|
||
'Vagrantfile',
|
||
'wxapp.php',
|
||
'insert.php',
|
||
'update.php',
|
||
'site.php',
|
||
'say.html',
|
||
'runtimedemo.txt',
|
||
'requirements.php',
|
||
'openVoice.sh',
|
||
'module.php',
|
||
'manifest.xml',
|
||
'index.php',
|
||
'codeception.yml',
|
||
'.htaccess',
|
||
'developer.cer',
|
||
'docker-compose.yml',
|
||
'wechat.log',
|
||
//'OrderController.php' 这个文件暂时不用加密
|
||
];
|
||
$output = [];
|
||
$list = scandir(Yii::$app->basePath.'/'.$dir);
|
||
//print_R($list);die;
|
||
|
||
foreach ($list as $k=>$item) {
|
||
|
||
if (in_array($item, $ignore)) {
|
||
continue;
|
||
}
|
||
$_temPath = Yii::$app->basePath.'/'.$dir . $item;
|
||
|
||
if (is_dir($_temPath)) {
|
||
$_temOutput = channelScanRoot($dir . $item . '/');
|
||
$output = array_merge($output, $_temOutput);
|
||
continue;
|
||
}
|
||
$temMd5 = md5(file_get_contents($_temPath));
|
||
$output[$dir . $item] = $temMd5;
|
||
|
||
}
|
||
return $output;
|
||
}
|
||
|
||
|
||
function addFileToZip($datalist,$tmpPath,$fileName){
|
||
$fileName = $tmpPath.$fileName;
|
||
if(!file_exists($fileName)){
|
||
//重新生成文件
|
||
$zip = new ZipArchive();//使用本类,linux需开启zlib,windows需取消php_zip.dll前的注释
|
||
if ($zip->open($fileName, ZIPARCHIVE::CREATE)!==TRUE) {
|
||
exit('无法打开文件,或者文件创建失败');
|
||
}
|
||
//$datalist=list_dir($tmpPath);
|
||
//dd($datalist);die;
|
||
foreach($datalist as $val){
|
||
if(file_exists($val)){
|
||
$zip->addFile($val, str_replace($tmpPath, '', $val));
|
||
}
|
||
}
|
||
$zip->close();//关闭
|
||
}
|
||
}
|
||
|
||
//获取文件列表
|
||
function list_dir($dir){
|
||
$result = array();
|
||
if (is_dir($dir)){
|
||
$file_dir = scandir($dir);
|
||
foreach($file_dir as $file){
|
||
if ($file == '.' || $file == '..'){
|
||
continue;
|
||
}
|
||
elseif (is_dir($dir.$file)){
|
||
$result = array_merge($result, list_dir($dir.$file.'/'));
|
||
}
|
||
else{
|
||
array_push($result, $dir.$file);
|
||
}
|
||
}
|
||
}
|
||
return $result;
|
||
}
|
||
function remote_file_exists($url_file){
|
||
//检测输入
|
||
$url_file = trim($url_file);
|
||
if (empty($url_file)) { return false; }
|
||
$url_arr = parse_url($url_file);
|
||
if (!is_array($url_arr) || empty($url_arr)){return false; }
|
||
|
||
//获取请求数据
|
||
$host = $url_arr['host'];
|
||
$path = $url_arr['path'] ."?".$url_arr['query'];
|
||
$port = isset($url_arr['port']) ?$url_arr['port'] : "80";
|
||
|
||
//连接服务器
|
||
$fp = fsockopen($host, $port, $err_no, $err_str,30);
|
||
if (!$fp){ return false; }
|
||
|
||
//构造请求协议
|
||
$request_str = "GET ".$path."HTTP/1.1";
|
||
$request_str .= "Host:".$host."";
|
||
$request_str .= "Connection:Close";
|
||
|
||
//发送请求
|
||
fwrite($fp,$request_str);
|
||
$first_header = fgets($fp, 1024);
|
||
fclose($fp);
|
||
|
||
//判断文件是否存在
|
||
if (trim($first_header) == ""){ return false;}
|
||
if (!preg_match("/200/", $first_header)){
|
||
return false;
|
||
}
|
||
|
||
return true;
|
||
}
|
||
|
||
|
||
function arrayToJson($data) {
|
||
if (isset($data['id'])) {
|
||
unset($data['id']);
|
||
}
|
||
if (isset($data['ident'])) {
|
||
unset($data['ident']);
|
||
}
|
||
if (isset($data['storeId'])) {
|
||
unset($data['storeId']);
|
||
}
|
||
if (isset($data['uniacid'])) {
|
||
unset($data['uniacid']);
|
||
}
|
||
if (isset($data['identName'])) {
|
||
unset($data['identName']);
|
||
}
|
||
$key = array_keys($data);
|
||
$arr = [];
|
||
foreach ($key as $value) {
|
||
$arr[$value] = $data[$value];
|
||
}
|
||
return json_encode($arr);
|
||
}
|
||
|
||
//获取省市区数据1获取省,2获取省市,3获取省市区
|
||
function getCity($type = 1) {
|
||
$cityInfo=(new \yii\db\Query())
|
||
->from('{{%ybwm_core_district}}');
|
||
if ($type == 1) {
|
||
$data = $cityInfo->select(['id as value','name as label'])->where('level=1 AND upid=0')->all();
|
||
}
|
||
if ($type == 2) {
|
||
$data =$cityInfo->select(['id as value','name as label'])->where('level=1 AND upid=0')->all();
|
||
foreach ($data as $key => $value) {
|
||
$data[$key]['children'] = $cityInfo->select(['id as value','name as label'])->where('level=2 AND upid=:upid',[':upid'=>$value['value']])->all();
|
||
}
|
||
}
|
||
if ($type == 3) {
|
||
$data = $cityInfo->select(['id as value','name as label'])->where('level=1 AND upid=0')->all();
|
||
|
||
foreach ($data as $key => $value) {
|
||
$children = $cityInfo->select(['id as value','name as label'])->where('level=2 AND upid=:upid',[':upid'=>$value['value']])->all();
|
||
foreach ($children as $key2 => $value2) {
|
||
$children[$key2]['children'] = $cityInfo->select(['id as value','name as label'])->where('level=3 AND upid=:upid',[':upid'=>$value2['value']])->all();
|
||
}
|
||
$data[$key]['children'] = $children;
|
||
|
||
}
|
||
}
|
||
return $data;
|
||
}
|
||
//距离
|
||
function getDistance($lat1, $lng1, $lat2, $lng2) {
|
||
$EARTH_RADIUS = 6378137; //地球半径
|
||
$RAD = pi() / 180.0;
|
||
|
||
$radLat1 = $lat1 * $RAD;
|
||
$radLat2 = $lat2 * $RAD;
|
||
$a = $radLat1 - $radLat2; // 两点纬度差
|
||
$b = ($lng1 - $lng2) * $RAD; // 两点经度差
|
||
$s = 2 * asin(sqrt(pow(sin($a / 2), 2) + cos($radLat1) * cos($radLat2) * pow(sin($b / 2), 2)));
|
||
$s = $s * $EARTH_RADIUS;
|
||
return round(round($s * 10000) / 10000 / 1000, 2);
|
||
}
|
||
|
||
function array_get($array, $key, $default = null)
|
||
{
|
||
if (is_null($key)) {
|
||
return $array;
|
||
}
|
||
if (isset($array[$key])) {
|
||
return $array[$key];
|
||
}
|
||
foreach (explode('.', $key) as $segment) {
|
||
if (!is_array($array) || !array_key_exists($segment, $array)) {
|
||
return value($default);
|
||
}
|
||
$array = $array[$segment];
|
||
}
|
||
return $array;
|
||
}
|
||
function mFristAndLast($y=0,$m=0){
|
||
$y = $y ? $y : date('Y');
|
||
$m = $m ? $m : date('m');
|
||
$d = date('t', strtotime($y.'-'.$m));
|
||
return array("startTime"=>strtotime($y.'-'.$m),"endTime"=>mktime(23,59,59,$m,$d,$y));
|
||
}
|
||
//腾讯转百度坐标转换
|
||
function coordinateSwitchf($a, $b) {
|
||
$x = (double) $b;
|
||
$y = (double) $a;
|
||
$x_pi = 3.14159265358979324;
|
||
$z = sqrt($x * $x + $y * $y) + 0.00002 * sin($y * $x_pi);
|
||
$theta = atan2($y, $x) + 0.000003 * cos($x * $x_pi);
|
||
$gb = number_format($z * cos($theta) + 0.0065, 6);
|
||
$ga = number_format($z * sin($theta) + 0.006, 6);
|
||
|
||
return ['Latitude' => $ga, 'Longitude' => $gb];
|
||
|
||
}
|
||
/**
|
||
* 获取指定月份数组
|
||
* @param $date
|
||
* @param $rtype 1天数 2具体日期数组
|
||
* @return
|
||
*/
|
||
function get_day( $date ,$rtype = '1'){
|
||
$tem = explode('-' , $date); //切割日期 得到年份和月份
|
||
$year = $tem['0'];
|
||
$month = $tem['1'];
|
||
if( in_array($month , array( '1' , '3' , '5' , '7' , '8' , '01' , '03' , '05' , '07' , '08' , '10' , '12'))) {
|
||
// $text = $year.'年的'.$month.'月有31天';
|
||
$text = '31';
|
||
}
|
||
elseif( $month == 2 )
|
||
{
|
||
if ( $year%400 == 0 || ($year%4 == 0 && $year%100 !== 0) ) //判断是否是闰年
|
||
{
|
||
// $text = $year.'年的'.$month.'月有29天';
|
||
$text = '29';
|
||
}
|
||
else{
|
||
// $text = $year.'年的'.$month.'月有28天';
|
||
$text = '28';
|
||
}
|
||
}
|
||
else{
|
||
// $text = $year.'年的'.$month.'月有30天';
|
||
$text = '30';
|
||
}
|
||
if ($rtype == '2') {
|
||
for ($i = 1; $i <= $text ; $i ++ ) {
|
||
if($i<10){
|
||
$i='0'.$i;
|
||
}
|
||
$r[$year."-".$month."-".$i] =0 ;
|
||
}
|
||
} else {
|
||
$r = $text;
|
||
}
|
||
return $r;
|
||
}
|
||
function dataByTime($data,$endTime=null){
|
||
$arr=[];
|
||
for ($i=14; $i>=0;$i--){
|
||
if($endTime){
|
||
$day=date('Y-m-d',bcsub(strtotime($endTime),bcmul(bcmul(bcmul($i,24),60),60)));
|
||
}else{
|
||
$day=date('Y-m-d', strtotime('-'.$i.' days'));
|
||
}
|
||
if(!is_string($day)){
|
||
$day=strval($day);
|
||
}
|
||
$arr[$day]=0;
|
||
}
|
||
|
||
$newArr=[];
|
||
|
||
foreach ($data as $k=>$v){
|
||
//
|
||
if(substr($v['hours'],0,1)=='0'){
|
||
$v['hours']=substr($v['hours'],1);
|
||
}
|
||
|
||
$newArr[$v['hours']]=$v['money'];
|
||
}
|
||
if($newArr){
|
||
$data_arr=$newArr+$arr;
|
||
}else{
|
||
$data_arr=$arr;
|
||
}
|
||
ksort($data_arr);
|
||
$a=[];
|
||
foreach ($data_arr as $key=>$v){
|
||
$a[]=array(
|
||
'hours'=>$key,
|
||
'money'=>$v
|
||
);
|
||
|
||
}
|
||
//dd($a);die;
|
||
return $a;
|
||
}
|
||
function CreatQuery($type,$re,$time=''){
|
||
$arr=[];
|
||
if($type==1){
|
||
for ($i=1;$i<=24;$i++){
|
||
$arr[$i]=0;
|
||
}
|
||
}elseif($type==2){
|
||
for ($i=14; $i>=0;$i--){
|
||
if($time){
|
||
$day=date('Y-m-d',strtotime($time)-24*$i*60*60);
|
||
}else{
|
||
$day=date('Y-m-d', strtotime('-'.$i.' days'));
|
||
}
|
||
if(!is_string($day)){
|
||
$day=strval($day);
|
||
}
|
||
$arr[$day]=0;
|
||
}
|
||
}elseif($type==3){
|
||
$arr=get_day($time,'2');
|
||
}
|
||
|
||
$newArr=[];
|
||
|
||
foreach ($re as $k=>$v){
|
||
//
|
||
if(substr($v['hours'],0,1)=='0'){
|
||
$v['hours']=substr($v['hours'],1);
|
||
}
|
||
|
||
$newArr[$v['hours']]=$v['money'];
|
||
}
|
||
if($newArr){
|
||
$data_arr=$newArr+$arr;
|
||
}else{
|
||
$data_arr=$arr;
|
||
}
|
||
ksort($data_arr);
|
||
$a=[];
|
||
|
||
foreach ($data_arr as $key=>$v){
|
||
$a[]=array(
|
||
'hours'=>$key,
|
||
'money'=>$v
|
||
);
|
||
|
||
}
|
||
//dd($a);die;
|
||
return $a;
|
||
}
|
||
function getSysInfo(){
|
||
$json=ybwmDecrypt(file_get_contents('./web/secret.json'),Yii::$app->params['channel_model_name']);
|
||
$json='{"time_start":"2020-10-16 00:00:00","time_end":"2099-11-30 00:00:00","time_type":1,"domain_url":"v2.b-ke.cn","domain_name":"\u4e91\u8d1d\u8fde\u9501\u9910\u996eV2\u540e\u53f0\u6f14\u793a","phone":"15307193890","auth_code":"UERRE-MXFHD-RUFZY-NUBGR","status":1,"account_type":1,"account_number":30,"id":90,"service_type":"\u5546\u4e1a\u6388\u6743\u7248","authData":{"channel":["mini","ali","zijie","wechat"],"plug":["miniPlay","rollBag","cashier","payVip","oldWithNew","distribution","queuing","reserve","dividend"],"service":["app","chshier","ps"]},"appName":"\u8fde\u9501\u7248"}';
|
||
$data=json_decode($json,true);
|
||
|
||
|
||
return $data;
|
||
}
|
||
//获取独立版本信息.插件及渠道
|
||
function getSysInformation(){
|
||
$json=ybwmDecrypt(file_get_contents('./web/secret.json'),Yii::$app->params['channel_model_name']);
|
||
$data=json_decode($json,true);
|
||
$newArr=array(
|
||
'appData'=>$data['appData'],
|
||
'authData'=>$data['authData'],
|
||
);
|
||
return $newArr;
|
||
}
|
||
//获取指定版本的插件 渠道
|
||
function getChannelData($modelName){
|
||
$json=ybwmDecrypt(file_get_contents('./web/secret.json'),Yii::$app->params['channel_model_name']);
|
||
$data=json_decode($json,true)['authData'];
|
||
$arr=[];
|
||
|
||
foreach ($data as $k=>$v){
|
||
if($k==$modelName){
|
||
$arr=$v['channel'];
|
||
}
|
||
}
|
||
return $arr;
|
||
}
|
||
function getPlugData($modelName){
|
||
$json=ybwmDecrypt(file_get_contents('./web/secret.json'),Yii::$app->params['channel_model_name']);
|
||
$data=json_decode($json,true)['authData'];
|
||
$arr=[];
|
||
foreach ($data as $k=>$v){
|
||
$key=array_keys($v);
|
||
if($key[0]==$modelName){
|
||
$arr=$v[$key[0]]['plug'];
|
||
}
|
||
}
|
||
return $arr;
|
||
}
|
||
/**
|
||
* 下载程序压缩包文件
|
||
* @param $url 要下载的url
|
||
* @param $save_dir 要存放的目录
|
||
* @return res 成功返回下载信息 失败返回false
|
||
*/
|
||
function down_file($url, $save_dir) {
|
||
if (trim($url) == '') {
|
||
return false;
|
||
}
|
||
if (trim($save_dir) == '') {
|
||
return false;
|
||
}
|
||
if (0 !== strrpos($save_dir, '/')) {
|
||
$save_dir.= '/';
|
||
}
|
||
$filename = basename($url);
|
||
//创建保存目录
|
||
if (!file_exists($save_dir) && !mkdir($save_dir, 0777, true)) {
|
||
return false;
|
||
}
|
||
//开始下载
|
||
$ch = curl_init();
|
||
$timeout = 5;
|
||
curl_setopt($ch, CURLOPT_URL, $url);
|
||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
|
||
$content = curl_exec($ch);
|
||
$status = curl_getinfo($ch);
|
||
curl_close($ch);
|
||
|
||
// 判断执行结果
|
||
if ($status['http_code'] ==200) {
|
||
$size = strlen($content);
|
||
//文件大小
|
||
$fp2 = @fopen($save_dir . $filename , 'a');
|
||
fwrite($fp2, $content);
|
||
fclose($fp2);
|
||
unset($content, $url);
|
||
$res = [
|
||
'status' =>$status['http_code'] ,
|
||
'file_name' => $filename,
|
||
'save_path' => $save_dir . $filename
|
||
];
|
||
} else {
|
||
$res = false;
|
||
}
|
||
|
||
return $res;
|
||
}
|
||
//删除文件夹
|
||
function removeDir($dirName){
|
||
if(! is_dir($dirName))
|
||
{
|
||
return false;
|
||
}
|
||
$handle = @opendir($dirName);
|
||
while(($file = @readdir($handle)) !== false)
|
||
{
|
||
if($file != '.' && $file != '..')
|
||
{
|
||
$dir = $dirName . '/' . $file;
|
||
is_dir($dir) ? removeDir($dir) : @unlink($dir);
|
||
}
|
||
}
|
||
closedir($handle);
|
||
|
||
return rmdir($dirName) ;
|
||
}
|
||
function unzip($src_file, $dest_dir=false, $create_zip_name_dir=true, $overwrite=true){
|
||
if ($zip = zip_open($src_file)){
|
||
if ($zip){
|
||
$splitter = ($create_zip_name_dir === true) ? "." : "/";
|
||
if($dest_dir === false){
|
||
$dest_dir = substr($src_file, 0, strrpos($src_file, $splitter))."/";
|
||
}
|
||
//var_dump($src_file);die;
|
||
// 如果不存在 创建目标解压目录
|
||
create_dirs($dest_dir);
|
||
// 对每个文件进行解压
|
||
while ($zip_entry = zip_read($zip)){
|
||
// 文件不在根目录
|
||
$pos_last_slash = strrpos(zip_entry_name($zip_entry), "/");
|
||
if ($pos_last_slash !== false){
|
||
// 创建目录 在末尾带 /
|
||
create_dirs($dest_dir.'/'.substr(zip_entry_name($zip_entry), 0, $pos_last_slash+1));
|
||
}
|
||
|
||
// 打开包
|
||
if (zip_entry_open($zip,$zip_entry,"r")){
|
||
// 文件名保存在磁盘上,
|
||
$file_name = $dest_dir.'/'.zip_entry_name($zip_entry);
|
||
|
||
// 检查文件是否需要重写
|
||
if ($overwrite === true || $overwrite === false && !is_file($file_name)){
|
||
// 读取压缩文件的内容
|
||
$fstream = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));
|
||
@file_put_contents($file_name, $fstream);
|
||
// 设置权限
|
||
chmod($file_name, 0777);
|
||
//echo "save: ".$file_name."<br />";die;
|
||
}
|
||
// 关闭入口
|
||
zip_entry_close($zip_entry);
|
||
}
|
||
}
|
||
// 关闭压缩包
|
||
zip_close($zip);
|
||
}
|
||
}else{
|
||
return false;
|
||
}
|
||
return true;
|
||
}
|
||
/**
|
||
* 创建目录
|
||
*/
|
||
function create_dirs($path){
|
||
if (!is_dir($path)){
|
||
$directory_path = "";
|
||
$directories = explode("/",$path);
|
||
array_pop($directories);
|
||
foreach($directories as $directory){
|
||
$directory_path .= $directory."/";
|
||
if (!is_dir($directory_path)){
|
||
mkdir($directory_path);
|
||
chmod($directory_path, 0777);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
function filterArr($arr,$data){
|
||
$newData=[];
|
||
foreach ($arr as $v){
|
||
$count=0;
|
||
foreach ($data as $vo){
|
||
if($v['days']==$vo['days']&&$vo['count']){
|
||
$count=$vo['count'];
|
||
}
|
||
}
|
||
$newData[]=array(
|
||
'days'=>$v['days'],
|
||
'count'=>$count,
|
||
);
|
||
}
|
||
return $newData;
|
||
}
|
||
//门店编号,6位数不足6位数补0
|
||
function storeCode($shop_id){
|
||
if(is_numeric($shop_id)){
|
||
$num=6-strlen($shop_id);
|
||
$code=str_pad(mt_rand(0, 999999), $num, "0", STR_PAD_BOTH);
|
||
$code=substr($code,0,$num).$shop_id;
|
||
return $code;
|
||
}
|
||
}
|
||
|
||
function curl_post($url, $params = array(), $headers = [])
|
||
{
|
||
$params = json_encode($params);
|
||
$ch = curl_init();
|
||
curl_setopt($ch, CURLOPT_URL, $url);
|
||
curl_setopt($ch, CURLOPT_HEADER, 0);
|
||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
|
||
curl_setopt($ch, CURLOPT_POST, 1);
|
||
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
|
||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||
//ssl?false
|
||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
|
||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
|
||
$output = curl_exec($ch);
|
||
curl_close($ch);
|
||
return $output;
|
||
}
|
||
//查看当月的第一天和最后一天
|
||
function getMonthRange() {
|
||
$beginDate = date('Y-m-01 00:00:00', strtotime(date("Y-m-d")));
|
||
$endDate = date('Y-m-d 23:59:59', strtotime("$beginDate +1 month -1 day"));
|
||
$data['start'] = strtotime($beginDate);
|
||
$data['end'] = strtotime($endDate);
|
||
return $data;
|
||
}
|
||
//查看当周的第一天和最后一天
|
||
function getWeekRange() {
|
||
|
||
$sdefaultDate = date("Y-m-d");
|
||
// $first =1 表示每周星期一为开始日期 0表示每周日为开始日期
|
||
$first = 1;
|
||
// 获取当前周的第几天 周日是 0 周一到周六是 1 - 6
|
||
$w = date('w', strtotime($sdefaultDate));
|
||
// 获取本周开始日期,如果$w是0,则表示周日,减去 6 天
|
||
$week_start = date('Y-m-d 00:00:00', strtotime("$sdefaultDate -" . ($w ? $w - $first : 6) . ' days'));
|
||
// 本周结束日期
|
||
$week_end = date('Y-m-d 23:59:59', strtotime("$week_start +6 days"));
|
||
$data['start'] = strtotime($week_start);
|
||
$data['end'] = strtotime($week_end);
|
||
return $data;
|
||
}
|
||
//查看当周的第一天和最后一天
|
||
function getQuarterRange() {
|
||
|
||
$season = ceil((date('n'))/3);//当月是第几季度
|
||
$data['start'] =mktime(0, 0, 0,$season*3-3+1,1,date('Y'));
|
||
$data['end'] = mktime(23,59,59,$season*3,date('t',mktime(0, 0 , 0,$season*3,1,date("Y"))),date('Y'));
|
||
|
||
return $data;
|
||
}
|
||
|
||
function downloadExcel($newExcel, $filename, $format)
|
||
{
|
||
// $format只能为 Xlsx 或 Xls
|
||
if ($format == 'Xlsx') {
|
||
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
|
||
} elseif ($format == 'Xls') {
|
||
header('Content-Type: application/vnd.ms-excel');
|
||
}
|
||
|
||
header("Content-Disposition: attachment;filename="
|
||
. $filename . '.' . strtolower($format));
|
||
header('Cache-Control: max-age=0');
|
||
$objWriter = IOFactory::createWriter($newExcel, $format);
|
||
try {
|
||
$objWriter->save('php://output');
|
||
} catch (Exception $e) {
|
||
echo $e->getMessage();
|
||
// die(); // 终止异常
|
||
}
|
||
//通过php保存在本地的时候需要用到
|
||
//$objWriter->save($dir.'/demo.xlsx');
|
||
|
||
//以下为需要用到IE时候设置
|
||
// If you're serving to IE 9, then the following may be needed
|
||
//header('Cache-Control: max-age=1');
|
||
// If you're serving to IE over SSL, then the following may be needed
|
||
//header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
|
||
//header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); // always modified
|
||
//header('Cache-Control: cache, must-revalidate'); // HTTP/1.1
|
||
//header('Pragma: public'); // HTTP/1.0
|
||
exit;
|
||
}
|
||
|
||
//返回当日是周几
|
||
function getWeek($unixTime=''){
|
||
|
||
$unixTime=is_numeric($unixTime)?$unixTime:time();
|
||
|
||
$weekarray=array('日','一','二','三','四','五','六');
|
||
|
||
return '周'.$weekarray[date('w',$unixTime)];
|
||
|
||
}
|
||
function getCurrentTimeSection($beginTime,$endTime)
|
||
{
|
||
$checkDayStr = date('Y-m-d ',time());
|
||
$timeBegin1 = strtotime($checkDayStr."$beginTime".":00");
|
||
$timeEnd1 = strtotime($checkDayStr."$endTime".":00");
|
||
|
||
$curr_time = time();
|
||
|
||
if($curr_time >= $timeBegin1 && $curr_time <= $timeEnd1)
|
||
{
|
||
return 1;
|
||
}
|
||
|
||
return 0;
|
||
}
|
||
//数组转换成xml
|
||
function arrayToXml($arr) {
|
||
$xml = "<root>";
|
||
foreach ($arr as $key => $val) {
|
||
if (is_array($val)) {
|
||
$xml .= "<" . $key . ">" . arrayToXml($val) . "</" . $key . ">";
|
||
} else {
|
||
$xml .= "<" . $key . ">" . $val . "</" . $key . ">";
|
||
}
|
||
}
|
||
$xml .= "</root>";
|
||
return $xml;
|
||
}
|
||
//xml转换成数组
|
||
function xmlToArray($xml) {
|
||
|
||
//禁止引用外部xml实体
|
||
|
||
libxml_disable_entity_loader(true);
|
||
|
||
$xmlstring = simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA);
|
||
|
||
$val = json_decode(json_encode($xmlstring), true);
|
||
|
||
return $val;
|
||
}
|
||
|
||
function qrcodeWithLogo($QR, $logo) {
|
||
$QR = imagecreatefromstring($QR);
|
||
$logo = imagecreatefromstring($logo);
|
||
$QR_width = imagesx($QR); //二维码图片宽度
|
||
$QR_height = imagesy($QR); //二维码图片高度
|
||
$logo_width = imagesx($logo); //logo图片宽度
|
||
$logo_height = imagesy($logo); //logo图片高度
|
||
$logo_qr_width = $QR_width / 2.2; //组合之后logo的宽度(占二维码的1/2.2)
|
||
$scale = $logo_width / $logo_qr_width; //logo的宽度缩放比(本身宽度/组合后的宽度)
|
||
$logo_qr_height = $logo_height / $scale; //组合之后logo的高度
|
||
$from_width = ($QR_width - $logo_qr_width) / 2; //组合之后logo左上角所在坐标点
|
||
/**
|
||
* 重新组合图片并调整大小
|
||
* imagecopyresampled() 将一幅图像(源图象)中的一块正方形区域拷贝到另一个图像中
|
||
*/
|
||
imagecopyresampled($QR, $logo, $from_width, $from_width, 0, 0, $logo_qr_width, $logo_qr_height, $logo_width, $logo_height);
|
||
/**
|
||
* 如果想要直接输出图片,应该先设header。header("Content-Type: image/png; charset=utf-8");
|
||
* 并且去掉缓存区函数
|
||
*/
|
||
//获取输出缓存,否则imagepng会把图片输出到浏览器
|
||
ob_start();
|
||
imagepng($QR);
|
||
imagedestroy($QR);
|
||
imagedestroy($logo);
|
||
$contents = ob_get_contents();
|
||
ob_end_clean();
|
||
return $contents;
|
||
}
|
||
/**
|
||
* 剪切图片为圆形
|
||
* @param $picture 图片数据流 比如file_get_contents(imageurl)返回的东东
|
||
* @return 图片数据流
|
||
*/
|
||
function yuanImg($picture) {
|
||
$src_img = imagecreatefromstring($picture);
|
||
$w = imagesx($src_img);
|
||
$h = imagesy($src_img);
|
||
$w = min($w, $h);
|
||
$h = $w;
|
||
$img = imagecreatetruecolor($w, $h);
|
||
//这一句一定要有
|
||
imagesavealpha($img, true);
|
||
//拾取一个完全透明的颜色,最后一个参数127为全透明
|
||
$bg = imagecolorallocatealpha($img, 255, 255, 255, 127);
|
||
imagefill($img, 0, 0, $bg);
|
||
$r = $w / 2; //圆半径
|
||
$y_x = $r; //圆心X坐标
|
||
$y_y = $r; //圆心Y坐标
|
||
for ($x = 0; $x < $w; $x++) {
|
||
for ($y = 0; $y < $h; $y++) {
|
||
$rgbColor = imagecolorat($src_img, $x, $y);
|
||
if (((($x - $r) * ($x - $r) + ($y - $r) * ($y - $r)) < ($r * $r))) {
|
||
imagesetpixel($img, $x, $y, $rgbColor);
|
||
}
|
||
}
|
||
}
|
||
/**
|
||
* 如果想要直接输出图片,应该先设header。header("Content-Type: image/png; charset=utf-8");
|
||
* 并且去掉缓存区函数
|
||
*/
|
||
//获取输出缓存,否则imagepng会把图片输出到浏览器
|
||
ob_start();
|
||
imagepng($img);
|
||
imagedestroy($img);
|
||
$contents = ob_get_contents();
|
||
ob_end_clean();
|
||
return $contents;
|
||
}
|
||
|
||
|
||
/**
|
||
* 获取某月所有时间
|
||
* @param string $time 某天时间戳
|
||
* @param string $format 转换的时间格式
|
||
* @return array
|
||
**/
|
||
function getMonth($time = '', $format='Y-m-d'){
|
||
$time = $time != '' ? $time : time();
|
||
//获取当前周几
|
||
$week = date('d', $time);
|
||
$date = [];
|
||
for ($i=1; $i<= date('t', $time); $i++){
|
||
//if(strtotime( '+' . $i-$week .' days', $time)<=time()) {
|
||
$date[] = date($format, strtotime('+' . $i - $week . ' days', $time));
|
||
// }
|
||
}
|
||
return $date;
|
||
}
|
||
//删除目录及文件
|
||
function deldir($path) {
|
||
//如果是目录则继续
|
||
if (is_dir($path)) {
|
||
//扫描一个文件夹内的所有文件夹和文件并返回数组
|
||
$p = scandir($path);
|
||
foreach ($p as $key => $val) {
|
||
//排除目录中的.和..
|
||
if ($val != "." && $val != "..") {
|
||
//如果是目录则递归子目录,继续操作
|
||
if (is_dir($path . $val)) {
|
||
//子目录中操作删除文件夹和文件
|
||
deldir($path . $val . '/');
|
||
//目录清空后删除空文件夹
|
||
@rmdir($path . $val);
|
||
} else {
|
||
//如果是文件直接删除
|
||
unlink($path . '/' . $val);
|
||
}
|
||
}
|
||
}
|
||
//closedir($dh);
|
||
//删除目录文件夹
|
||
if (rmdir($path)) {
|
||
return true;
|
||
} else {
|
||
return false;
|
||
}
|
||
}
|
||
return false;
|
||
}
|
||
|
||
/**
|
||
* 获取两个时间之间的日期
|
||
* @param $startDate
|
||
* @param $endDate
|
||
* @return array
|
||
*/
|
||
function getDatesBetweenTwoDays($startDate, $endDate)
|
||
{
|
||
$dates = [];
|
||
if (strtotime($startDate) > strtotime($endDate)) {
|
||
// 如果开始日期大于结束日期,直接return 防止下面的循环出现死循环
|
||
return $dates;
|
||
} elseif ($startDate == $endDate) {
|
||
// 开始日期与结束日期是同一天时
|
||
array_push($dates, $startDate);
|
||
return $dates;
|
||
} else {
|
||
array_push($dates, $startDate);
|
||
$currentDate = $startDate;
|
||
do {
|
||
$nextDate = date('Y-m-d', strtotime($currentDate . ' +1 days'));
|
||
array_push($dates, $nextDate);
|
||
$currentDate = $nextDate;
|
||
} while ($endDate != $currentDate);
|
||
|
||
return $dates;
|
||
}
|
||
}
|
||
/**
|
||
* 数据导出
|
||
* @param array $title 标题行名称
|
||
* @param array $data 导出数据 需要注意导出的时候,是按照查询字段先后顺序的
|
||
* @param string $fileName 下载是的excel文件名
|
||
* @param string $savePath 保存路径
|
||
* @param $isDown 是否下载 false--保存 true--下载
|
||
* @return $top_name 首行合并的抬头内容
|
||
*/
|
||
//示例 exportExcel(array('姓名','年龄'), array(array('a',21),array('b',23)), '我是下载的excle名字', './', true,'我是首行抬头居中的内容');
|
||
function exportExcel($title, $data, $fileName, $savePath='./', $isDown=true,$top_name=''){
|
||
error_reporting(0);
|
||
$obj = new Spreadsheet(); //创建一个新的excel文档
|
||
//横向单元格标识
|
||
$cellName = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'AA', 'AB', 'AC', 'AD', 'AE', 'AF', 'AG', 'AH', 'AI', 'AJ', 'AK', 'AL', 'AM', 'AN', 'AO', 'AP', 'AQ', 'AR', 'AS', 'AT', 'AU', 'AV', 'AW', 'AX', 'AY', 'AZ');
|
||
$obj->getActiveSheet(0)->setTitle('sheet名称'); //设置sheet名称
|
||
$_row = 1; //设置纵向单元格标识
|
||
if($title){
|
||
$_cnt = count($title);
|
||
|
||
//$obj->getActiveSheet(0)->mergeCells('A'.$_row.':'.$cellName[$_cnt-1].$_row); //合并单元格
|
||
|
||
if($top_name){
|
||
$obj->setActiveSheetIndex(0)->setCellValue('A'.$_row, $top_name); //设置合并后的单元格内容
|
||
$_row++;
|
||
}
|
||
//
|
||
$obj->getDefaultStyle()->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
|
||
$obj->getDefaultStyle()->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
|
||
//
|
||
$i = 0;
|
||
foreach($title AS $v){ //设置列标题
|
||
$obj->setActiveSheetIndex(0)->setCellValue($cellName[$i].$_row, $v);
|
||
$i++;
|
||
}
|
||
$_row++;
|
||
}
|
||
|
||
//填写数据
|
||
if($data){
|
||
$i = 0;
|
||
foreach($data AS $_v){
|
||
$j = 0;
|
||
foreach($_v AS $_cell){
|
||
$obj->getActiveSheet(0)->setCellValue($cellName[$j] . ($i+$_row), $_cell);
|
||
$j++;
|
||
}
|
||
$i++;
|
||
}
|
||
}
|
||
|
||
//文件名处理
|
||
if(!$fileName){
|
||
$fileName = uniqid(time(),true);
|
||
}
|
||
|
||
$objWrite = IOFactory::createWriter($obj, 'Xls');
|
||
|
||
if($isDown){ //网页下载
|
||
header('pragma:public');
|
||
header("Content-Disposition:attachment;filename=$fileName.xls");
|
||
$objWrite->save('php://output');exit;
|
||
}
|
||
|
||
$_fileName = iconv("utf-8", "gb2312", $fileName); //转码
|
||
$_savePath = $savePath.$_fileName.'.xlsx';
|
||
$objWrite->save($_savePath);
|
||
|
||
return $savePath.$fileName.'.xlsx';
|
||
|
||
|
||
|
||
}
|
||
|
||
function Sec2Time($time)
|
||
{
|
||
if (is_numeric($time)) {
|
||
$value = array(
|
||
"years" => 0, "days" => 0, "hours" => 0,
|
||
"minutes" => 0, "seconds" => 0,
|
||
);
|
||
$t = '';
|
||
if ($time >= 31556926) {
|
||
$value["years"] = floor($time / 31556926);
|
||
$time = ($time % 31556926);
|
||
$t .= $value["years"] . "年";
|
||
}
|
||
if ($time >= 86400) {
|
||
$value["days"] = floor($time / 86400);
|
||
$time = ($time % 86400);
|
||
$t .= $value["days"] . "天";
|
||
}
|
||
if ($time >= 3600) {
|
||
$value["hours"] = floor($time / 3600);
|
||
$time = ($time % 3600);
|
||
$t .= $value["hours"] . "小时";
|
||
}
|
||
if ($time >= 60) {
|
||
$value["minutes"] = floor($time / 60);
|
||
$time = ($time % 60);
|
||
$t .= $value["minutes"] . "分";
|
||
}
|
||
$value["seconds"] = floor($time);
|
||
//return (array) $value;
|
||
$t .= $value["seconds"] . "秒";
|
||
return $t;
|
||
|
||
} else {
|
||
return (bool) false;
|
||
}
|
||
}
|
||
function miniScan($dir){
|
||
//忽略升级的文件夹
|
||
$ignore = [
|
||
'.',
|
||
'..',
|
||
];
|
||
$output = [];
|
||
$list = scandir(Yii::$app->basePath.'/'.$dir);
|
||
foreach ($list as $item) {
|
||
if (in_array($item, $ignore)) {
|
||
continue;
|
||
}
|
||
$_temPath = Yii::$app->basePath.'/'.$dir . $item;
|
||
// dd($_temPath);die;
|
||
if (is_dir($_temPath)) {
|
||
//dd($_temPath);
|
||
$_temOutput = miniScan($dir . $item . '/');
|
||
$output = array_merge($output, $_temOutput);
|
||
continue;
|
||
|
||
}
|
||
$temMd5 = md5(file_get_contents($_temPath));
|
||
|
||
$output[$dir . $item] = $temMd5;
|
||
}
|
||
return $output;
|
||
}
|
||
function dateRange($time = null, $day = 7, $format = 'Y-m-d') {
|
||
$time = $time ?: strtotime(date($format));
|
||
$date = [];
|
||
$weekArr[] = '周日';
|
||
$weekArr[] = '周一';
|
||
$weekArr[] = '周二';
|
||
$weekArr[] = '周三';
|
||
$weekArr[] = '周四';
|
||
$weekArr[] = '周五';
|
||
$weekArr[] = '周六';
|
||
for ($i = 0; $i < $day; $i++) {
|
||
$dateTime = date($format, strtotime('+' . $i . ' days', $time));
|
||
$dayName = date("m-d", strtotime('+' . $i . ' days', $time));
|
||
if ($dateTime == date($format)) {
|
||
$dayName = '今天';
|
||
}
|
||
if ($dateTime == date($format, strtotime('+1days', time()))) {
|
||
$dayName = '明天';
|
||
}
|
||
$date[$i] = array(
|
||
'time' => $dateTime,
|
||
'week' => date("w", strtotime($dateTime)) == 0 ? 7 : date("w", strtotime($dateTime)),
|
||
'day' => $dayName,
|
||
'weekName' => $weekArr[date("w", strtotime($dateTime))],
|
||
);
|
||
}
|
||
return $date;
|
||
|
||
}
|
||
|
||
//获取本周日期
|
||
function get_week($time = '', $format = 'Y-m-d') {
|
||
$time = $time != '' ? $time : time();
|
||
//获取当前周几
|
||
$week = date('w', $time);
|
||
$date = [];
|
||
for ($i = 0; $i < 7; $i++) {
|
||
$date[$i] = date($format, strtotime('+' . $i . ' days', $time));
|
||
}
|
||
return $date;
|
||
}
|
||
// php 获取当前访问的完整url
|
||
function GetCurUrl() {
|
||
$url =$_SERVER["REQUEST_SCHEME"].'://'.$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
|
||
return $url;
|
||
}
|
||
|
||
function stringToPinYin($chinese){
|
||
$chinese=set_char($chinese);
|
||
$result = '' ;
|
||
for ($i=0; $i<strlen($chinese); $i++) {
|
||
$p = ord(substr($chinese,$i,1));
|
||
if ($p>160) {
|
||
$q = ord(substr($chinese,++$i,1));
|
||
$p = $p*256 + $q - 65536;
|
||
}
|
||
$result .= substr(zh_to_py($p),0,1);
|
||
}
|
||
return $result ;
|
||
}
|
||
//-------------------中文转拼音--------------------------------//
|
||
function zh_to_py($num, $blank = '') {
|
||
$pylist = array(
|
||
'a'=>-20319,
|
||
'ai'=>-20317,
|
||
'an'=>-20304,
|
||
'ang'=>-20295,
|
||
'ao'=>-20292,
|
||
'ba'=>-20283,
|
||
'bai'=>-20265,
|
||
'ban'=>-20257,
|
||
'bang'=>-20242,
|
||
'bao'=>-20230,
|
||
'bei'=>-20051,
|
||
'ben'=>-20036,
|
||
'beng'=>-20032,
|
||
'bi'=>-20026,
|
||
'bian'=>-20002,
|
||
'biao'=>-19990,
|
||
'bie'=>-19986,
|
||
'bin'=>-19982,
|
||
'bing'=>-19976,
|
||
'bo'=>-19805,
|
||
'bu'=>-19784,
|
||
'ca'=>-19775,
|
||
'cai'=>-19774,
|
||
'can'=>-19763,
|
||
'cang'=>-19756,
|
||
'cao'=>-19751,
|
||
'ce'=>-19746,
|
||
'ceng'=>-19741,
|
||
'cha'=>-19739,
|
||
'chai'=>-19728,
|
||
'chan'=>-19725,
|
||
'chang'=>-19715,
|
||
'chao'=>-19540,
|
||
'che'=>-19531,
|
||
'chen'=>-19525,
|
||
'cheng'=>-19515,
|
||
'chi'=>-19500,
|
||
'chong'=>-19484,
|
||
'chou'=>-19479,
|
||
'chu'=>-19467,
|
||
'chuai'=>-19289,
|
||
'chuan'=>-19288,
|
||
'chuang'=>-19281,
|
||
'chui'=>-19275,
|
||
'chun'=>-19270,
|
||
'chuo'=>-19263,
|
||
'ci'=>-19261,
|
||
'cong'=>-19249,
|
||
'cou'=>-19243,
|
||
'cu'=>-19242,
|
||
'cuan'=>-19238,
|
||
'cui'=>-19235,
|
||
'cun'=>-19227,
|
||
'cuo'=>-19224,
|
||
'da'=>-19218,
|
||
'dai'=>-19212,
|
||
'dan'=>-19038,
|
||
'dang'=>-19023,
|
||
'dao'=>-19018,
|
||
'de'=>-19006,
|
||
'deng'=>-19003,
|
||
'di'=>-18996,
|
||
'dian'=>-18977,
|
||
'diao'=>-18961,
|
||
'die'=>-18952,
|
||
'ding'=>-18783,
|
||
'diu'=>-18774,
|
||
'dong'=>-18773,
|
||
'dou'=>-18763,
|
||
'du'=>-18756,
|
||
'duan'=>-18741,
|
||
'dui'=>-18735,
|
||
'dun'=>-18731,
|
||
'duo'=>-18722,
|
||
'e'=>-18710,
|
||
'en'=>-18697,
|
||
'er'=>-18696,
|
||
'fa'=>-18526,
|
||
'fan'=>-18518,
|
||
'fang'=>-18501,
|
||
'fei'=>-18490,
|
||
'fen'=>-18478,
|
||
'feng'=>-18463,
|
||
'fo'=>-18448,
|
||
'fou'=>-18447,
|
||
'fu'=>-18446,
|
||
'ga'=>-18239,
|
||
'gai'=>-18237,
|
||
'gan'=>-18231,
|
||
'gang'=>-18220,
|
||
'gao'=>-18211,
|
||
'ge'=>-18201,
|
||
'gei'=>-18184,
|
||
'gen'=>-18183,
|
||
'geng'=>-18181,
|
||
'gong'=>-18012,
|
||
'gou'=>-17997,
|
||
'gu'=>-17988,
|
||
'gua'=>-17970,
|
||
'guai'=>-17964,
|
||
'guan'=>-17961,
|
||
'guang'=>-17950,
|
||
'gui'=>-17947,
|
||
'gun'=>-17931,
|
||
'guo'=>-17928,
|
||
'ha'=>-17922,
|
||
'hai'=>-17759,
|
||
'han'=>-17752,
|
||
'hang'=>-17733,
|
||
'hao'=>-17730,
|
||
'he'=>-17721,
|
||
'hei'=>-17703,
|
||
'hen'=>-17701,
|
||
'heng'=>-17697,
|
||
'hong'=>-17692,
|
||
'hou'=>-17683,
|
||
'hu'=>-17676,
|
||
'hua'=>-17496,
|
||
'huai'=>-17487,
|
||
'huan'=>-17482,
|
||
'huang'=>-17468,
|
||
'hui'=>-17454,
|
||
'hun'=>-17433,
|
||
'huo'=>-17427,
|
||
'ji'=>-17417,
|
||
'jia'=>-17202,
|
||
'jian'=>-17185,
|
||
'jiang'=>-16983,
|
||
'jiao'=>-16970,
|
||
'jie'=>-16942,
|
||
'jin'=>-16915,
|
||
'jing'=>-16733,
|
||
'jiong'=>-16708,
|
||
'jiu'=>-16706,
|
||
'ju'=>-16689,
|
||
'juan'=>-16664,
|
||
'jue'=>-16657,
|
||
'jun'=>-16647,
|
||
'ka'=>-16474,
|
||
'kai'=>-16470,
|
||
'kan'=>-16465,
|
||
'kang'=>-16459,
|
||
'kao'=>-16452,
|
||
'ke'=>-16448,
|
||
'ken'=>-16433,
|
||
'keng'=>-16429,
|
||
'kong'=>-16427,
|
||
'kou'=>-16423,
|
||
'ku'=>-16419,
|
||
'kua'=>-16412,
|
||
'kuai'=>-16407,
|
||
'kuan'=>-16403,
|
||
'kuang'=>-16401,
|
||
'kui'=>-16393,
|
||
'kun'=>-16220,
|
||
'kuo'=>-16216,
|
||
'la'=>-16212,
|
||
'lai'=>-16205,
|
||
'lan'=>-16202,
|
||
'lang'=>-16187,
|
||
'lao'=>-16180,
|
||
'le'=>-16171,
|
||
'lei'=>-16169,
|
||
'leng'=>-16158,
|
||
'li'=>-16155,
|
||
'lia'=>-15959,
|
||
'lian'=>-15958,
|
||
'liang'=>-15944,
|
||
'liao'=>-15933,
|
||
'lie'=>-15920,
|
||
'lin'=>-15915,
|
||
'ling'=>-15903,
|
||
'liu'=>-15889,
|
||
'long'=>-15878,
|
||
'lou'=>-15707,
|
||
'lu'=>-15701,
|
||
'lv'=>-15681,
|
||
'luan'=>-15667,
|
||
'lue'=>-15661,
|
||
'lun'=>-15659,
|
||
'luo'=>-15652,
|
||
'ma'=>-15640,
|
||
'mai'=>-15631,
|
||
'man'=>-15625,
|
||
'mang'=>-15454,
|
||
'mao'=>-15448,
|
||
'me'=>-15436,
|
||
'mei'=>-15435,
|
||
'men'=>-15419,
|
||
'meng'=>-15416,
|
||
'mi'=>-15408,
|
||
'mian'=>-15394,
|
||
'miao'=>-15385,
|
||
'mie'=>-15377,
|
||
'min'=>-15375,
|
||
'ming'=>-15369,
|
||
'miu'=>-15363,
|
||
'mo'=>-15362,
|
||
'mou'=>-15183,
|
||
'mu'=>-15180,
|
||
'na'=>-15165,
|
||
'nai'=>-15158,
|
||
'nan'=>-15153,
|
||
'nang'=>-15150,
|
||
'nao'=>-15149,
|
||
'ne'=>-15144,
|
||
'nei'=>-15143,
|
||
'nen'=>-15141,
|
||
'neng'=>-15140,
|
||
'ni'=>-15139,
|
||
'nian'=>-15128,
|
||
'niang'=>-15121,
|
||
'niao'=>-15119,
|
||
'nie'=>-15117,
|
||
'nin'=>-15110,
|
||
'ning'=>-15109,
|
||
'niu'=>-14941,
|
||
'nong'=>-14937,
|
||
'nu'=>-14933,
|
||
'nv'=>-14930,
|
||
'nuan'=>-14929,
|
||
'nue'=>-14928,
|
||
'nuo'=>-14926,
|
||
'o'=>-14922,
|
||
'ou'=>-14921,
|
||
'pa'=>-14914,
|
||
'pai'=>-14908,
|
||
'pan'=>-14902,
|
||
'pang'=>-14894,
|
||
'pao'=>-14889,
|
||
'pei'=>-14882,
|
||
'pen'=>-14873,
|
||
'peng'=>-14871,
|
||
'pi'=>-14857,
|
||
'pian'=>-14678,
|
||
'piao'=>-14674,
|
||
'pie'=>-14670,
|
||
'pin'=>-14668,
|
||
'ping'=>-14663,
|
||
'po'=>-14654,
|
||
'pu'=>-14645,
|
||
'qi'=>-14630,
|
||
'qia'=>-14594,
|
||
'qian'=>-14429,
|
||
'qiang'=>-14407,
|
||
'qiao'=>-14399,
|
||
'qie'=>-14384,
|
||
'qin'=>-14379,
|
||
'qing'=>-14368,
|
||
'qiong'=>-14355,
|
||
'qiu'=>-14353,
|
||
'qu'=>-14345,
|
||
'quan'=>-14170,
|
||
'que'=>-14159,
|
||
'qun'=>-14151,
|
||
'ran'=>-14149,
|
||
'rang'=>-14145,
|
||
'rao'=>-14140,
|
||
're'=>-14137,
|
||
'ren'=>-14135,
|
||
'reng'=>-14125,
|
||
'ri'=>-14123,
|
||
'rong'=>-14122,
|
||
'rou'=>-14112,
|
||
'ru'=>-14109,
|
||
'ruan'=>-14099,
|
||
'rui'=>-14097,
|
||
'run'=>-14094,
|
||
'ruo'=>-14092,
|
||
'sa'=>-14090,
|
||
'sai'=>-14087,
|
||
'san'=>-14083,
|
||
'sang'=>-13917,
|
||
'sao'=>-13914,
|
||
'se'=>-13910,
|
||
'sen'=>-13907,
|
||
'seng'=>-13906,
|
||
'sha'=>-13905,
|
||
'shai'=>-13896,
|
||
'shan'=>-13894,
|
||
'shang'=>-13878,
|
||
'shao'=>-13870,
|
||
'she'=>-13859,
|
||
'shen'=>-13847,
|
||
'sheng'=>-13831,
|
||
'shi'=>-13658,
|
||
'shou'=>-13611,
|
||
'shu'=>-13601,
|
||
'shua'=>-13406,
|
||
'shuai'=>-13404,
|
||
'shuan'=>-13400,
|
||
'shuang'=>-13398,
|
||
'shui'=>-13395,
|
||
'shun'=>-13391,
|
||
'shuo'=>-13387,
|
||
'si'=>-13383,
|
||
'song'=>-13367,
|
||
'sou'=>-13359,
|
||
'su'=>-13356,
|
||
'suan'=>-13343,
|
||
'sui'=>-13340,
|
||
'sun'=>-13329,
|
||
'suo'=>-13326,
|
||
'ta'=>-13318,
|
||
'tai'=>-13147,
|
||
'tan'=>-13138,
|
||
'tang'=>-13120,
|
||
'tao'=>-13107,
|
||
'te'=>-13096,
|
||
'teng'=>-13095,
|
||
'ti'=>-13091,
|
||
'tian'=>-13076,
|
||
'tiao'=>-13068,
|
||
'tie'=>-13063,
|
||
'ting'=>-13060,
|
||
'tong'=>-12888,
|
||
'tou'=>-12875,
|
||
'tu'=>-12871,
|
||
'tuan'=>-12860,
|
||
'tui'=>-12858,
|
||
'tun'=>-12852,
|
||
'tuo'=>-12849,
|
||
'wa'=>-12838,
|
||
'wai'=>-12831,
|
||
'wan'=>-12829,
|
||
'wang'=>-12812,
|
||
'wei'=>-12802,
|
||
'wen'=>-12607,
|
||
'weng'=>-12597,
|
||
'wo'=>-12594,
|
||
'wu'=>-12585,
|
||
'xi'=>-12556,
|
||
'xia'=>-12359,
|
||
'xian'=>-12346,
|
||
'xiang'=>-12320,
|
||
'xiao'=>-12300,
|
||
'xie'=>-12120,
|
||
'xin'=>-12099,
|
||
'xing'=>-12089,
|
||
'xiong'=>-12074,
|
||
'xiu'=>-12067,
|
||
'xu'=>-12058,
|
||
'xuan'=>-12039,
|
||
'xue'=>-11867,
|
||
'xun'=>-11861,
|
||
'ya'=>-11847,
|
||
'yan'=>-11831,
|
||
'yang'=>-11798,
|
||
'yao'=>-11781,
|
||
'ye'=>-11604,
|
||
'yi'=>-11589,
|
||
'yin'=>-11536,
|
||
'ying'=>-11358,
|
||
'yo'=>-11340,
|
||
'yong'=>-11339,
|
||
'you'=>-11324,
|
||
'yu'=>-11303,
|
||
'yuan'=>-11097,
|
||
'yue'=>-11077,
|
||
'yun'=>-11067,
|
||
'za'=>-11055,
|
||
'zai'=>-11052,
|
||
'zan'=>-11045,
|
||
'zang'=>-11041,
|
||
'zao'=>-11038,
|
||
'ze'=>-11024,
|
||
'zei'=>-11020,
|
||
'zen'=>-11019,
|
||
'zeng'=>-11018,
|
||
'zha'=>-11014,
|
||
'zhai'=>-10838,
|
||
'zhan'=>-10832,
|
||
'zhang'=>-10815,
|
||
'zhao'=>-10800,
|
||
'zhe'=>-10790,
|
||
'zhen'=>-10780,
|
||
'zheng'=>-10764,
|
||
'zhi'=>-10587,
|
||
'zhong'=>-10544,
|
||
'zhou'=>-10533,
|
||
'zhu'=>-10519,
|
||
'zhua'=>-10331,
|
||
'zhuai'=>-10329,
|
||
'zhuan'=>-10328,
|
||
'zhuang'=>-10322,
|
||
'zhui'=>-10315,
|
||
'zhun'=>-10309,
|
||
'zhuo'=>-10307,
|
||
'zi'=>-10296,
|
||
'zong'=>-10281,
|
||
'zou'=>-10274,
|
||
'zu'=>-10270,
|
||
'zuan'=>-10262,
|
||
'zui'=>-10260,
|
||
'zun'=>-10256,
|
||
'zuo'=>-10254
|
||
);
|
||
if($num>0 && $num<160 ) {
|
||
return chr($num);
|
||
} elseif ($num<-20319||$num>-10247) {
|
||
return $blank;
|
||
} else {
|
||
foreach ($pylist as $py => $code) {
|
||
if($code > $num) break;
|
||
$result = $py;
|
||
}
|
||
return $result;
|
||
}
|
||
}
|
||
function set_char($str,$charset="utf-8",$charset_out="gb2312"){
|
||
if(function_exists('iconv')){
|
||
$str=iconv($charset,$charset_out,$str);
|
||
}elseif(function_exists("mb_convert_encoding")){
|
||
$str=mb_convert_encoding($str,$charset_out,$charset);
|
||
}
|
||
return $str;
|
||
}
|