nizerin / jpush-mini
JPush API PHP 客户端
1.0.0
2019-09-29 09:42 UTC
Requires
- php: >=5.4
- ext-curl: *
Requires (Dev)
This package is auto-updated.
Last update: 2024-09-08 19:56:46 UTC
README
这是 JPush REST API 的 PHP 版本封装开发包,由极光推送官方提供,通常支持最新的 API 功能。
对应的 REST API 文档: https://docs.jiguang.cn/jpush/server/push/server_overview/
安装
使用 Composer 安装
composer require nizerin/jpush-mini
使用方法
初始化
use JPush\Client as JPush; ... ... $client = new JPush($app_key, $master_secret); ...
或者
$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 文件夹中有简单示例代码,开发者可以参考其中的样例快速了解库的使用方法。
**注:所下载的样例代码不能直接使用,需要在
examples/config.php
文件中填入相关必要参数,或者设置相关环境变量,不进行此操作则示例将无法运行。**另外为保护开发者隐私,examples/config.php 文件不在版本控制中,需要使用如下命令手动复制:
$ cp examples/config.php.example examples/config.php
简单使用方法
若要运行 push_example.php 中的示例代码:
# 假定当前目录为 JPush 源码所在的根目录
$ php examples/push_example.php
同时也可编辑相关的示例文件,更改参数查看执行效果
测试
# 编辑 tests/bootstrap.php 文件,填入必须的变量值 # OR 设置相应的环境变量 # 运行全部测试用例 $ composer tests # 运行某一具体测试用例 $ composer tests/JPush/xxTest.php
贡献
欢迎在 GitHub 上提交错误报告和 pull request:https://github.com/jpush/jpush-api-php-client.
许可证
该库作为开源软件,受 MIT 许可证 的条款约束。