Skip to content

Commit

Permalink
新增unipush示例
Browse files Browse the repository at this point in the history
  • Loading branch information
ArrayDC committed Jul 20, 2019
1 parent 3d0be9d commit ae4b3b3
Show file tree
Hide file tree
Showing 46 changed files with 7,481 additions and 0 deletions.
84 changes: 84 additions & 0 deletions push/UniPush/IGt.Batch.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?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 = LangUtils::randomUUID();
$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) {
}
}
Loading

0 comments on commit ae4b3b3

Please sign in to comment.