Laravel 调用 个推 对Android和IOS进行推送

来源:互联网 发布:淘宝搜白夜追凶视频 编辑:程序博客网 时间:2024/05/18 02:45
<?php//个推header("Content-Type: text/html; charset=utf-8");//引用的个推的文件require_once(public_path() . '/Admin/getui/IGt.Push.php');require_once(public_path() . '/Admin/getui/igetui/IGt.AppMessage.php');require_once(public_path() . '/Admin/getui/igetui/IGt.APNPayload.php');require_once(public_path() . '/Admin/getui/igetui/template/IGt.BaseTemplate.php');require_once(public_path() . '/Admin/getui/IGt.Batch.php');require_once(public_path() . '/Admin/getui/igetui/template/IGt.NotificationTemplate.php');require_once(public_path() . '/Admin/getui/igetui/utils/AppConditions.php');require_once(public_path() . '/Admin/getui/protobuf/type/pb_string.php');//http的域名define('HOST',env('APP_GTHOST'));define('APPKEY',env('APP_GTKEY'));//个推的keydefine('APPID',env('APP_GTID'));//个推的appiddefine('MASTERSECRET',env('APP_GTMASTERSECRET'));//个推的密钥class SendMessageController extends Controller{    //发送消息    public function send($id){        $res =   $this -> pushMessageToList($content->title,$content->content,$person);//这个主要用了别名推送,一个别名可以绑定十个cid.cid代表的是设备id    }//群推没有限制,这个方式主要是直接把推送任务直接给了个推这边,不分别用户的类型    public function pushMessageToApp($title,$content){        $igt = new \IGeTui(HOST,APPKEY,MASTERSECRET);        $template = $this -> IGtTransmissionTemplateDemo($title,$content);        //个推信息体        //基于应用消息体        $message = new \IGtAppMessage();        $message->set_isOffline(true);        $message->set_offlineExpireTime(10 * 60 * 1000);//离线时间单位为毫秒,例,两个小时离线为3600*1000*2        $message->set_data($template);        $appIdList=array(APPID);        $message->set_appIdList($appIdList);        $rep = $igt->pushMessageToApp($message,"任务组名");    }    //群推 有人员限制 这个主要利用了 别名推送 (利用用户uid当作了推送的别名)..获取不同类型的用户,将uid(别名)统一传过去    function pushMessageToList($title,$content,$obj){        putenv("gexin_pushList_needDetails=true");        $igt = new \IGeTui(HOST,APPKEY,MASTERSECRET);        $template = $this -> IGtTransmissionTemplateDemo($title,$content);        //定义"ListMessage"信息体//        $message = new \IGtListMessage();        $message = new \IGtSingleMessage();        $message->set_isOffline(true);//是否离线        $message->set_offlineExpireTime(3600*12*1000);//离线时间        $message->set_data($template);//设置推送消息类型        $message->set_PushNetWorkType(0);//设置是否根据WIFI推送消息,1为wifi推送,0为不限制推送//        $contentId = $igt->getContentId($message);        foreach($obj as $k => $v){            $target = new \IGtTarget();            $target->set_appId(APPID);            $target->set_alias($v->id);            try {                $rep = $igt->pushMessageToSingle($message, $target);//利用的是单推  效率高            }catch(\RequestException $e){                $requstId =e.getRequestId();                //失败时重发                $rep = $igt->pushMessageToSingle($message, $target,$requstId);            }        }    }//试试这个     //这个主要是透传消息模板    function IGtTransmissionTemplateDemo($title,$content){        $template =  new \IGtTransmissionTemplate();        $template->set_appId(APPID);//应用appid        $template->set_appkey(APPKEY);//应用appkey        $template->set_transmissionType(1);//透传消息类型        $template->set_transmissionContent($content);//透传内容        //APN高级推送        $apn = new \IGtAPNPayload();        $alertmsg=new \DictionaryAlertMsg();        $alertmsg->body=$content;        $alertmsg->actionLocKey="ActionLockey";        $alertmsg->locKey=$title;        $alertmsg->locArgs=array("locargs");        $alertmsg->launchImage="launchimage";//        IOS8.2 支持        $alertmsg->title=$title;        $alertmsg->titleLocKey=$content;        $alertmsg->titleLocArgs=array("TitleLocArg");        $apn->alertMsg=$alertmsg;        $apn->badge=1;        $apn->sound="";        $apn->add_customMsg("payload","payload");        $apn->contentAvailable=1;        $apn->category="ACTIONABLE";        $template->set_apnInfo($apn);        return $template;    }}?>

原创粉丝点击