Yii 1.1 프레임 워 크 는 PHP 극광 푸 시 메시지 알림 기능 을 실현 합 니 다.
2.공식 demo 예 를 보완 하고 수정 합 니 다.저 는 demo 를 복사 하여 Notify Push.php 로 바 꾸 었 습 니 다.다음 코드 는 다음 과 같 습 니 다.
<?php
require dirname(__FILE__) . '/jpush-api-php-client/autoload.php';
use JPush\Client as JPush;
class NotifyPush {
static function pushAlias($alias,$ticket=' ',$alert){
$appKey=Yii::app()->params['push']['AppKey'];
$appMasterSecret=Yii::app()->params['push']['AppMasterSecret'];
$production_mode=Yii::app()->params['push']['production_mode'];
$client = new JPush($appKey, $appMasterSecret);
//
// , !!
try {
$response = $client->push()
->setPlatform(array('ios', 'android'))
// , audience addAlias、addTag、addTagAnd addRegistrationId
// , , , audience
// , addTagAnd ,
->addAlias($alias)
->setNotificationAlert($alert)
->iosNotification($ticket, array(
'sound' => 'sound.caf',
// 'badge' => '+1',
// 'content-available' => true,
// 'mutable-content' => true,
'category' => 'jiguang',
'extras' => array(
'key' => 'value',
'jiguang'
),
))
->androidNotification($ticket, array(
'title' => $alert,
// 'build_id' => 2,
'extras' => array(
'key' => 'value',
'jiguang'
),
))
->message($alert, array(
'title' => $alert,
// 'content_type' => 'text',
'extras' => array(
'key' => 'value',
'jiguang'
),
))
->options(array(
// sendno: , API ,
// API , API
// 100
// 'sendno' => 100,
// time_to_live: ( ),
// , , 。
// 86400 (1 ), 10 。 0 ,
// 1
// 'time_to_live' => 1,
// apns_production: APNs ,
// True ,False ;
'apns_production' => $production_mode,
// big_push_duration: ( ), , , ,
// n , 。 1400.
// 1
// 'big_push_duration' => 1
))
->send();
print_r($response);
} catch (\JPush\Exceptions\APIConnectionException $e) {
// try something here
print $e;
} catch (\JPush\Exceptions\APIRequestException $e) {
// try something here
print $e;
}
}
static function pushAll($ticket=' ',$alert){
$appKey=Yii::app()->params['push']['AppKey'];
$appMasterSecret=Yii::app()->params['push']['AppMasterSecret'];
$production_mode=Yii::app()->params['push']['production_mode'];
$client = new JPush($appKey, $appMasterSecret);
//
// , !!
try {
$response = $client->push()
->setPlatform(array('ios', 'android'))
->setAudience('all')
// , audience addAlias、addTag、addTagAnd addRegistrationId
// , , , audience
// , addTagAnd ,
->setNotificationAlert($alert)
->iosNotification($ticket, array(
'sound' => 'sound.caf',
// 'badge' => '+1',
// 'content-available' => true,
// 'mutable-content' => true,
'category' => 'jiguang',
'extras' => array(
'key' => 'value',
'jiguang'
),
))
->androidNotification($ticket, array(
'title' => $alert,
// 'build_id' => 2,
'extras' => array(
'key' => 'value',
'jiguang'
),
))
->message($alert, array(
'title' => $alert,
// 'content_type' => 'text',
'extras' => array(
'key' => 'value',
'jiguang'
),
))
->options(array(
// sendno: , API ,
// API , API
// 100
// 'sendno' => 100,
// time_to_live: ( ),
// , , 。
// 86400 (1 ), 10 。 0 ,
// 1
// 'time_to_live' => 1,
// apns_production: APNs ,
// True ,False ;
'apns_production' => $production_mode,
// big_push_duration: ( ), , , ,
// n , 。 1400.
// 1
// 'big_push_duration' => 1
))
->send();
print_r($response);
} catch (\JPush\Exceptions\APIConnectionException $e) {
// try something here
print $e;
} catch (\JPush\Exceptions\APIRequestException $e) {
// try something here
print $e;
}
}
}
3.Notify Push.php 의 방법 을 호출 하여 푸 시 를 실현 합 니 다.다음 코드:
class CronNotifyPushCommand extends CConsoleCommand{
public $keys=array();
public function init(){
parent::init();
}
public function actionIndex(){
echo 'start CronNotifyPushCommand '.chr(10);
if(!Yii::app()->params['push']['push_status']){
echo 'push status disabled';die();
}
$rkey='message_notify_list';
$waitTotals=Fredis::model()->redis->lsize($rkey);
echo 'wait totals:'.$waitTotals.chr(10);
$waitResult=true;
$i=0;
while($waitResult) {$i++;
echo $i.'/'.$waitTotals.' wait to do'.chr(10);
$waitResult=Fredis::model()->redis->rpop($rkey);
if(!$waitResult) {
continue;
}
$db_data=unserialize($waitResult);var_dump($db_data);
$message_content=$db_data['message_content'];
$uid=$db_data['uid'];
$alias=$uid;
if($uid==0){
NotifyPush::pushAll($message_content, $message_content);
}else {
NotifyPush::pushAlias($alias, $message_content, $message_content);
}
}
echo 'end'.chr(10);
}
}
총결산위 에서 말씀 드 린 것 은 편집장 님 께 서 소개 해 주신 Yii 1.1 프레임 워 크 입 니 다.PHP 극광 푸 시 메시지 알림 을 실현 하고 여러분 께 도움 이 되 기 를 바 랍 니 다.궁금 한 점 이 있 으 시 면 메 시 지 를 남 겨 주세요.편집장 님 께 서 바로 답 해 드 리 겠 습 니 다.여기 서도 저희 사이트 에 대한 여러분 의 지지 에 감 사 드 립 니 다!
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Laravel - 변환된 유효성 검사 규칙으로 API 요청 제공동적 콘텐츠를 위해 API를 통해 Laravel CMS에 연결하는 모바일 앱(또는 웹사이트) 구축을 고려하십시오. 이제 앱은 CMS에서 번역된 콘텐츠를 받을 것으로 예상되는 다국어 앱이 될 수 있습니다. 일반적으로 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.