'Not Found');
$message = 'Not Found';
} elseif ($code == 405) {
$status = 405;
$data = array('error' => 'Method not allowed');
$message = 'Method not allowed';
} else {
$status = 200;
$message = $msg;
}
//输出结果
header(self::HTTP_VERSION . " " . $status . " " . $message);
$output = array(
'code' => (int)intval($code),
'message' => $message,
);
$content_type = isset($_SERVER['CONTENT_TYPE']) ? $_SERVER['CONTENT_TYPE'] : $_SERVER['HTTP_ACCEPT'];
if (strpos($content_type, 'application/json') !== false) {
if (is_array($data) && $data['page_config']) {
$output = array_merge($output, $data);
} else {
$output['data'] = $data;
}
header("Content-Type: application/json");
echo self::encodeJson($output);
die();
} else if (strpos($content_type, 'application/xml') !== false) {
header("Content-Type: application/xml");
echo self::encodeXml($output);
die();
} else {
if (is_array($data) && $data['page_config']) {
$output = array_merge($output, $data);
} else {
$output['data'] = $data;
}
header("Content-Type: application/json");
echo self::encodeJson($output);
die();
}
}
//json格式
private static function encodeJson($responseData)
{
$str = json_encode($responseData);
return $str;
}
//xml格式
private static function encodeXml($responseData)
{
$xml = new \SimpleXMLElement('
| " . $k . " | " . $v . " | "; } } else { $html .= "" . $key . " | " . $value . " | "; } $html .= "