2 Star 2 Fork 0

纸喵软件 / frame-php

Create your Gitee Account
Explore and code with more than 6 million developers,Free private repositories !:)
Sign up
This repository doesn't specify license. Without author's permission, this code is only for learning and cannot be used for other purposes.
Clone or download
Response.php 908 Bytes
Copy Edit Web IDE Raw Blame History
<?php
/**
*
* Created by PhpStorm.
* User: 倒霉狐狸
* Date: 2018-08-07
* Time: 10:58
*/
namespace zhimiao;
class Response {
// 默认的错误码提示信息
public static $code_msg = [
0 => '系统繁忙',
-1 => '未登录',
];
/**
* json输出
* @param $code
* @param null $data
* @param string $msg
* @param array $header
*/
public static function json($code, $data = null, $msg = '', $header = [])
{
$result = [
'code' => $code,
'msg' => self::$code_msg[$code] ?? $msg
];
if (!is_null($data)) {
$result['result'] = $data;
}
@ob_clean();
header("Content-Type: application/json; charset=utf-8");
foreach ($header as $k => $v) {
header("{$k}: {$v}");
}
echo json_encode($result);
exit();
}
}

Comment ( 0 )

Sign in for post a comment

PHP
1
https://gitee.com/zhimiao/frame-php.git
git@gitee.com:zhimiao/frame-php.git
zhimiao
frame-php
frame-php
master

Search

103611 48b8ff67 1899542 103622 4d02230c 1899542