改寫百度雲推送SDK,PHP PEAR 包:Services_Baidu_Push


iPhone使用apple push很方便,而Android很多廠商刪除了google push,而且google在大陸連不上,所以要用別的辦法。

Android常見的推送服務商有:極光推送(https://www.jpush.cn/)、百度雲推送。

app加入推送的lib,會有一個常駐后台進程,通過推送服務商推送消息,無需啟動app。

 

百度雲推送官方文檔:http://developer.baidu.com/cloud/push

對於這種第三方庫,PHP官方稱之為PEAR,需要按照PEAR標准開發(標准URI)。

PEAR的優勢:一鍵安裝到php/lib/php目錄,require即可使用,很方便。

百度推送的官方sdk不符合PEAR標准,使用不便,不想為百度重寫,所以我改寫了一下(sdk中帶的很多垃圾沒去改寫),安裝步驟如下:

pear channel-discover sinkcup.github.io/pear
pear install sinkcup/Services_Baidu_Push

使用步驟:

1、注冊登錄百度開發者后台,獲得api key和secret key,在app里添加lib。

2、demo(參考https://github.com/sinkcup/Services_Baidu_Push/blob/master/tests/Services/Baidu/PushTest.php

<?php
require_once 'Services/Baidu/Push.php';

$apiKey = 'asdf';
$secretKey = 'qwer';
$c = new Services_Baidu_Push($apiKey, $secretKey);
$msg = array(
    "description"=> "testSimplePushToAndroid群發",
    "notification_basic_style"=>7,
);
$r = $c->simplePushToAndroid($msg);
var_dump($r);
exit;
?>

輸出:

bool(true)

我的PEAR 頻道:http://sinkcup.github.io/pear/

項目源代碼:https://github.com/sinkcup/Services_Baidu_Push


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM