Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sergiomadness/php-push-notification-server
Push-notification server
https://github.com/sergiomadness/php-push-notification-server
apns-http2 apns2 docker gcm push-notifications service
Last synced: 6 days ago
JSON representation
Push-notification server
- Host: GitHub
- URL: https://github.com/sergiomadness/php-push-notification-server
- Owner: SergioMadness
- Created: 2017-08-03T09:28:38.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-10-02T14:37:34.000Z (about 7 years ago)
- Last Synced: 2024-10-29T14:19:38.855Z (about 2 months ago)
- Topics: apns-http2, apns2, docker, gcm, push-notifications, service
- Language: PHP
- Size: 29.3 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# Push sender
# Connection through TCP/IP sockets
## config.json
```javascript
{
"ip": "",
"port": 10000,
"jwtToken": "kjdsfhjk849678946",
"apns": {
"all": {
"key": "certificates/AuthKey_FHH747JJD.p8",
"keyPassword": "",
"keyId": "FHH747JJD",
"teamId": "SERTYUJJ",
"production": false
}
},
"gcm": {
"all": {
"apiKey": "AIzJdurHh377f7O95u-OAS_KKdfhh57878L4QcQ",
"retries": 0
},
"byPattern": {
"apiKey": "AJSGHdshjd8Hhhjf7O95u-OAS_KKdfhh57878L4QcQ",
"retries": 10
}
},
"map": {
"apns": {
"*": "corp"
},
"gcm": {
"*": "all",
"*pattern*": "byPattern"
}
}
}
```## message
```php
\JWT::encode([
'tokens' => [
'dasasd8962ghgre'
],
'bundleId' => 'ru.test.baundle',
'message' => 'Service is ready',
'title' => 'Hello, guys!',
'sound' => null,
'extraParams' => [
'acme' => ''
],
], $this->getJwtKey());
```## response
```javascript
[
{
"token":"dasasd8962ghgre",
"statusCode":400,
"message":"DeviceTokenNotForTopic\nThe device token does not match the specified topic"
}
]
```## Example
```bash
sudo docker run -d -i --name pusher -p 10000:10000 -v /home/www-docker/builds/build-pusher-1/certificates:/usr/src/pusher/certificates -v /home/www-docker/builds/build-pusher-1/config.json:/usr/src/pusher/config.json professionalweb/push-notification-server
``````php
/* Create TCP/IP socket. */
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($socket === false) {
$m = "Can't create socket through socket_create(): couse: " . socket_strerror(socket_last_error());
\Log::error($m);
throw new \Exception($m);
}$result = socket_connect($socket, $this->getPushServiceIp(), $this->getPushServicePort());
if ($result === false) {
$m = "Can't execute socket_connect().\nCause: ($result) " . socket_strerror(socket_last_error($socket)) . "\n";
\Log::error($m);
throw new \Exception($m);
}$message = \JWT::encode([
'platform' => 'android',
'tokens' => ['dasdw534535'],
'bundleId' => 'ru.bundle.name',
'message' => 'Have a nice day!',
'title' => 'Hello',
'sound' => '',
'extraParams' => [
'acme' => 'Some param'
],
], '')
socket_write($socket, $message, strlen($message));
$message = "\n";
socket_write($socket, $message, strlen($message));$response = socket_read($socket, 2048);
socket_close($socket);
```