|
@@ -20,11 +20,11 @@ discard block |
|
|
block discarded – undo |
|
20
|
20
|
$options = $this->getOptions(); |
|
21
|
21
|
if (isset($options['apns.proxy_host_url'])) { |
|
22
|
22
|
// Override CURL options to connect to a HTTP/1.1 to HTTP/2 proxy |
|
23
|
|
- $curl_options[CURLOPT_URL] = $options['apns.proxy_host_url'] . '/3/device/' . $this->getAddress(); |
|
|
23
|
+ $curl_options[CURLOPT_URL] = $options['apns.proxy_host_url'].'/3/device/'.$this->getAddress(); |
|
24
|
24
|
$curl_options[CURLOPT_PORT] = $options['apns.proxy_host_port'] ?? 443; |
|
25
|
25
|
// Use HTTP/1.1 instead of HTTP/2 |
|
26
|
26
|
$curl_options[CURLOPT_HTTP_VERSION] = CURL_HTTP_VERSION_1_1; |
|
27
|
|
- $this->logger->notice(sprintf('Using HTTP/1.1 CURL Proxy URL: "%s" and port "%s"', $curl_options[CURLOPT_URL], $curl_options[CURLOPT_URL])); |
|
|
27
|
+ $this->logger->notice(sprintf('Using HTTP/1.1 CURL Proxy URL: "%s" and port "%s"', $curl_options[CURLOPT_URL], $curl_options[CURLOPT_URL])); |
|
28
|
28
|
} |
|
29
|
29
|
else { |
|
30
|
30
|
$version_info = curl_version(); |
|
@@ -35,7 +35,7 @@ discard block |
|
|
block discarded – undo |
|
35
|
35
|
|
|
36
|
36
|
// Get the UID from the client certificate we use for authentication, this |
|
37
|
37
|
// is set to the bundle ID. |
|
38
|
|
- $options=$this->getOptions(); |
|
|
38
|
+ $options = $this->getOptions(); |
|
39
|
39
|
$cert_filename = $options['apns.certificate']; |
|
40
|
40
|
if (strlen($cert_filename) == 0) { |
|
41
|
41
|
throw new RuntimeException('apns.certificate option not set'); |
|
@@ -47,7 +47,7 @@ discard block |
|
|
block discarded – undo |
|
47
|
47
|
); |
|
48
|
48
|
} |
|
49
|
49
|
|
|
50
|
|
- $cert=openssl_x509_parse( $cert_file_contents ); |
|
|
50
|
+ $cert = openssl_x509_parse($cert_file_contents); |
|
51
|
51
|
if (false === $cert) { |
|
52
|
52
|
throw new RuntimeException('Error parsing APNS client certificate'); |
|
53
|
53
|
} |
|
@@ -72,42 +72,42 @@ discard block |
|
|
block discarded – undo |
|
72
|
72
|
$authProvider = AuthProvider\Certificate::create($authProviderOptions); |
|
73
|
73
|
|
|
74
|
74
|
// Create the push message |
|
75
|
|
- $alert=Alert::create(); |
|
|
75
|
+ $alert = Alert::create(); |
|
76
|
76
|
$alert->setBody($this->getText()); |
|
77
|
77
|
// Note: It is possible to specify a title and a subtitle: $alert->setTitle() && $alert->setSubtitle() |
|
78
|
78
|
// The tiqr service currently does not implement this. |
|
79
|
|
- $payload=Payload::create()->setAlert($alert); |
|
|
79
|
+ $payload = Payload::create()->setAlert($alert); |
|
80
|
80
|
$payload->setSound('default'); |
|
81
|
81
|
foreach ($this->getCustomProperties() as $name => $value) { |
|
82
|
82
|
$payload->setCustomValue($name, $value); |
|
83
|
83
|
} |
|
84
|
84
|
$this->logger->debug(sprintf('JSON Payload: %s', $payload->toJson())); |
|
85
|
|
- $notification=new Notification($payload, $this->getAddress()); |
|
|
85
|
+ $notification = new Notification($payload, $this->getAddress()); |
|
86
|
86
|
// Set expiration to 30 seconds from now, same as Message_APNS |
|
87
|
87
|
$now = new DateTime(); |
|
88
|
|
- $expirationInstant=$now->add(new DateInterval('PT30S')); |
|
|
88
|
+ $expirationInstant = $now->add(new DateInterval('PT30S')); |
|
89
|
89
|
$notification->setExpirationAt($expirationInstant); |
|
90
|
90
|
|
|
91
|
91
|
// Send the push message |
|
92
|
92
|
$client = new Client($authProvider, $options['apns.environment'] == 'production', $curl_options); |
|
93
|
93
|
$client->addNotification($notification); |
|
94
|
|
- $responses=$client->push(); |
|
95
|
|
- if ( sizeof($responses) != 1) { |
|
96
|
|
- $this->logger->warning(sprintf('Unexpected number responses. Expected 1, got %d', sizeof($responses)) ); |
|
|
94
|
+ $responses = $client->push(); |
|
|
95
|
+ if (sizeof($responses) != 1) { |
|
|
96
|
+ $this->logger->warning(sprintf('Unexpected number responses. Expected 1, got %d', sizeof($responses))); |
|
97
|
97
|
if (sizeof($responses) == 0) { |
|
98
|
98
|
$this->logger->warning('Could not determine whether the notification was sent'); |
|
99
|
99
|
return; |
|
100
|
100
|
} |
|
101
|
101
|
} |
|
102
|
102
|
/** @var \Pushok\Response $response */ |
|
103
|
|
- $response = reset($responses); // Get first response from the array |
|
104
|
|
- $deviceToken=$response->getDeviceToken() ?? ''; |
|
|
103
|
+ $response = reset($responses); // Get first response from the array |
|
|
104
|
+ $deviceToken = $response->getDeviceToken() ?? ''; |
|
105
|
105
|
// A canonical UUID that is the unique ID for the notification. E.g. 123e4567-e89b-12d3-a456-4266554400a0 |
|
106
|
|
- $apnsId=$response->getApnsId() ?? ''; |
|
|
106
|
+ $apnsId = $response->getApnsId() ?? ''; |
|
107
|
107
|
// Status code. E.g. 200 (Success), 410 (The device token is no longer active for the topic.) |
|
108
|
|
- $statusCode=$response->getStatusCode(); |
|
|
108
|
+ $statusCode = $response->getStatusCode(); |
|
109
|
109
|
$this->logger->info(sprintf('Got response with ApnsId "%s", status %s for deviceToken "%s"', $apnsId, $statusCode, $deviceToken)); |
|
110
|
|
- if ( strcasecmp($deviceToken, $this->getAddress()) ) { |
|
|
110
|
+ if (strcasecmp($deviceToken, $this->getAddress())) { |
|
111
|
111
|
$this->logger->warning(sprintf('Unexpected deviceToken in response. Expected: "%s"; got: "%s"', $this->getAddress(), $deviceToken)); |
|
112
|
112
|
} |
|
113
|
113
|
if ($statusCode == 200) { |
|
@@ -115,9 +115,9 @@ discard block |
|
|
block discarded – undo |
|
115
|
115
|
return; |
|
116
|
116
|
} |
|
117
|
117
|
|
|
118
|
|
- $reasonPhrase=$response->getReasonPhrase(); // E.g. The device token is no longer active for the topic. |
|
119
|
|
- $errorReason=$response->getErrorReason(); // E.g. Unregistered |
|
120
|
|
- $errorDescription=$response->getErrorDescription(); // E.g. The device token is inactive for the specified topic. |
|
|
118
|
+ $reasonPhrase = $response->getReasonPhrase(); // E.g. The device token is no longer active for the topic. |
|
|
119
|
+ $errorReason = $response->getErrorReason(); // E.g. Unregistered |
|
|
120
|
+ $errorDescription = $response->getErrorDescription(); // E.g. The device token is inactive for the specified topic. |
|
121
|
121
|
|
|
122
|
122
|
$this->logger->error(sprintf('Error sending APNS2 push notification. APNS ID: "%s"; deviceToken: "%s"; Error: "%s" "%s" "%s"', $apnsId, $deviceToken, $reasonPhrase, $errorReason, $errorDescription)); |
|
123
|
123
|
throw new RuntimeException( |