【官方文檔】https://docs.jiguang.cn/jpush/server/3rd/php_sdk/
ionic 客戶端
step1:注冊賬號,并創(chuàng)建應(yīng)用
https://www.jiguang.cn/
step2:應(yīng)用添加插件
cordova plugin add jpush-phonegap-plugin --variable APP_KEY=******
step3:app.js 添加代碼
//啟動極光推送服務(wù)
window.plugins.jPushPlugin.init();
step4:設(shè)置別名,標簽懂从。
window.plugins.jPushPlugin.setAlias("12345678"); 任意地方均可。
php 后臺服務(wù)器端
step1:安裝插件
composer require jpush/jpush
vendor/jpush 有相關(guān)demo
step2:
功能實現(xiàn):
創(chuàng)建控制器:
public function actionPushonedriver(){
// 簡單推送示例
// 這只是使用樣例,不應(yīng)該直接用于實際生產(chǎn)環(huán)境中 !!
$rel = JpushFunction::sendJpushOneDriver();
return $rel;
}
創(chuàng)建model:
public function sendJpushOneDriver(){
$app_key = Yii::$app->params['jpush']['appKey'];
$master_secret = Yii::$app->params['jpush']['masterSecret'];
$client = new JPush($app_key, $master_secret);
$push_payload = $client->push()
->setPlatform(array('ios', 'android'));
// ->addAllAudience();
// ->setAudience('all')
// ->addAlias('alias')
try {
$push_payload->addAlias('12345678')
->androidNotification('分配給你新訂單了懈费,請注意派送', array(
'title' => '新訂單分配',
// 'builder_id' => 2,
'extras' => array(
'key' => 'neworderdelivery',
'jiguang'
),
))
->message('分配給你新訂單了羹饰,請注意派送', array(
'title' => '新訂單分配',
// 'builder_id' => 2,
'extras' => array(
'key' => 'neworderdelivery',
'jiguang'
),
));
$response = $push_payload->send();
print_r($response);
} catch (\JPush\Exceptions\APIConnectionException $e) {
// try something here
print $e;
} catch (\JPush\Exceptions\APIRequestException $e) {
// try something here
print $e;
}
}
方法實現(xiàn)