个推   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);
}

}

php 个推的例子的更多相关文章

  1. 我写的websocket推送例子,每隔5秒服务器向客户端浏览器发送消息(node.js和浏览器)

    node.js服务端 先要安装ws模块的支持 npm install ws 服务端(server.js) var gws; var WebSocketServer = require('ws').Se ...

  2. .NET平台下 极光推送

    正好看到别人发了个极光的推送例子,想来前面也刚做过这个,就把我的push类共享下 public class JPush { /// <summary> /// push信息到手机应用上 J ...

  3. 自定义iOS 中推送消息 提示框

    看到标题你可能会觉得奇怪 推送消息提示框不是系统自己弹出来的吗? 为什么还要自己自定义呢? 因为项目需求是这样的:最近需要做 远程推送通知 和一个客服系统 包括店铺客服和官方客服两个模块 如果有新的消 ...

  4. 1、ASP.NET MVC入门到精通——新语法

    本系列目录:ASP.NET MVC4入门到精通系列目录汇总 在学习ASP.NET MVC之前,有必要先了解一下C#3.0所带来的新的语法特性,这一点尤为重要,因为在MVC项目中我们利用C#3.0的新特 ...

  5. Head First-观察者模式

    什么是观察者模式?观察者模式定义了对象之间一对多的关系. 观察者模式中有主题(即可观察者)和观察者.主题用一个共同的接口来通知观察者,主题不知道观察者的细节,只知道观察者实现了主题的接口. 普遍的观察 ...

  6. 《Introduction to Tornado》中文翻译计划——第五章:异步Web服务

    http://www.pythoner.com/294.html 本文为<Introduction to Tornado>中文翻译,将在https://github.com/alioth3 ...

  7. tornado学习精要

    最简单的应用在程序的最顶部,我们导入了一些Tornado模块.虽然Tornado还有另外一些有用的模块,但在这个例子中我们必须至少包含这四个模块. 12341234包括了一个有用的模块(tornado ...

  8. FastRPC 3.2 发布,高性能 C++ 协程 RPC 框架

    用过go erlang gevent的亲们应该都会知道协程在应用中带来的方便. 如果对协程不理解的同学,通过阅读下面例子可以快速了解我们框架的协程的意义,已了解的可以跳过这部分. 协程例子:假设我们要 ...

  9. [蓝桥杯]2013蓝桥省赛B组题目及详解

    /*——————————————————————————————————————————————————————————— 题目:2013 高斯日记T-1 问题描述: 大数学家高斯有一个好习惯:无论如 ...

随机推荐

  1. Map获取键值,Map的几种遍历方法

    Map 类提供了一个称为entrySet()的方法,这个方法返回一个Map.Entry实例化后的对象集.接着,Map.Entry类提供了一个 getKey()方法和一个getValue()方法,Map ...

  2. FTP服务添加用户及设置权限

    CentOS下安装vsftpd省略. 添加ftp账户: useradd ahaii -d /home/ftp/ -s /sbin/nologin 添加密码: passwd ahaii 限制该用户只能访 ...

  3. MySQL(1) - 基础

    参考资料: http://www.jianshu.com/p/91e3af27743f 一.MySQL介绍以及安装 1.1 MySQL介绍 MariaDB数据库管理系统是MySQL的一个分支,主要由开 ...

  4. Java 中值传递和引用传递 区分

    详细参见  http://blog.csdn.net/zzp_403184692/article/details/8184751

  5. LeetCode OJ Remove Duplicates from Sorted Array II

    Follow up for "Remove Duplicates":What if duplicates are allowed at most twice? For exampl ...

  6. NOIP2002-普及组复赛-第三题-选数

    题目描述 Description 已知 n 个整数 x1,x2,…,xn,以及一个整数 k(k<n).从 n 个整数中任选 k 个整数相加,可分别得到一系列的和.例如当 n=4,k=3,4 个整 ...

  7. 洛谷-陶陶摘苹果(升级版)-BOSS战-入门综合练习1

    题目描述 Description 又是一年秋季时,陶陶家的苹果树结了n个果子.陶陶又跑去摘苹果,这次她有一个a公分的椅子.当他手够不着时,他会站到椅子上再试试. 这次与NOIp2005普及组第一题不同 ...

  8. mybatis的insert返回主键

    <insert id="insert" useGeneratedKeys="true" keyProperty="id" parame ...

  9. I Think I Need a Houseboat

    I Think I Need a Houseboat Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java ...

  10. ***1133. Fibonacci Sequence(斐波那契数列,二分,数论)

    1133. Fibonacci Sequence Time limit: 1.0 secondMemory limit: 64 MB is an infinite sequence of intege ...