push推送Api接⼝
使⽤个推的服务:
controoler:
<?php
/**
*@namePushController
*@authorpangee
*@desc推送服务接⼝
*/
classPushControllerextendsYaf_Controller_Abstract{
publicfunctionsingleAction(){
if(!$this->_isAdmin()){
if(!$cid){
echojson_encode(array("errno"=>-7001,"errmsg"=>"仅管理员可以进⾏此操作"));
returnFALSE;
}
}
$cid=$this->getRequest()->getQuery("cid","");
$msg=$this->getRequest()->getQuery("msg","");
if(!$cid||!$msg){
echojson_encode(array("errno"=>-7002,"errmsg"=>"请输⼊推送⽤户的设备ID与要推送的内容"));
returnFALSE;
}
//调⽤Model
$model=newPushModel();
if($model->single($cid,$msg)){
echojson_encode(array(
"errno"=>0,
"errmsg"=>"",
));
}el{
echojson_encode(array(
"errno"=>$model->errno,
"errmsg"=>$model->errmsg,
));
}
returnTRUE;
}
publicfunctiontoallAction(){
if(!$this->_isAdmin()){
if(!$cid){
echojson_encode(array("errno"=>-7001,"errmsg"=>"仅管理员可以进⾏此操作"));
returnFALSE;
}
}
$msg=$this->getRequest()->getQuery("msg","");
if(!$msg){
echojson_encode(array("errno"=>-7004,"errmsg"=>"请输⼊要推送的内容"));
returnFALSE;
}
//调⽤Model
$model=newPushModel();
if($model->toAll($msg)){
echojson_encode(array(
"errno"=>0,
"errmsg"=>"",
));
}el{
echojson_encode(array(
"errno"=>$model->errno,
"errmsg"=>$model->errmsg,
));
}
returnTRUE;
}
privatefunction_isAdmin(){
returntrue;
}
}
model:
<?php
/**
*@namePushModel
*@desc推送服务接⼝
*@authorpangee
*/
$pushLibPath=dirname(__FILE__).'/../library/ThirdParty/Getui/';
require_once($pushLibPath.'');
require_once($pushLibPath.'igetui/');
require_once($pushLibPath.'igetui/');
require_once($pushLibPath.'igetui/template/');
require_once($pushLibPath.'');
require_once($pushLibPath.'igetui/utils/');
define('APPKEY','SdPeZMB7ut5TtWhnSYazi2');
define('APPID','bc0toEga7l599DIkgbI4g5');
define('MASTERSECRET','N8yAUQwbzN8dwulr2pzS98');
define('HOST','/');
classPushModel{
public$errno=0;
public$errmsg="";
publicfunction__construct(){
}
publicfunctionsingle($cid,$msg="测试内容dd"){
$igt=newIGeTui(HOST,APPKEY,MASTERSECRET);
$template=$this->_IGtTransmissionTemplateDemo($msg);
$message=newIGtSingleMessage();
$message->t_isOffline(true);//是否离线
$message->t_offlineExpireTime(3600*12*1000);//离线时间
$message->t_data($template);//设置推送消息类型
$message->t_PushNetWorkType(0);//设置是否根据WIFI推送消息,1为wifi推送,0为不限制推送
//接收⽅
$target=newIGtTarget();
$target->t_appId(APPID);
$target->t_clientId($cid);
//$target->t_alias(Alias);
try{
$rep=$igt->pushMessageToSingle($message,$target);
}catch(RequestException$e){
$requstId=$e->getRequestId();
$rep=$igt->pushMessageToSingle($message,$target,$requstId);
$this->errno=-7003;
$this->errmsg=$rep['result'];
returnfal;
}
returntrue;
}
functiontoAll($msg){
$igt=newIGeTui(HOST,APPKEY,MASTERSECRET);
$template=$this->_IGtTransmissionTemplateDemo($msg);
$message=newIGtAppMessage();
$message->t_isOffline(true);
//$message->t_offlineExpireTime(10*60*1000);//离线时间单位为毫秒,例,两个⼩时离线为3600*1000*2
$message->t_data($template);
$appIdList=array(APPID);
$phoneTypeList=array('ANDROID');
//$provinceList=array('浙江','北京','上海');
//$age=array("0000","0010");
$cdt=newAppConditions();
$cdt->addCondition(AppConditions::PHONE_TYPE,$phoneTypeList);
//$cdt->addCondition(AppConditions::REGION,$provinceList);
//$cdt->addCondition(AppConditions::TAG,$tagList);
//$cdt->addCondition("age",$age);
$message->t_appIdList($appIdList);
$message->condition=$cdt;
$igt->pushMessageToApp($message);
returntrue;
}
privatefunction_IGtTransmissionTemplateDemo($msg="测试内容dddd"){
$template=newIGtTransmissionTemplate();
$template->t_appId(APPID);//应⽤appid
$template->t_appkey(APPKEY);//应⽤appkey
$template->t_transmissionType(1);//透传消息类型
$template->t_transmissionContent($msg);//透传内容
$message=newIGtSingleMessage();
//APN⾼级推送
$apn=newIGtAPNPayload();
$alertmsg=newDictionaryAlertMsg();
$alertmsg->body="body";
$alertmsg->actionLocKey="ActionLockey";
$alertmsg->locKey="LocKey";
$alertmsg->locArgs=array("locargs");
$alertmsg->launchImage="launchimage";
//IOS8.2⽀持
$alertmsg->title="Title";
$alertmsg->titleLocKey="TitleLocKey";
$alertmsg->titleLocArgs=array("TitleLocArg");
$apn->alertMsg=$alertmsg;
$apn->badge=7;
$apn->sound="";
$apn->add_customMsg("payload","payload");
$apn->contentAvailable=1;
$apn->category="ACTIONABLE";
$template->t_apnInfo($apn);
return$template;
}
}
本文发布于:2023-01-01 01:40:58,感谢您对本站的认可!
本文链接:http://www.wtabcd.cn/fanwen/fan/90/69170.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |