Send.php 676 B

1234567891011121314151617181920212223242526272829
  1. <?php
  2. namespace lemo\api;
  3. use think\facade\Request;
  4. trait Send
  5. {
  6. /**
  7. * 返回成功
  8. */
  9. public static function returnMsg($code = 200,$message = '',$data = [],$header = [])
  10. {
  11. http_response_code($code); //设置返回头部
  12. $return['code'] = (int)$code;
  13. $return['message'] = $message;
  14. $return['data'] = is_array($data) ? $data : ['info'=>$data];
  15. // 发送头部信息
  16. foreach ($header as $name => $val) {
  17. if (is_null($val)) {
  18. header($name);
  19. } else {
  20. header($name . ':' . $val);
  21. }
  22. }
  23. exit(json_encode($return,JSON_UNESCAPED_UNICODE));
  24. }
  25. }