JPush API client library for PHP
来源:互联网 发布:秃子套件淘宝怎么找 编辑:程序博客网 时间:2024/06/06 06:09
JPush API client library for PHP
简要概述
- 本API提供简单的接口去调用JPush Push API
- 本API提供简单的接口去调用JPush Report API
- 本API提供简单的接口去调用JPush Device API
- 本API提供简单的接口去调用JPush Schedule API
快速安装
1.复制src/JPush
到项目目录下
2.在需要使用JPush的源文件头部 引入 src/JPush/JPush.php
既可使用(注意确认引入的路径是否正确).
# 引入代码require_once("../JPush/JPush.php");
PS: 在下载的中的example文件夹有简单示例代码, 开发者可以参考其中的样例快速了解该库的使用方法.
使用 Composer
如果你的项目使用composer管理依赖, 亦可以通过以下方式使用JPush PHP Library.
- 在
composer.json
中添加 jpush依赖, 目前最新版本为 v3.3.9
{ "require":{ "jpush/jpush": "v3.4.2" }}
- 执行
php composer.phar install
或php composer.phar update
进行安装
快速使用
代码示例
example文件夹有简单示例代码, 开发者可参考以快速使用该库
examples/├── push_example.php Push API使用示例├── device_example.php Device API使用示例├── report_example.php Report API使用示例└── schedule_example.php Schedule API使用示例
初始化
$client = new JPush($app_key, $master_secret);
简单推送
$result = $client->push() ->setPlatform('all') ->addAllAudience() ->setNotificationAlert('Hi, JPush') ->send();echo 'Result=' . json_encode($result) . $br;
完整的推送示例
包含指定Platform,指定Alias,Tag,指定iOS,Android notification,指定Message等
$result = $client->push() ->setPlatform('ios', 'android') ->addAlias('alias1') ->addTag(array('tag1', 'tag2')) ->setNotificationAlert('Hi, JPush') ->addAndroidNotification('Hi, android notification', 'notification title', 1, array("key1"=>"value1", "key2"=>"value2")) ->addIosNotification("Hi, iOS notification", 'iOS sound', '+1', true, 'iOS category', array("key1"=>"value1", "key2"=>"value2")) ->setMessage("msg content", 'msg title', 'type', array("key1"=>"value1", "key2"=>"value2")) ->setOptions(100000, 3600, null, false) ->send();echo 'Result=' . json_encode($result) . $br;
发送短信推送示例
推送未送达的情况下进行短信送达, 该功能需预付短信费用, 并调用Device API绑定设备与手机号
$result = $client->push() ->setPlatform('all') ->addTag('tag1') ->setNotificationAlert("Hi, JPush SMS") ->setSmsMessage('Hi, JPush SMS', 60) ->send();echo 'Result=' . json_encode($result) . $br;
定时推送示例
$payload = $client->push() ->setPlatform("all") ->addAllAudience() ->setNotificationAlert("Hi, 这是一条定时发送的消息") ->build();// 创建一个2016-12-22 13:45:00触发的定时任务$response = $client->schedule()->createSingleSchedule("每天14点发送的定时任务", $payload, array("time"=>"2016-12-22 13:45:00"));echo 'Result=' . json_encode($response) . $br;
实例代码
use JPush\Client as JPush;/** * @消息推送(最新版本) */function push5($uid,$content,$alias,$live,$type){ $jg = M('System')->where(array('id'=>1))->find(); $app_key = $jg['jg_appkey'];//app_key $master_secret = $jg['jg_secret'];//master_secre $client = new JPush($app_key,$master_secret); try { $response = $client->push() ->setPlatform(array('ios', 'android')) ->addAllAudience() ->iosNotification($content,array( 'sound'=>'default', 'badge' => 2, 'content-available' => true, 'category' => 'jiguang', 'extras' => ['user_id'=>$uid,'alias'=>$alias,'live'=>$live,'type'=>$type] ) ) ->androidNotification($content,array( 'title' => $content, 'builder_id' => 1, 'extras' => array( "user_id"=>$uid,"alias"=>$alias,'live'=>$live,'type'=>$type), ) ) ->options([ 'sendno' => 100, 'time_to_live' => 86400, 'apns_production' => true, 'big_push_duration' => 0 ]) ->send(); return 1; }catch (APIRequestException $e) { return 2; } catch (APIConnectionException $e) { return 3; }}
版本更新
Release页面有详细的版本发布记录与下载。
相关参数说明文
阅读全文
0 0
- JPush API client library for PHP
- Java Client Library Method Summary API中文版
- Google APIs Client Library for Java V3
- Java Client API for RabbitMQ
- 使用jpush-client-sdk实现极光jpush
- JPush:引用library/.aar文件的JPush
- PHP Client for Mysql Binlog
- XML-RPC Library for PHP
- HTML Purifier library for PHP
- Client API - Best Practices for performance tuning
- NuGet安装,通过NuGet安装Couchbase Client Library for .NET
- php实现jPush
- PHP中的CURL函数库(Client URL Library Function)
- PHP中的CURL函数库(Client URL Library Function)
- PHP中的CURL函数库(Client URL Library Function)
- php之curl(Client URL Library)简介
- incorrect MySQL client library version! This gem was compiled for 6.0.0 but the client library is 5.
- 极光推送Jpush(v3)服务端PHP版本集成(V3版本只调用推送API)【转】
- 不要过度依赖JQuery(一)
- sql在mybatais中的强转
- java两种核心机制
- 【Solidity】7. 部件
- Android 8.0 功能和 API
- JPush API client library for PHP
- 网络协议(1)
- WebApp 中Meta标签属性及含义
- 使用java程序修改本地文件部分内容
- 数人云架构师:微服务体系中的K8S&Mesos调度与服务发现
- JAVA配置环境变量的作用
- MongoDb 中 serverStatus was very slow 的原因分析
- EditText与软键盘
- 【前端知识点】设计模式(design pattern)的简介