|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace SimpleApns\Lib; |
| 4 | + |
| 5 | +class Request { |
| 6 | + |
| 7 | + |
| 8 | + public static function curlRequest(array $data) { |
| 9 | + |
| 10 | + $responses = [ |
| 11 | + '200' => 'Success.', |
| 12 | + |
| 13 | + '400' => 'Bad request.', |
| 14 | + |
| 15 | + '403' => 'There was an error with the certificate or with the provider’s authentication token.', |
| 16 | + |
| 17 | + '404' => 'The request contained an invalid :path value.', |
| 18 | + |
| 19 | + '405' => 'The request used an invalid :method value. Only POST requests are supported.', |
| 20 | + |
| 21 | + '410' => 'The device token is no longer active for the topic.', |
| 22 | + |
| 23 | + '413' => 'The notification payload was too large.', |
| 24 | + |
| 25 | + '429' => 'The server received too many requests for the same device token.', |
| 26 | + |
| 27 | + '500' => 'Internal server error.', |
| 28 | + |
| 29 | + '503' => 'The server is shutting down and unavailable.', |
| 30 | + ]; |
| 31 | + |
| 32 | + $url = $data['config']['url'].$data['deviceToken']; |
| 33 | + |
| 34 | + $ch = curl_init($url); |
| 35 | + curl_setopt($ch, CURLOPT_HTTPHEADER, $data['headers']); |
| 36 | + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data['message'])); |
| 37 | + curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0); |
| 38 | + |
| 39 | + curl_setopt($ch, CURLOPT_SSLCERT, $data['config']['keyPath']); |
| 40 | + #curl_setopt($ch, CURLOPT_SSLCERTPASSWD, $data['config']['secretKey']); |
| 41 | + |
| 42 | + curl_setopt($ch, CURLOPT_FAILONERROR, true); |
| 43 | + curl_exec($ch); |
| 44 | + $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
| 45 | + curl_close($ch); |
| 46 | + |
| 47 | + return [ 'response' => $responses[$httpcode], 'code' => $httpcode]; |
| 48 | + } |
| 49 | +} |
0 commit comments