Error.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace App\Api\Service;
  3. /**
  4. * API服务端 - 错误码
  5. * @author Flc <2016-7-31 11:27:09>
  6. */
  7. class Error
  8. {
  9. /**
  10. * 错误码
  11. * @var [type]
  12. */
  13. public static $errCodes = [
  14. // 系统码
  15. '200' => '成功',
  16. '400' => '未知错误',
  17. '401' => '无此权限',
  18. '500' => '服务器异常',
  19. // 公共错误码
  20. '1001' => '[app_id]缺失',
  21. '1002' => '[app_id]不存在或无权限',
  22. '1003' => '[method]缺失',
  23. '1004' => '[format]错误',
  24. '1005' => '[sign_method]错误',
  25. '1006' => '[sign]缺失',
  26. '1007' => '[sign]签名错误',
  27. '1008' => '[method]方法不存在',
  28. '1009' => 'run方法不存在,请联系管理员',
  29. '1010' => '[nonce]缺失',
  30. '1011' => '[nonce]必须为字符串',
  31. '1012' => '[nonce]长度必须为1-32位',
  32. '1014' => '[token]用户异常',
  33. ];
  34. /**
  35. * 返回错误码
  36. * @var string
  37. */
  38. public static function getError($code = '400', $_ = false)
  39. {
  40. if (! isset(self::$errCodes[$code])) {
  41. $code = '400';
  42. }
  43. return ($_ ? "[{$code}]" : '')
  44. . self::$errCodes[$code];
  45. }
  46. }