Commit 9bdd7e85 authored by hujun's avatar hujun

个推包

parent bf42e038
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 15-4-9
* Time: 下午3:45
*/
header("Content-Type: text/html; charset=utf-8");
require_once(dirname(__FILE__) . '/' . 'IGt.Push.php');
class IGtBatch
{
var $batchId;
var $innerMsgList = array();
var $seqId = 0;
var $APPKEY;
var $push;
var $lastPostData;
public function __construct($appkey, $push)
{
$this->APPKEY = $appkey;
$this->push = $push;
$this->batchId = uniqid();
}
public function getBatchId()
{
return $this->batchId;
}
public function add($message, $target)
{
if ($this->seqId >= 5000) {
throw new Exception("Can not add over 5000 message once! Please call submit() first.");
} else {
$this->seqId += 1;
$innerMsg = new SingleBatchItem();
$innerMsg->set_seqId($this->seqId);
$innerMsg->set_data($this->createSingleJson($message, $target));
array_push($this->innerMsgList, $innerMsg);
}
return $this->seqId . "";
}
public function createSingleJson($message, $target)
{
$params = $this->push->getSingleMessagePostData($message,$target);
return json_encode($params);
}
public function submit()
{
$requestId = uniqid();
$data = array();
$data["appkey"]=$this->APPKEY;
$data["serialize"] = "pb";
$data["async"] = GTConfig::isPushSingleBatchAsync();
$data["action"] = "pushMessageToSingleBatchAction";
$data['requestId'] = $requestId;
$singleBatchRequest = new SingleBatchRequest();
$singleBatchRequest->set_batchId($this->batchId);
foreach ($this->innerMsgList as $index => $innerMsg) {
$singleBatchRequest->add_batchItem();
$singleBatchRequest->set_batchItem($index, $innerMsg);
}
$data["singleDatas"] = base64_encode($singleBatchRequest->SerializeToString());
$this->seqId = 0;
$this->innerMsgList = array();
$this->lastPostData = $data;
$result = $this->push->httpPostJSON(null, $data, true);
return $result;
}
public function retry()
{
$result = $this->push->httpPostJSON(null, $this->lastPostData, true);
return $result;
}
public function setApiUrl($apiUrl) {
}
}
\ No newline at end of file
This diff is collapsed.
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 15-6-3
* Time: 下午10:07
*/
require_once('../parser/pb_parser.php');
$test = new PBParser();
$test->parse('./performance.proto');
?>
\ No newline at end of file
<?php
//更新时间为2014年11月11日
//增加ClientId可自定义别名功能
header("Content-Type: text/html; charset=utf-8");
require_once(dirname(__FILE__) . '/' . 'IGt.Push.php');
define('APPKEY','');
define('APPID','');
define('MASTERSECRET','');
define('CID','');
define('DEVICETOKEN','');
define('Alias','请输入别名');
define('HOST','http://sdk.open.api.igexin.com/apiex.htm');
//define('CID2','请输入ClientID');
//pushMessageToSingle();
pushMessageToList();
//aliasBind(); //ClientID与别名绑定
//aliasBatch(); //多个ClientID,使用同一别名绑定
//queryCID(); //根据别名查询ClientId
//queryAlias(); //根据ClientId查询别名
//aliasUnBind(); //解除ClientId别名绑定
//aliasUnBindAll(); //解除所有ClientId别名绑定
function aliasBind(){
$igt = new IGeTui(HOST,APPKEY,MASTERSECRET);
$rep = $igt->bindAlias(APPID,ALIAS,CID);
var_dump($rep);
echo("<br><br>");
}
function aliasBatch(){
$igt = new IGeTui(HOST,APPKEY,MASTERSECRET);
$target = new IGtTarget();
$target->set_clientId(CID);
$target->set_alias(ALIAS);
$targetList[] = $target;
// $target1 = new IGtTarget();
// $target1->set_clientId(CID2);
// $target1->set_alias(ALIAS);
// $targetList[] = $target1;
$rep = $igt->bindAliasBatch(APPID,$targetList);
var_dump($rep);
echo("<br><br>");
}
function queryCID(){
$igt = new IGeTui(HOST,APPKEY,MASTERSECRET);
$rep = $igt->queryClientId(APPID,ALIAS);
var_dump($rep);
echo("<br><br>");
}
function queryAlias(){
$igt = new IGeTui(HOST,APPKEY,MASTERSECRET);
$rep = $igt->queryAlias(APPID,CID);
var_dump($rep);
echo("<br><br>");
}
function aliasUnBind(){
$igt = new IGeTui(HOST,APPKEY,MASTERSECRET);
$rep = $igt->unBindAlias(APPID,ALIAS,CID);
var_dump($rep);
echo("<br><br>");
}
function aliasUnBindAll(){
$igt = new IGeTui(HOST,APPKEY,MASTERSECRET);
$rep = $igt->unBindAliasAll(APPID,ALIAS,CID);
var_dump($rep);
echo("<br><br>");
}
//
//服务端推送接口,支持三个接口推送
//1.PushMessageToSingle接口:支持对单个用户进行推送
//2.PushMessageToList接口:支持对多个用户进行推送,建议为50个用户
//3.pushMessageToApp接口:对单个应用下的所有用户进行推送,可根据省份,标签,机型过滤推送
//
//单推接口案例
function pushMessageToSingle(){
$igt = new IGeTui(HOST,APPKEY,MASTERSECRET);
//消息模版:
// 1.TransmissionTemplate:透传功能模板
// 2.LinkTemplate:通知打开链接功能模板
// 3.NotificationTemplate:通知透传功能模板
// 4.NotyPopLoadTemplate:通知弹框下载功能模板
//$template = IGtNotyPopLoadTemplateDemo();
//$template = IGtLinkTemplateDemo();
//$template = IGtNotificationTemplateDemo();
$template = IGtTransmissionTemplateDemo();
//个推信息体
$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为不限制推送
//接收方
$target = new IGtTarget();
$target->set_appId(APPID);
//$target->set_clientId(CID);
$target->set_alias(ALIAS);
$rep = $igt->pushMessageToSingle($message,$target);
var_dump($rep);
echo ("<br><br>");
}
//多推接口案例
function pushMessageToList(){
putenv("needDetails=true");
$igt = new IGeTui(HOST,APPKEY,MASTERSECRET);
//消息模版:
// 1.TransmissionTemplate:透传功能模板
// 2.LinkTemplate:通知打开链接功能模板
// 3.NotificationTemplate:通知透传功能模板
// 4.NotyPopLoadTemplate:通知弹框下载功能模板
//$template = IGtNotyPopLoadTemplateDemo();
//$template = IGtLinkTemplateDemo();
//$template = IGtNotificationTemplateDemo();
$template = IGtTransmissionTemplateDemo();
//个推信息体
$message = new IGtListMessage();
$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,'toList');
//$contentId = $igt->getContentId($message,"toList任务别名功能"); //根据TaskId设置组名,支持下划线,中文,英文,数字
//接收方1
$target1 = new IGtTarget();
$target1->set_appId(APPID);
//$target1->set_clientId(CID);
$target1->set_alias(ALIAS);
$targetList[] = $target1;
$rep = $igt->pushMessageToList($contentId, $targetList);
var_dump($rep);
echo ("<br><br>");
}
//所有推送接口均支持四个消息模板,依次为通知弹框下载模板,通知链接模板,通知透传模板,透传模板
//注:IOS离线推送需通过APN进行转发,需填写pushInfo字段,目前仅不支持通知弹框下载功能
function IGtNotyPopLoadTemplateDemo(){
$template = new IGtNotyPopLoadTemplate();
$template ->set_appId(APPID);//应用appid
$template ->set_appkey(APPKEY);//应用appkey
//通知栏
$template ->set_notyTitle("个推");//通知栏标题
$template ->set_notyContent("个推最新版点击下载");//通知栏内容
$template ->set_notyIcon("");//通知栏logo
$template ->set_isBelled(true);//是否响铃
$template ->set_isVibrationed(true);//是否震动
$template ->set_isCleared(true);//通知栏是否可清除
//弹框
$template ->set_popTitle("弹框标题");//弹框标题
$template ->set_popContent("弹框内容");//弹框内容
$template ->set_popImage("");//弹框图片
$template ->set_popButton1("下载");//左键
$template ->set_popButton2("取消");//右键
//下载
$template ->set_loadIcon("");//弹框图片
$template ->set_loadTitle("地震速报下载");
$template ->set_loadUrl("http://dizhensubao.igexin.com/dl/com.ceic.apk");
$template ->set_isAutoInstall(false);
$template ->set_isActived(true);
return $template;
}
function IGtLinkTemplateDemo(){
$template = new IGtLinkTemplate();
$template ->set_appId(APPID);//应用appid
$template ->set_appkey(APPKEY);//应用appkey
$template ->set_title("请输入通知标题");//通知栏标题
$template ->set_text("请输入通知内容");//通知栏内容
$template ->set_logo("");//通知栏logo
$template ->set_isRing(true);//是否响铃
$template ->set_isVibrate(true);//是否震动
$template ->set_isClearable(true);//通知栏是否可清除
$template ->set_url("http://www.igetui.com/");//打开连接地址
// iOS推送需要设置的pushInfo字段
//$template ->set_pushInfo($actionLocKey,$badge,$message,$sound,$payload,$locKey,$locArgs,$launchImage);
//$template ->set_pushInfo("",2,"","","","","","");
return $template;
}
function IGtNotificationTemplateDemo(){
$template = new IGtNotificationTemplate();
$template->set_appId(APPID);//应用appid
$template->set_appkey(APPKEY);//应用appkey
$template->set_transmissionType(1);//透传消息类型
$template->set_transmissionContent("测试离线");//透传内容
$template->set_title("个推");//通知栏标题
$template->set_text("个推最新版点击下载");//通知栏内容
$template->set_logo("http://wwww.igetui.com/logo.png");//通知栏logo
$template->set_isRing(true);//是否响铃
$template->set_isVibrate(true);//是否震动
$template->set_isClearable(true);//通知栏是否可清除
// iOS推送需要设置的pushInfo字段
//$template ->set_pushInfo($actionLocKey,$badge,$message,$sound,$payload,$locKey,$locArgs,$launchImage);
//$template ->set_pushInfo("test",1,"message","","","","","");
return $template;
}
function IGtTransmissionTemplateDemo(){
$template = new IGtTransmissionTemplate();
$template->set_appId(APPID);//应用appid
$template->set_appkey(APPKEY);//应用appkey
$template->set_transmissionType(1);//透传消息类型
$template->set_transmissionContent("测试离线");//透传内容
//iOS推送需要设置的pushInfo字段
//$template ->set_pushInfo($actionLocKey,$badge,$message,$sound,$payload,$locKey,$locArgs,$launchImage);
//$template ->set_pushInfo("", 0, "", "", "", "", "", "");
return $template;
}
?>
<?php
header("Content-Type: text/html; charset=utf-8");
require_once(dirname(__FILE__) . '/' . 'igetui/utils/ApnsUtils.php');
getPushInfoLen();
function getPushInfoLen() {
$rep = ApnsUtils :: validatePayloadLength("阳春三月天气新,湖中丽人花照春。满船罗绮载花酒,燕歌赵舞留行云。五月湖中采莲女,笑隔荷花共人语",
"", "b", "a", "", "4", "com.gexin.ios.silence", "DDDD",0);
var_dump($rep);
echo ("<br><br>");
}
?>
This diff is collapsed.
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 15-4-28
* Time: 下午5:05
*/
class RequestException extends Exception
{
var $requestId;
public function __construct($requestId, $message, $e)
{
parent::__construct($message, $e);
$this->requestId = $requestId;
}
public function getRequestId()
{
return $this->requestId;
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 15-4-10
* Time: 上午11:37
*/
class IGtAPNPayload
{
var $APN_SOUND_SILENCE = "com.gexin.ios.silence";
public static $PAYLOAD_MAX_BYTES = 2048;
var $customMsg = array();
var $badge = -1;
var $sound = "default";
var $contentAvailable = 0;
var $category;
var $alertMsg;
var $multiMedias = array();
public function get_payload()
{
try {
$apsMap = array();
if ($this->alertMsg != null) {
$msg = $this->alertMsg->get_alertMsg();
if($msg != null)
{
$apsMap["alert"] = $msg;
}
}
if ($this->badge >= 0) {
$apsMap["badge"] = $this->badge;
}
if($this -> sound == null || $this->sound == '' )
{
$apsMap["sound"] = 'default';
}elseif($this->sound != $this->APN_SOUND_SILENCE)
{
$apsMap["sound"] = $this->sound;
}
if (sizeof($apsMap) == 0) {
throw new Exception("format error");
}
if ($this->contentAvailable > 0) {
$apsMap["content-available"] = $this->contentAvailable;
}
if ($this->category != null && $this->category != "") {
$apsMap["category"] = $this->category;
}
$map = array();
if(count($this->customMsg) > 0){
foreach ($this->customMsg as $key => $value) {
$map[$key] = $value;
}
}
$map["aps"] = $apsMap;
if($this -> multiMedias != null && sizeof($this -> multiMedias) > 0) {
$map["_grinfo_"] = $this->check_multiMedias();
}
return json_encode($map);
} catch (Exception $e) {
throw new Exception("create apn payload error", -1, $e);
}
}
public function add_customMsg($key, $value)
{
if ($key != null && $key != "" && $value != null) {
$this->customMsg[$key] = $value;
}
}
function check_multiMedias()
{
if(sizeof($this -> multiMedias) > 3) {
throw new RuntimeException("MultiMedias size overlimit");
}
$needGeneRid = false;
$rids = array();
for($i = 0; $i < sizeof($this -> multiMedias); $i++) {
$media = $this -> multiMedias[$i];
if($media -> get_rid() == null) {
$needGeneRid = true;
} else {
$rids[$media -> get_rid()] = 0;
}
if($media->get_type() == null || $media->get_url() == null) {
throw new RuntimeException("MultiMedia resType and resUrl can't be null");
}
}
if(sizeof($rids) != sizeof($this -> multiMedias)) {
$needGeneRid = true;
}
if($needGeneRid) {
for ($i = 0; $i < sizeof($this->multiMedias); $i++) {
$this->multiMedias[$i] -> set_rid("grid-" . $i);
}
}
return $this -> multiMedias;
}
function add_multiMedia($media) {
$this->multiMedias[] = $media;
return $this;
}
function set_multiMedias($medias) {
$this->multiMedias = $medias;
return $this;
}
}
interface ApnMsg
{
public function get_alertMsg();
}
class DictionaryAlertMsg implements ApnMsg{
var $title;
var $body;
var $titleLocKey;
var $titleLocArgs = array();
var $actionLocKey;
var $locKey;
var $locArgs = array();
var $launchImage;
public function get_alertMsg() {
$alertMap = array();
if ($this->title != null && $this->title != "") {
$alertMap["title"] = $this->title;
}
if ($this->body != null && $this->body != "") {
$alertMap["body"] = $this->body;
}
if ($this->titleLocKey != null && $this->titleLocKey != "") {
$alertMap["title-loc-key"] = $this->titleLocKey;
}
if (sizeof($this->titleLocArgs) > 0) {
$alertMap["title-loc-args"] = $this->titleLocArgs;
}
if ($this->actionLocKey != null && $this->actionLocKey) {
$alertMap["action-loc-key"] = $this->actionLocKey;
}
if ($this->locKey != null && $this->locKey != "") {
$alertMap["loc-key"] = $this->locKey;
}
if (sizeof($this->locArgs) > 0) {
$alertMap["loc-args"] = $this->locArgs;
}
if ($this->launchImage != null && $this->launchImage != "") {
$alertMap["launch-image"] = $this->launchImage;
}
if(count($alertMap) == 0)
{
return null;
}
return $alertMap;
}
}
class SimpleAlertMsg implements ApnMsg{
var $alertMsg;
public function get_alertMsg() {
return $this->alertMsg;
}
}
?>
<?php
header("Content-Type: text/html; charset=utf-8");
require_once(dirname(__FILE__) .'/'.'utils/AppConditions.php');
class IGtAppMessage extends IGtMessage{
//array('','',..)
var $appIdList;
//array('','',..)
var $phoneTypeList;
//array('','',..)
var $provinceList;
var $tagList;
var $conditions;
var $speed=0;
function __construct(){
parent::__construct();
}
function get_appIdList() {
return $this->appIdList;
}
function set_appIdList($appIdList) {
$this->appIdList = $appIdList;
}
/**
* @deprecated deprecated since version 4.0.0.3
*/
function get_phoneTypeList() {
return $this->phoneTypeList;
}
/**
* @deprecated deprecated since version 4.0.0.3
*/
function set_phoneTypeList($phoneTypeList) {
$this->phoneTypeList = $phoneTypeList;
}
/**
* @deprecated deprecated since version 4.0.0.3
*/
function get_provinceList() {
return $this->provinceList;
}
/**
* @deprecated deprecated since version 4.0.0.3
*/
function set_provinceList($provinceList) {
$this->provinceList = $provinceList;
}
/**
* @deprecated deprecated since version 4.0.0.3
*/
function get_tagList() {
return $this->tagList;
}
/**
* @deprecated deprecated since version 4.0.0.3
*/
function set_tagList($tagList) {
$this->tagList = $tagList;
}
public function get_conditions()
{
return $this->conditions;
}
public function set_conditions($conditions)
{
$this->conditions = $conditions;
}
function get_speed()
{
return $this->speed;
}
function set_speed($speed)
{
$this->speed=$speed;
}
}
\ No newline at end of file
<?php
class IGtListMessage extends IGtMessage{
public function __construct(){
parent::__construct();
}
}
\ No newline at end of file
<?php
class IGtMessage{
var $isOffline;
/*
* 过多久该消息离线失效(单位毫秒) 支持1-72小时*3600000秒,默认1小时
*/
var $offlineExpireTime;
/**
* 0:联网方式不限;1:仅wifi;2:仅4G/3G/2G
*/
var $pushNetWorkType = 0;
var $data;
public function __construct()
{
}
function get_isOffline()
{
return $this->isOffline;
}
function set_isOffline($isOffline)
{
return $this->isOffline = $isOffline;
}
function get_offlineExpireTime()
{
return $this->offlineExpireTime;
}
function set_offlineExpireTime($offlineExpireTime)
{
return $this->offlineExpireTime = $offlineExpireTime;
}
function get_pushNetWorkType()
{
return $this->pushNetWorkType;
}
function set_pushNetWorkType($pushNetWorkType)
{
return $this->pushNetWorkType = $pushNetWorkType;
}
function get_data()
{
return $this->data;
}
function set_data($data)
{
return $this->data = $data;
}
}
\ No newline at end of file
<?php
/**
* 个推IOS多媒体消息,支持图片、音频、视频
* Created by PhpStorm.
* User: zqzhao5
* Date: 17-7-27
* Time: 下午3:21
*/
class IGtMultiMedia {
/**
* @var资源ID
*/
var $rid;
/**
* @var资源url
*/
var $url;
/**
* @var资源类型
*/
var $type;
/**
* @var是否只支持wifi下发
*/
var $onlywifi = 0;
public function __construct(){}
function get_rid() {
return $this->rid;
}
function set_rid($rid) {
$this->rid = $rid;
return $this;
}
function get_url() {
return $this->url;
}
function set_url($url) {
$this->url = $url;
return$this;
}
function get_type() {
return $this -> type;
}
function set_type($type) {
$this -> type = $type;
return $this;
}
function set_onlywifi($onlywifi) {
$this -> onlywifi = $onlywifi ? 1:0;
return $this;
}
function get_onlywifi() {
return $this -> onlywifi;
}
}
class MediaType {
const __default = self::pic;
const pic = 1;
const audio = 2;
const video = 3;
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment