1.response.php
<?php
class Response{
/**
*按json方式输出通信数据
*@param integer $code 状态码
*@param string $message 提示信息
*@param array $data 数据
*return string
*/
public static function json($code,$message,$data=array()){
if(!is_numeric($code)){
return ‘‘;
}
$result = array(
‘code‘ => $code,
‘message‘ => $message,
‘data‘ => $data
);
echo json_encode($result);
exit;
}
}
2.test.php
<?php
require_once(‘./response.php‘);
$arr = array(
‘id‘ =>1,
‘name‘ => ‘shazhuang‘
);
Response::json(200,‘数据返回成功‘,$arr);
时间: 2024-09-30 04:38:17