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);
}
}
php 个推的例子的更多相关文章
- 我写的websocket推送例子,每隔5秒服务器向客户端浏览器发送消息(node.js和浏览器)
node.js服务端 先要安装ws模块的支持 npm install ws 服务端(server.js) var gws; var WebSocketServer = require('ws').Se ...
- .NET平台下 极光推送
正好看到别人发了个极光的推送例子,想来前面也刚做过这个,就把我的push类共享下 public class JPush { /// <summary> /// push信息到手机应用上 J ...
- 自定义iOS 中推送消息 提示框
看到标题你可能会觉得奇怪 推送消息提示框不是系统自己弹出来的吗? 为什么还要自己自定义呢? 因为项目需求是这样的:最近需要做 远程推送通知 和一个客服系统 包括店铺客服和官方客服两个模块 如果有新的消 ...
- 1、ASP.NET MVC入门到精通——新语法
本系列目录:ASP.NET MVC4入门到精通系列目录汇总 在学习ASP.NET MVC之前,有必要先了解一下C#3.0所带来的新的语法特性,这一点尤为重要,因为在MVC项目中我们利用C#3.0的新特 ...
- Head First-观察者模式
什么是观察者模式?观察者模式定义了对象之间一对多的关系. 观察者模式中有主题(即可观察者)和观察者.主题用一个共同的接口来通知观察者,主题不知道观察者的细节,只知道观察者实现了主题的接口. 普遍的观察 ...
- 《Introduction to Tornado》中文翻译计划——第五章:异步Web服务
http://www.pythoner.com/294.html 本文为<Introduction to Tornado>中文翻译,将在https://github.com/alioth3 ...
- tornado学习精要
最简单的应用在程序的最顶部,我们导入了一些Tornado模块.虽然Tornado还有另外一些有用的模块,但在这个例子中我们必须至少包含这四个模块. 12341234包括了一个有用的模块(tornado ...
- FastRPC 3.2 发布,高性能 C++ 协程 RPC 框架
用过go erlang gevent的亲们应该都会知道协程在应用中带来的方便. 如果对协程不理解的同学,通过阅读下面例子可以快速了解我们框架的协程的意义,已了解的可以跳过这部分. 协程例子:假设我们要 ...
- [蓝桥杯]2013蓝桥省赛B组题目及详解
/*——————————————————————————————————————————————————————————— 题目:2013 高斯日记T-1 问题描述: 大数学家高斯有一个好习惯:无论如 ...
随机推荐
- 安卓.点击头像-->编辑个人姓名-->提交后.同时调用js关闭页面-->返回上一层
$(document).ready(function() { $('#selfbtn').click(function(){ var u = navigator.userAgent; if (u.in ...
- 处理Properties文件中key包含空格的情况
在这个互联网信息共享的时代,好处是一个问题的很多解决方案都可以从网络上得到,不好的一点就是很多人喜欢复制粘贴也不注明转载出处,不尊重别人的劳动成果,不假思索地把别人的原创复制到自己的博客然后发布,请大 ...
- 理解 Storm 拓扑的并行度(parallelism)概念
组成:一个运行中的拓扑是由什么构成的:工作进程(worker processes),执行器(executors)和任务(tasks)! 在一个 Storm 集群中,Storm 主要通过以下三个部件来运 ...
- Myeclipse 激活代码 8.6以前的版本
public class Akey { private static final String LL = "Decompiling this copyrighted software is ...
- Nginx简单配置,部分来源于网络
nginx.conf listener监听端口 server_name监听域名 location{}是用来为匹配的 URI 进行配置,URI 即语法中的“/uri/”.location / { }匹 ...
- 【Machine Learning in Action --3】决策树ID3算法
1.简单概念描述 决策树的类型有很多,有CART.ID3和C4.5等,其中CART是基于基尼不纯度(Gini)的,这里不做详解,而ID3和C4.5都是基于信息熵的,它们两个得到的结果都是一样的,本次定 ...
- javascript注释规范
注释在代码编写过程中的重要性,写代码超过半年的就能深深的体会到.没有注释的代码都不是好代码.为了别人学习,同时为了自己以后对代码进行'升级',看看js/javascript代码注释规范与示例.来自:h ...
- ssh连接ubuntu提示连接不上的问题
今天在自己的电脑上安装了最新版本的 ubuntu (我都在root用户下运行,非root用户请添加sudo命令) uname -rvo 运行结果为 3.13.0-32-generic #57-Ubun ...
- HTML+CSS D09 定位
1.定位 (1)相对定位 如果对一个元素进行相对定位,它将出现在它所在的位置上.然后,可以通过设置垂直或水平位置,让这个元素“相对于”它的起点进行移动. #box_relative { positi ...
- CodeFroces--Good Bye 2016-B--New Year and North Pole(水题-模拟)
B. New Year and North Pole time limit per test 2 seconds memory limit per test 256 megabytes input s ...