Yeelight /
miot-api
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * Created by PhpStorm. |
||
| 4 | * User: sheldon |
||
| 5 | * Date: 18-6-14 |
||
| 6 | * Time: 下午4:46. |
||
| 7 | */ |
||
| 8 | |||
| 9 | namespace MiotApi\Api; |
||
| 10 | |||
| 11 | class ErrorCode |
||
| 12 | { |
||
| 13 | /** |
||
| 14 | * HTTP 标准状态码 |
||
| 15 | * |
||
| 16 | * @var array |
||
| 17 | */ |
||
| 18 | public static $httpCodes = [ |
||
| 19 | 100 => 'Continue', |
||
| 20 | 101 => 'Switching Protocols', |
||
| 21 | 102 => 'Processing', // WebDAV; RFC 2518 |
||
| 22 | 200 => 'OK 成功,操作完成', |
||
| 23 | 201 => 'Created', |
||
| 24 | 202 => 'Accepted 已经接受此次请求,但操作未完成(完成了会有事件通知)', |
||
| 25 | 203 => 'Non-Authoritative Information', // since HTTP/1.1 |
||
| 26 | 204 => 'No Content', |
||
| 27 | 205 => 'Reset Content', |
||
| 28 | 206 => 'Partial Content', |
||
| 29 | 207 => 'Multi-Status 成功,但具有多个状态值 (对多个属性的读写)', // WebDAV; RFC 4918 |
||
| 30 | 208 => 'Already Reported', // WebDAV; RFC 5842 |
||
| 31 | 226 => 'IM Used', // RFC 3229 |
||
| 32 | 300 => 'Multiple Choices', |
||
| 33 | 301 => 'Moved Permanently', |
||
| 34 | 302 => 'Found', |
||
| 35 | 303 => 'See Other', // since HTTP/1.1 |
||
| 36 | 304 => 'Not Modified', |
||
| 37 | 305 => 'Use Proxy', // since HTTP/1.1 |
||
| 38 | 306 => 'Switch Proxy', |
||
| 39 | 307 => 'Temporary Redirect', // since HTTP/1.1 |
||
| 40 | 308 => 'Permanent Redirect', // approved as experimental RFC |
||
| 41 | 400 => 'Bad Request', |
||
| 42 | 401 => 'Unauthorized', |
||
| 43 | 402 => 'Payment Required', |
||
| 44 | 403 => 'Forbidden', |
||
| 45 | 404 => 'Not Found', |
||
| 46 | 405 => 'Method Not Allowed', |
||
| 47 | 406 => 'Not Acceptable', |
||
| 48 | 407 => 'Proxy Authentication Required', |
||
| 49 | 408 => 'Request Timeout', |
||
| 50 | 409 => 'Conflict', |
||
| 51 | 410 => 'Gone', |
||
| 52 | 411 => 'Length Required', |
||
| 53 | 412 => 'Precondition Failed', |
||
| 54 | 413 => 'Request Entity Too Large', |
||
| 55 | 414 => 'Request-URI Too Long', |
||
| 56 | 415 => 'Unsupported Media Type', |
||
| 57 | 416 => 'Requested Range Not Satisfiable', |
||
| 58 | 417 => 'Expectation Failed', |
||
| 59 | 418 => 'I\'m a teapot', // RFC 2324 |
||
| 60 | 419 => 'Authentication Timeout', // not in RFC 2616 |
||
| 61 | 420 => 'Method Failure', // Spring Framework |
||
| 62 | 422 => 'Unprocessable Entity', // WebDAV; RFC 4918 |
||
| 63 | 423 => 'Locked', // WebDAV; RFC 4918 |
||
| 64 | 424 => 'Failed Dependency', // WebDAV; RFC 4918 |
||
| 65 | 425 => 'Unordered Collection', // Internet draft |
||
| 66 | 426 => 'Upgrade Required', // RFC 2817 |
||
| 67 | 428 => 'Precondition Required', // RFC 6585 |
||
| 68 | 429 => 'Too Many Requests', // RFC 6585 |
||
| 69 | 431 => 'Request Header Fields Too Large', // RFC 6585 |
||
| 70 | 444 => 'No Response', // Nginx |
||
| 71 | 449 => 'Retry With', // Microsoft |
||
| 72 | 450 => 'Blocked by Windows Parental Controls', // Microsoft |
||
| 73 | 451 => 'Unavailable For Legal Reasons', // Internet draft |
||
| 74 | 494 => 'Request Header Too Large', // Nginx |
||
| 75 | 495 => 'Cert Error', // Nginx |
||
| 76 | 496 => 'No Cert', // Nginx |
||
| 77 | 497 => 'HTTP to HTTPS', // Nginx |
||
| 78 | 499 => 'Client Closed Request', // Nginx |
||
| 79 | 500 => 'Internal Server Error', |
||
| 80 | 501 => 'Not Implemented', |
||
| 81 | 502 => 'Bad Gateway', |
||
| 82 | 503 => 'Service Unavailable', |
||
| 83 | 504 => 'Gateway Timeout', |
||
| 84 | 505 => 'HTTP Version Not Supported', |
||
| 85 | 506 => 'Variant Also Negotiates', // RFC 2295 |
||
| 86 | 507 => 'Insufficient Storage', // WebDAV; RFC 4918 |
||
| 87 | 508 => 'Loop Detected', // WebDAV; RFC 5842 |
||
| 88 | 509 => 'Bandwidth Limit Exceeded', // Apache bw/limited extension |
||
| 89 | 510 => 'Not Extended', // RFC 2774 |
||
| 90 | 511 => 'Network Authentication Required', // RFC 6585 |
||
| 91 | 598 => 'Network read timeout error', // Unknown |
||
| 92 | 599 => 'Network connect timeout error', // Unknown |
||
| 93 | ]; |
||
| 94 | |||
| 95 | /** |
||
| 96 | * 出现错误的位置. |
||
| 97 | * |
||
| 98 | * @var array |
||
| 99 | */ |
||
| 100 | public static $positions = [ |
||
| 101 | 0 => '未知位置', |
||
| 102 | 1 => '开放平台', |
||
| 103 | 2 => '设备云', |
||
| 104 | 3 => '设备', |
||
| 105 | 4 => 'MIOT-SPEC', |
||
| 106 | ]; |
||
| 107 | |||
| 108 | public static $errorCodes = [ |
||
| 109 | '001' => 'Device不存在', |
||
| 110 | '002' => 'Service不存在', |
||
| 111 | '003' => 'Property不存在', |
||
| 112 | '004' => 'Event不存在', |
||
| 113 | '005' => 'Action不存在', |
||
| 114 | '006' => '没找到设备描述', |
||
| 115 | '007' => '没找到设备云', |
||
| 116 | '008' => '无效的ID (无效的PID、SID、AID、EID等)', |
||
| 117 | '009' => 'Scene不存在', |
||
| 118 | '013' => 'Property不可读', |
||
| 119 | '023' => 'Property不可写', |
||
| 120 | '033' => 'Property不可订阅', |
||
| 121 | '043' => 'Property值错误', |
||
| 122 | '034' => 'Action返回值错误', |
||
| 123 | '015' => 'Action执行错误', |
||
| 124 | '025' => 'Action参数个数不匹配', |
||
| 125 | '035' => 'Action参数错误', |
||
| 126 | '036' => '设备操作超时', |
||
| 127 | '100' => '设备在当前状态下无法执行此操作', |
||
| 128 | '901' => 'TOKEN不存在或过期', |
||
| 129 | '902' => 'TOKEN非法', |
||
| 130 | '903' => '授权过期', |
||
| 131 | '904' => '语音设备未授权', |
||
| 132 | '905' => '设备未绑定', |
||
| 133 | ]; |
||
| 134 | |||
| 135 | public static function getPosition($positionCode) |
||
| 136 | { |
||
| 137 | return ' Position : '. |
||
| 138 | (isset(self::$positions[$positionCode]) ? self::$positions[$positionCode] : 'Unknow Position'); |
||
| 139 | } |
||
| 140 | |||
| 141 | /** |
||
| 142 | * @param array $miotErrorCode |
||
| 143 | * |
||
| 144 | * @return string |
||
| 145 | */ |
||
| 146 | public static function getMiotErrorMessage($miotErrorCode) |
||
| 147 | { |
||
| 148 | if (preg_match('/\-70([0-9]{3})([0-9])([0-9]{3})/', $miotErrorCode, $matches)) { |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 149 | return self::getHttpMessage($matches[1]). |
||
| 150 | self::getErrorMessage($matches[2]). |
||
| 151 | self::getErrorMessage($matches[3]); |
||
| 152 | } |
||
| 153 | |||
| 154 | return 'Unknow Error'; |
||
| 155 | } |
||
| 156 | |||
| 157 | public static function getHttpMessage($httpCode) |
||
| 158 | { |
||
| 159 | return ' HttpCodeMessage ('.$httpCode.'): '. |
||
| 160 | (isset(self::$httpCodes[$httpCode]) ? self::$httpCodes[$httpCode] : 'Unknow Http Code'); |
||
| 161 | } |
||
| 162 | |||
| 163 | public static function getErrorMessage($errorCode) |
||
| 164 | { |
||
| 165 | return ' ErrorMessage : '. |
||
| 166 | (isset(self::$errorCodes[$errorCode]) ? self::$errorCodes[$errorCode] : 'Unknow Error'); |
||
| 167 | } |
||
| 168 | } |
||
| 169 |