102 lines
1.9 KiB
PHP
Executable File
102 lines
1.9 KiB
PHP
Executable File
<?php
|
|
defined('BASEPATH') OR exit('No direct script access allowed');
|
|
|
|
//todo:暂用,需重构
|
|
|
|
/**
|
|
* 成功数据重构
|
|
* @param $data
|
|
* @return array
|
|
*/
|
|
if(!function_exists('info_format'))
|
|
{
|
|
function info_format($data)
|
|
{
|
|
$data = _clean($data);
|
|
is_bool($data) && $data = array('status' => $data);
|
|
is_numeric($data) && $data = array('count' => $data);
|
|
is_string($data) && $data = array('result' => $data);
|
|
|
|
if(is_array($data) && array_search(current($data), $data) === 0)
|
|
{
|
|
$data = array('list' => $data);
|
|
}
|
|
|
|
if(empty($data))
|
|
{
|
|
$data = array('result' => array());
|
|
}
|
|
|
|
return array('errCode' => '0', 'data' => $data);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 过滤空字符
|
|
* @param $array
|
|
* @return array
|
|
*/
|
|
if(!function_exists('_clean'))
|
|
{
|
|
function _clean($array)
|
|
{
|
|
if(!is_array($array))
|
|
{
|
|
return $array;
|
|
}
|
|
|
|
foreach($array as $k => $v)
|
|
{
|
|
if($v === '' || $v === null || $v === array())
|
|
{
|
|
unset($array[$k]);
|
|
}
|
|
elseif(is_array($v))
|
|
{
|
|
$array[$k] = _clean($v);
|
|
}
|
|
}
|
|
|
|
return $array;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* API 输出
|
|
* @param $result
|
|
* @param bool $ifgzip
|
|
*/
|
|
|
|
if(!function_exists('print_result'))
|
|
{
|
|
function print_result($result, $ifgzip = false)
|
|
{
|
|
if(!isset($result['errCode']))
|
|
{
|
|
$data = info_format($result);
|
|
}
|
|
else
|
|
{
|
|
$data = $result;
|
|
}
|
|
|
|
if($ifgzip)
|
|
{
|
|
header('Content-Type: application/json');
|
|
header('Content-Encoding: gzip');
|
|
echo gzencode(json_encode($data, JSON_UNESCAPED_UNICODE), 6);
|
|
exit;
|
|
}
|
|
else
|
|
{
|
|
$result = json_encode($data, JSON_UNESCAPED_UNICODE);
|
|
echo $result;
|
|
exit;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|