44
55class Request {
66
7-
8- public static function curlRequest (array $ data ) {
7+ public static $ code = [
8+ '0 ' => 'Config issues. '
9+
10+ '200 ' => 'Success.',
911
10- $ responses = [
11- '200 ' => 'Success. ' ,
12+ '400 ' => ' Bad request.',
1213
13- ' 400 ' => 'Bad request . ' ,
14+ ' 403 ' => 'There was an error with the certificate or with the provider’s authentication token .',
1415
15- ' 403 ' => 'There was an error with the certificate or with the provider’s authentication token . ' ,
16+ ' 404 ' => 'The request contained an invalid :path value .',
1617
17- ' 404 ' => 'The request contained an invalid :path value. ' ,
18+ ' 405 ' => ' The request used an invalid :method value. Only POST requests are supported .',
1819
19- ' 405 ' => 'The request used an invalid :method value. Only POST requests are supported . ' ,
20+ ' 410 ' => ' The device token is no longer active for the topic .',
2021
21- ' 410 ' => 'The device token is no longer active for the topic . ' ,
22+ ' 413 ' => ' The notification payload was too large .',
2223
23- ' 413 ' => 'The notification payload was too large . ' ,
24+ ' 429 ' => ' The server received too many requests for the same device token .',
2425
25- ' 429 ' => 'The server received too many requests for the same device token . ' ,
26+ ' 500 ' => 'Internal server error .',
2627
27- '500 ' => 'Internal server error. ' ,
28+ '503 ' => ' The server is shutting down and unavailable.',
29+ ];
2830
29- '503 ' => 'The server is shutting down and unavailable. ' ,
30- ];
31+ public static function curlRequest(array $data) {
3132
3233 $url = $data[ ' config']['url ' ].$ data ['deviceToken ' ];
3334
@@ -37,13 +38,15 @@ public static function curlRequest(array $data) {
3738 curl_setopt($ ch , CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_2_0 );
3839
3940 curl_setopt($ ch , CURLOPT_SSLCERT , $ data ['config']['keyPath']);
40- # curl_setopt($ch, CURLOPT_SSLCERTPASSWD, $data['config']['secretKey']);
41+ curl_setopt($ ch , CURLOPT_SSLCERTPASSWD , $ data ['config']['secretKey']);
4142
4243 curl_setopt($ ch , CURLOPT_FAILONERROR , true);
4344 curl_exec($ ch );
4445 $ httpcode = curl_getinfo ($ ch , CURLINFO_HTTP_CODE );
4546 curl_close($ ch);
4647
47- return [ 'response ' => $ responses [$ httpcode ], 'code ' => $ httpcode ];
48+ $ httpcode = isset (self ::$ responses [$ httpcode ]) ? $ httpcode ? 0 ;
49+
50+ return [ 'response ' => ? self ::$ responses [$ httpcode ], 'code ' => $ httpcode ];
4851 }
4952}
0 commit comments