JsonResponse.php 659 Bytes
<?php
/**
 * 给前端返回json帮助类
 */
header('Content-Type:application/json;charset=utf-8');
class JsonResponse
{
    public static function result($result) 
    {
        $data = [
            'errcode' => 0,
            'errmsg' => 'ok',
            'timestamp' => time(),
            'result' => $result,
        ];
        echo json_encode($data);
        die;
    }

    public static function error($errmsg = '', $code = '500') 
    {
        $data = [
            'errcode' => $code,
            'errmsg' => $errmsg,
            'timestamp' => time(),
            'result' => [],
        ];
        echo json_encode($data);
        die;
    }
}