極光推送Jpush

這幾天研究極光推送,發現挺好玩的
一個jpush極光推送遠程調用api簡單的實例,php服務器,代碼貼上
文檔參考: http://docs.jpush.cn/display/dev/Push+API+v2

send.php
<?php
include('jpush.php');
$n_title   =  '極光推送title';
$n_content =  '極光推送message';   
$appkeys = 'xxxxx';
$masterSecret = 'xxxxx';
$sendno = 1234;//發送編號 最大支持32位正整數,由開發者自己維護,用於開發者自己標識一次發送請求。
$receiver_value = '';       
$platform = 'android,ios' ;
$msg_content = json_encode(array('n_builder_id'=>0, 'n_title'=>$n_title, 'n_content'=>$n_content));       
$obj = new jpush($masterSecret,$appkeys);             
$res = $obj->send($sendno, 4, $receiver_value, 1, $msg_content, $platform);       
print_r($res);
exit();   
?>


jpush.php
<?php
class jpush {
    private $_masterSecret = '';
    private $_appkeys = '';
   
   
    function __construct($masterSecret = '',$appkeys = '') {
        $this->_masterSecret = $masterSecret;
        $this->_appkeys = $appkeys;
    }
   
    function request_post($url = '', $param = '') {
        if (empty($url) || empty($param)) {
            return false;
        }
       
        $postUrl = $url;
        $curlPost = $param;
        $ch = curl_init();//初始化curl
        curl_setopt($ch, CURLOPT_URL,$postUrl);//抓取指定網頁
        curl_setopt($ch, CURLOPT_HEADER, 0);//設置header
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//要求結果爲字符串且輸出到屏幕上
        curl_setopt($ch, CURLOPT_POST, 1);//post提交方式
        curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
        $data = curl_exec($ch);//運行curl
        curl_close($ch);
       
        return $data;
    }
  
       // 發送
       // @param int $sendno 發送編號。由開發者自己維護,標識一次發送請求
       // @param int $receiver_type 接收者類型。
       // 1、指定的 IMEI。此時必須指定 appKeys。
       // 2、指定的 tag。 
       // 3、指定的 alias。
       // 4、 對指定 appkey 的所有用戶推送消息。
       // @param string $receiver_value 發送範圍值,與 receiver_type相對應。
       // 1、IMEI只支持一個
       // 2、tag 支持多個,使用 "," 間隔。
       // 3、alias 支持多個,使用 "," 間隔。
       // 4、不需要填
      
發佈了24 篇原創文章 · 獲贊 11 · 訪問量 7萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章