zoukankan      html  css  js  c++  java
  • php 个推的例子

    个推   http://docs.getui.com/server/php/start/

    <?php

    /**
    * Created by PhpStorm.
    * User: xiaochao
    * Date: 15/7/29
    * Time: 上午9:43
    */
    class push {

    private $APPKEY; //个推appkey
    private $APPID; //个推appid
    private $MASTERSECRET; //个推密钥
    private $HOST; //个推api地址

    /*
    * 初始化个推的配置选项
    * @param none
    */

    function __construct() {
    $this->CI = & get_instance();
    $this->CI->config->load('config.php');
    $gt_config = $this->CI->config->item('gt');
    $this->APPKEY = $gt_config['APPKEY'];
    $this->APPID = $gt_config['APPID'];
    $this->MASTERSECRET = $gt_config['MASTERSECRET'];
    $this->HOST = $gt_config['HOST'];
    require(APPPATH . "/libraries/getui/" . "IGt.Push.php");
    //require(APPPATH . "/libraries/getui/" . "igetui/IGt.AppMessage.php");
    //require(APPPATH . "/libraries/getui/" . "igetui/IGt.APNPayload.php");
    //require(APPPATH . "/libraries/getui/" . "igetui/template/IGt.BaseTemplate.php");
    //require(APPPATH . "/libraries/getui/" . "IGt.Batch.php");
    }

    /**
    * 推送单用户
    *
    * @param $template
    * @param $clientid
    */
    public function pushMessageToSingle($template, $clientid) {

    $igt = new IGeTui($this->HOST, $this->APPKEY, $this->MASTERSECRET);

    //个推信息体
    $message = new IGtSingleMessage();

    $message->set_isOffline(true); //是否离线
    $message->set_offlineExpireTime(172800000); //离线时间
    $message->set_data($template); //设置推送消息类型
    //接收方
    $target = new IGtTarget();
    $target->set_appId($this->APPID);
    $target->set_clientId($clientid);
    $rep = $igt->pushMessageToSingle($message, $target);

    var_dump($rep);
    }

    /**
    * 给所有用户推送
    *
    * @param $phoneType
    * @param $template
    */
    public function pushMessageToApp($phoneType, $template) {

    //此方式可通过获取服务端地址列表判断最快域名后进行消息推送,每10分钟检查一次最快域名
    $igt = new IGeTui('', $this->APPKEY, $this->MASTERSECRET);

    //个推信息体
    //基于应用消息体
    $message = new IGtAppMessage();

    $message->set_isOffline(true);

    //离线时间单位为毫秒,例,两个小时离线为3600*1000*2
    $message->set_offlineExpireTime(172800000);
    $message->set_data($template);

    //设置是否根据WIFI推送消息,1为wifi推送,0为不限制推送
    $message->set_PushNetWorkType(0);

    //设置群推接口的推送速度,单位为条/秒,例如填写100,则为100条/秒。仅对指定应用群推接口有效。
    $message->set_speed(1000);
    $message->set_appIdList(array($this->APPID));

    if ($phoneType == 1) {
    $message->set_phoneTypeList(array('ANDROID'));
    } else {
    $message->set_phoneTypeList(array('IOS'));
    }

    $rep = $igt->pushMessageToApp($message);

    var_dump($rep);
    }

    /**
    * 通知透传模版
    *
    * @param $data
    * @return IGtNotificationTemplate
    */
    public function NotificationTemplate($data) {

    $template = new IGtNotificationTemplate();
    //应用appid
    $template->set_appId($this->APPID);
    //应用appkey
    $template->set_appkey($this->APPKEY);
    //通知栏标题
    $template->set_title($data['title']);
    //通知栏内容
    $template->set_text($data['text']);
    //通知栏logo
    $template->set_logo($data['logo']);
    //是否响铃
    $template->set_isRing($data['isRing']);
    //是否震动
    $template->set_isVibrate($data['isVibrate']);
    //通知栏是否可清除
    $template->set_isClearable($data['isClearable']);
    //收到消息是否立即启动应用:1为立即启动,2则广播等待客户端自启动
    $template->set_transmissionType($data['transmissionType']);
    //透传内容
    $template->set_transmissionContent($data['transmissionContent']);
    //TODO:IOS待添加
    return $template;
    }

    /**
    * 透传模版
    *
    * @param $data
    * @return IGtTransmissionTemplate
    */
    public function TransmissionTemplate($data) {
    $template = new IGtTransmissionTemplate();
    //应用appid
    $template->set_appId($this->APPID);
    //应用appkey
    $template->set_appkey($this->APPKEY);
    //收到消息是否立即启动应用,1为立即启动,2则广播等待客户端自启动
    $template->set_transmissionType($data['transmissionType']);
    //透传内容
    $template->set_transmissionContent($data['transmissionContent']);
    //TODO:IOS待添加
    $apn = new IGtAPNPayload();
    $alertmsg = new DictionaryAlertMsg();
    $alertmsg->body = "body";
    $alertmsg->actionLocKey = "ActionLockey";
    $alertmsg->locKey = "张杰逗比";
    $alertmsg->locArgs = array("locargs");
    $alertmsg->launchImage = "launchimage";
    // IOS8.2 支持
    $alertmsg->title = "张杰逗比";
    $alertmsg->titleLocKey = "TitleLocKey";
    $alertmsg->titleLocArgs = array("TitleLocArg");

    $apn->alertMsg = $alertmsg;
    $apn->badge = 2;
    $apn->sound = "";
    $apn->add_customMsg("islogout", 'true');
    $apn->contentAvailable = 1;
    $apn->category = "ACTIONABLE";
    $template->set_apnInfo($apn);
    return $template;
    }

    /**
    * 点击打开网页模版
    *
    * @param $data
    * @return IGtLinkTemplate
    */
    public function LinkTemplate($data) {
    $template = new IGtLinkTemplate();
    //应用appid
    $template->set_appId($this->APPID);
    //应用appkey
    $template->set_appkey($this->APPKEY);
    //通知栏标题
    $template->set_title($data['title']);
    //通知栏内容
    $template->set_text($data['text']);
    //通知栏logo
    $template->set_logo($data['logo']);
    //通知栏logo链接
    //$template->set_logoURL("");
    //是否响铃
    $template->set_isRing($data['isRing']);
    //是否震动
    $template->set_isVibrate($data['isVibrate']);
    //通知栏是否可清除
    $template->set_isClearable($data['isClearable']);
    //打开连接地址
    $template->set_url($data['url']);
    //TODO:IOS待添加

    return $template;
    }

    /**
    * 通知栏弹框下载 IOS 不支持
    *
    * @param $data
    * @return IGtNotyPopLoadTemplate
    */
    public function NotyPopLoadTemplate($data) {

    $template = new IGtNotyPopLoadTemplate();
    $template->set_appId($this->APPID); //应用appid
    $template->set_appkey($this->APPKEY); //应用appkey
    //通知栏
    //通知栏标题
    $template->set_notyTitle($data['notyTitle']);
    //通知栏内容
    $template->set_notyContent($data['notyContent']);
    //通知栏logo
    $template->set_notyIcon($data['notyIcon']);
    //是否响铃
    $template->set_isBelled($data['isBelled']);
    //是否震动
    $template->set_isVibrationed($data['isVibrationed']);
    //通知栏是否可清除
    $template->set_isCleared($data['isCleared']);

    //弹框
    //弹框标题
    $template->set_popTitle($data['popTitle']);
    //弹框内容
    $template->set_popContent($data['popContent']);
    //弹框图片
    $template->set_popImage($data['popImage']);
    //左键
    $template->set_popButton1($data['popButton1']);
    //右键
    $template->set_popButton2($data['popButton2']);

    //下载
    //弹框图片
    $template->set_loadIcon($data['loadIcon']);
    //弹框标题
    $template->set_loadTitle($data['loadTitle']);
    //下载地址
    $template->set_loadUrl($data['loadUrl']);
    //是否自动安装
    $template->set_isAutoInstall($data['isAutoInstall']);
    //安装完成后是否自动启动
    $template->set_isActived($data['isActived']);
    return $template;
    }

    /**
    * 给客户端发送退出登录提醒
    * @param string $user_id 用户的id
    * */
    public function push_logout($user_id) {
    $this->CI->load->model('User_data_model');
    $client_data = $this->CI->User_data_model->getclientdata($user_id);
    $msgdata = array(
    'islogout' => TRUE
    );
    $temp = $this->TransmissionTemplate(array(
    'transmissionType' => 0, 'transmissionContent' => json_encode($msgdata)
    ));
    $this->pushMessageToSingle($temp, $client_data->client_id);
    }

    }

  • 相关阅读:
    Pycharm在线/手动离线安装第三方库-以scapy为例(本地离线添加已经安装的第三方库通过添加Path实现)
    python+splinter实现12306网站刷票并自动购票流程
    利用RELK进行日志收集
    web安全之文件上传漏洞攻击与防范方法
    C# 使用 CancellationTokenSource 终止线程
    ASP.NET MVC 下拉框的传值的两种方式
    SQL Server(解决问题)已成功与服务器建立连接,但是在登录过程中发生错误。(provider: Shared Memory Provider, error:0
    C# .net中json字符串和对象之间的转化方法
    asp.net 未能加载文件或程序集“WebApi”或它的某一个依赖项。试图加载格式不正确的程序。
    将博客搬至CSDN
  • 原文地址:https://www.cnblogs.com/lijiageng/p/5799884.html
Copyright © 2011-2022 走看看