From 0b6e1ad60d852fd1965d9f9442a0ccb432377ac1 Mon Sep 17 00:00:00 2001 From: sunaoka Date: Thu, 14 Oct 2021 17:13:06 +0900 Subject: [PATCH 1/4] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f5cbb78..2ba7da9 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ $payload = [ $options = new APNs\Token\Option(); $options->payload = $payload; -$options->authKey = 'file:///path/to/key.p8'; +$options->authKey = '/path/to/key.p8'; $options->keyId = 'ABCDE12345'; $options->teamId = 'ABCDE12345'; $options->topic = 'com.example.app'; From ed9524bcf64253238c29b9fe0c019a17f649e27f Mon Sep 17 00:00:00 2001 From: sunaoka Date: Thu, 14 Oct 2021 18:38:49 +0900 Subject: [PATCH 2/4] Add example --- .gitattributes | 1 + example/apns-certificate.php | 33 ++++++++++++++++++++++++++++++ example/apns-token.php | 34 +++++++++++++++++++++++++++++++ example/fcm-http-v1.php | 32 +++++++++++++++++++++++++++++ example/fcm-legacy-json.php | 29 ++++++++++++++++++++++++++ example/fcm-legacy-plain-text.php | 27 ++++++++++++++++++++++++ 6 files changed, 156 insertions(+) create mode 100644 example/apns-certificate.php create mode 100644 example/apns-token.php create mode 100644 example/fcm-http-v1.php create mode 100644 example/fcm-legacy-json.php create mode 100644 example/fcm-legacy-plain-text.php diff --git a/.gitattributes b/.gitattributes index 58355a1..efbaeee 100644 --- a/.gitattributes +++ b/.gitattributes @@ -2,6 +2,7 @@ /.github export-ignore /.gitignore export-ignore /CHANGELOG.md export-ignore +/example export-ignore /phpstan.neon export-ignore /phpunit.xml export-ignore /tests export-ignore diff --git a/example/apns-certificate.php b/example/apns-certificate.php new file mode 100644 index 0000000..f4df5ac --- /dev/null +++ b/example/apns-certificate.php @@ -0,0 +1,33 @@ + [ + 'alert' => [ + 'title' => 'Game Request', + 'body' => 'Bob wants to play poker', + ], + ], +]; + +$options = new APNs\Certificate\Option(); +$options->payload = $payload; +$options->certificate = '/path/to/cert.pem'; +$options->password = 'password of certificate'; +$options->topic = 'com.example.app'; + +$driver = new APNs\Certificate($options); + +$pusher = new Pusher(); +$feedback = $pusher->to($deviceToken)->send($driver); + +$result = $feedback->isSuccess($deviceToken); +if (! $result) { + echo $feedback->failure($deviceToken); +} diff --git a/example/apns-token.php b/example/apns-token.php new file mode 100644 index 0000000..7b3c0f5 --- /dev/null +++ b/example/apns-token.php @@ -0,0 +1,34 @@ + [ + 'alert' => [ + 'title' => 'Game Request', + 'body' => 'Bob wants to play poker', + ], + ], +]; + +$options = new APNs\Token\Option(); +$options->payload = $payload; +$options->authKey = '/path/to/key.p8'; +$options->keyId = 'ABCDE12345'; +$options->teamId = 'ABCDE12345'; +$options->topic = 'com.example.app'; + +$driver = new APNs\Token($options); + +$pusher = new Pusher(); +$feedback = $pusher->to($deviceToken)->send($driver); + +$result = $feedback->isSuccess($deviceToken); +if (! $result) { + echo $feedback->failure($deviceToken); +} diff --git a/example/fcm-http-v1.php b/example/fcm-http-v1.php new file mode 100644 index 0000000..3b1a5c1 --- /dev/null +++ b/example/fcm-http-v1.php @@ -0,0 +1,32 @@ + [ + 'notification' => [ + 'title' => 'Portugal vs. Denmark', + 'body' => 'great match!', + ], + ], +]; + +$options = new FCM\V1\Option(); +$options->payload = $payload; +$options->credentials = 'serviceAccountKey.json'; +$options->projectId = 'project-id-abc12'; + +$driver = new FCM\V1($options); + +$pusher = new Pusher(); +$feedback = $pusher->to($deviceToken)->send($driver); + +$result = $feedback->isSuccess($deviceToken); +if (! $result) { + echo $feedback->failure($deviceToken); +} diff --git a/example/fcm-legacy-json.php b/example/fcm-legacy-json.php new file mode 100644 index 0000000..c5f6a28 --- /dev/null +++ b/example/fcm-legacy-json.php @@ -0,0 +1,29 @@ + [ + 'title' => 'Portugal vs. Denmark', + 'body' => 'great match!', + ], +]; + +$options = new FCM\Json\Option(); +$options->payload = $payload; +$options->apiKey = 'server-key'; + +$driver = new FCM\Json($options); + +$pusher = new Pusher(); +$feedback = $pusher->to($deviceToken)->send($driver); + +$result = $feedback->isSuccess($deviceToken); +if (! $result) { + echo $feedback->failure($deviceToken); +} diff --git a/example/fcm-legacy-plain-text.php b/example/fcm-legacy-plain-text.php new file mode 100644 index 0000000..f08604a --- /dev/null +++ b/example/fcm-legacy-plain-text.php @@ -0,0 +1,27 @@ + 'Portugal vs. Denmark', + 'data.body' => 'great match!', +]; + +$options = new FCM\PlainText\Option(); +$options->payload = $payload; +$options->apiKey = 'server-key'; + +$driver = new FCM\PlainText($options); + +$pusher = new Pusher(); +$feedback = $pusher->to($deviceToken)->send($driver); + +$result = $feedback->isSuccess($deviceToken); +if (! $result) { + echo $feedback->failure($deviceToken); +} From 9700fb39ac6d7c4160e844ddb4cb1265165ef9dc Mon Sep 17 00:00:00 2001 From: sunaoka Date: Thu, 14 Oct 2021 18:47:29 +0900 Subject: [PATCH 3/4] Update README.md --- README.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/README.md b/README.md index 2ba7da9..a376523 100644 --- a/README.md +++ b/README.md @@ -137,6 +137,24 @@ if ($result) { } ``` +## HTTP Request Option + +You can specify [Guzzle Request Options] as a driver option. + +```php +$options = new APNs\Token\Option(); +$options->httpOptions = [ + 'connect_timeout' => 3.14 + 'timeout' => 3.14, + 'debug' => true, +]; +``` + +## More examples + +More examples can be found in the [examples](example) directory. + + [Token Based]: https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/establishing_a_token-based_connection_to_apns [Certificate Based]: https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/establishing_a_certificate-based_connection_to_apns [Binary Provider]: https://developer.apple.com/library/archive/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/BinaryProviderAPI.html @@ -144,3 +162,4 @@ if ($result) { [Legacy JSON]: https://firebase.google.com/docs/cloud-messaging/http-server-ref#downstream-http-messages-json [Legacy Plain Text]: https://firebase.google.com/docs/cloud-messaging/http-server-ref#downstream-http-messages-plain-text [XMPP]: https://firebase.google.com/docs/cloud-messaging/xmpp-server-ref +[Guzzle Request Options]: https://docs.guzzlephp.org/en/stable/request-options.html From 63beea14f59297d5497a1b5c8149a2db5b3cf6a3 Mon Sep 17 00:00:00 2001 From: sunaoka Date: Thu, 14 Oct 2021 18:52:28 +0900 Subject: [PATCH 4/4] Update CHANGELOG.md --- CHANGELOG.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8237f88..86b3abf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,12 @@ # Release Notes -## [Unreleased](https://github.com/sunaoka/push-notifications-php/compare/1.0.2...develop) +## [Unreleased](https://github.com/sunaoka/push-notifications-php/compare/1.0.3...develop) + +## [v1.0.3 (2021-10-14)](https://github.com/sunaoka/push-notifications-php/compare/1.0.2...1.0.3) + +### Added + +- Added examples ## [v1.0.2 (2021-10-13)](https://github.com/sunaoka/push-notifications-php/compare/1.0.1...1.0.2)