JPush's officially supported PHP client library for accessing JPush APIs. 极光推送官方支持的 PHP 版本服务器端 SDK。
JPush's officially supported PHP client library for accessing JPush APIs. 极光推送官方支持的 PHP 版本服务器端 SDK。
这是 JPush REST API 的 PHP 版本封装开发包,是由极光推送官方提供的,一般支持最新的 API 功能。
对应的 REST API 文档: https://docs.jiguang.cn/jpush/server/push/server_overview/
支持的 PHP 版本: 5.3.3 ~ 5.6.x, 7.x
若需要兼容 PHP 5.3.3 以下版本,可以使用 v3 分支的代码。 因为运行 Composer 需要 PHP 5.3.2+ 以上版本,所以其不提供 Composer 支持, 也可以点击链接下载 v3.4.x 版本源码。
$ php composer.phar install 或 $ composer install 进行安装。直接下载源代码也是一种安装 SDK 的方法,不过因为有版本更新的维护问题,所以这种安装方式十分不推荐,但由于种种原因导致无法使用 Composer,所以我们也提供了这种情况下的备选方案。
require 'path_to_sdk/autoload.php';use JPush\Client as JPush;
...
...
$client = new JPush($app_key, $master_secret);
...OR
$client = new \JPush\Client($app_key, $master_secret);$client->push()
->setPlatform('all')
->addAllAudience()
->setNotificationAlert('Hello, JPush')
->send();$pusher = $client->push();
$pusher->setPlatform('all');
$pusher->addAllAudience();
$pusher->setNotificationAlert('Hello, JPush');
try {
$pusher->send();
} catch (\JPush\Exceptions\JPushException $e) {
// try something else here
print $e;
}注意: 这只是使用样例, 不应该直接用于实际环境中!!
在下载的中的 examples 文件夹有简单示例代码, 开发者可以参考其中的样例快速了解该库的使用方法。
简单使用方法
先填写对应的appKey和masterSecret,可以额外设定Registration_id。
若要运行 push_example.php 中的示例代码:
# 假定当前目录为 JPush 源码所在的根目录
$ php examples/push_example.php同时也可编辑相关的示例文件,更改参数查看执行效果
# 编辑 tests/bootstrap.php 文件,填入必须的变量值
# OR 设置相应的环境变量
# 运行全部测试用例
$ composer tests
# 运行某一具体测试用例
$ composer tests/JPush/xxTest.phpBug reports and pull requests are welcome on GitHub at https://github.com/jpush/jpush-api-php-client.
The library is available as open source under the terms of the MIT License.
No open issues yet, or sync has not completed.