An open API service indexing awesome lists of open source software.

https://github.com/abler98/php-huawei-pushkit

HUAWEI Push Kit SDK for PHP
https://github.com/abler98/php-huawei-pushkit

hms hms-pushkit huawei php push

Last synced: 9 months ago
JSON representation

HUAWEI Push Kit SDK for PHP

Awesome Lists containing this project

README

          

# HUAWEI Push Kit SDK for PHP

[![Latest Stable Version](https://poser.pugx.org/megakit/php-huawei-pushkit/v)](//packagist.org/packages/megakit/php-huawei-pushkit)
[![Total Downloads](https://poser.pugx.org/megakit/php-huawei-pushkit/downloads)](//packagist.org/packages/megakit/php-huawei-pushkit)
[![Latest Unstable Version](https://poser.pugx.org/megakit/php-huawei-pushkit/v/unstable)](//packagist.org/packages/megakit/php-huawei-pushkit)
[![License](https://poser.pugx.org/megakit/php-huawei-pushkit/license)](//packagist.org/packages/megakit/php-huawei-pushkit)

Simple SDK for HUAWEI Push Kit server.

## Installation

Use [Composer] to install the package:

```shell script
$ composer require megakit/php-huawei-pushkit
```

## Quickstart example

```php
'',
'oauth_client_id' => '',
'oauth_client_secret' => '',
];

$tokens = [
'',
];

$huaweiConfig = HuaweiConfigBuilder::withDefaults()
->setAppId($config['app_id'])
->setOAuthCredentials($config['oauth_client_id'], $config['oauth_client_secret'])
->build();

$httpConfig = HttpConfigBuilder::withDefaults()->build();

$senderFactory = new SenderFactory();
$sender = $senderFactory->createSenderWithConfig($huaweiConfig, $httpConfig);

$notification = NotificationBuilder::make()
->setTitle('Hello')
->setBody('World')
->build();

$androidNotification = AndroidNotificationBuilder::make()
->setClickAction(
AndroidClickActionBuilder::make()
->setType(AndroidClickAction::TYPE_START_APP)
->build()
)
->build();

$androidConfig = AndroidConfigBuilder::make()
->setNotification($androidNotification)
->build();

$message = MessageBuilder::make()
->setNotification($notification)
->setAndroid($androidConfig)
->setData(['hello' => 'world'])
->build();

$destination = new TokenDestination($tokens);

try {
$sender->sendMessage($message, $destination);
echo 'Message sent successfully' . PHP_EOL;
} catch (HuaweiException $e) {
echo 'Error sending message: ' . $e->getMessage() . ' (' . $e->getCode() . ')' . PHP_EOL;
}
```

License
-------

All contents of this package are licensed under the [MIT license].

[Composer]: https://getcomposer.org
[MIT license]: LICENSE