GithubHelp home page GithubHelp logo

clarence-pan / jpush-api-php-client Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jpush/jpush-api-php-client

0.0 2.0 0.0 604 KB

JPush's officially supported PHP client library for accessing JPush APIs. 极光推送官方支持的 PHP 版本服务器端 SDK。

Home Page: http://docs.jpush.cn

PHP 100.00%

jpush-api-php-client's Introduction

Build Status

JPush API client library for PHP

简要概述

快速安装

1.复制src/JPush到项目目录下

2.在需要使用JPush的源文件头部 引入 src/JPush/JPush.php 既可使用(注意确认引入的路径是否正确).

# 引入代码
require_once("../JPush/JPush.php");

PS: 在下载的中的example文件夹有简单示例代码, 开发者可以参考其中的样例快速了解该库的使用方法.

使用 Composer

如果你的项目使用composer管理依赖, 亦可以通过以下方式使用JPush PHP Library.

  1. composer.json 中添加 jpush依赖, 目前最新版本为 v3.3.9
{
    "require":{
        "jpush/jpush": "v3.4.2"
    }
}
  1. 执行 php composer.phar installphp 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;

版本更新

Release页面有详细的版本发布记录与下载。

jpush-api-php-client's People

Contributors

clarence-pan avatar javenfang avatar xiamengyu avatar xiezefan avatar zincal8 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.