IGt.Push.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787
  1. <?php
  2. /**
  3. * VERSION 3.3.2.1
  4. */
  5. header("Content-Type: text/html; charset=utf-8");
  6. require_once(dirname(__FILE__) . '/' . 'protobuf/pb_message.php');
  7. require_once(dirname(__FILE__) . '/' . 'igetui/IGt.Req.php');
  8. require_once(dirname(__FILE__) . '/' . 'igetui/IGt.Message.php');
  9. require_once(dirname(__FILE__) . '/' . 'igetui/IGt.AppMessage.php');
  10. require_once(dirname(__FILE__) . '/' . 'igetui/IGt.ListMessage.php');
  11. require_once(dirname(__FILE__) . '/' . 'igetui/IGt.SingleMessage.php');
  12. require_once(dirname(__FILE__) . '/' . 'igetui/IGt.Target.php');
  13. require_once(dirname(__FILE__) . '/' . 'igetui/template/IGt.BaseTemplate.php');
  14. require_once(dirname(__FILE__) . '/' . 'igetui/template/IGt.LinkTemplate.php');
  15. require_once(dirname(__FILE__) . '/' . 'igetui/template/IGt.NotificationTemplate.php');
  16. require_once(dirname(__FILE__) . '/' . 'igetui/template/IGt.TransmissionTemplate.php');
  17. require_once(dirname(__FILE__) . '/' . 'igetui/template/IGt.NotyPopLoadTemplate.php');
  18. require_once(dirname(__FILE__) . '/' . 'igetui/template/IGt.APNTemplate.php');
  19. require_once(dirname(__FILE__) . '/' . 'igetui/utils/GTConfig.php');
  20. require_once(dirname(__FILE__) . '/' . 'igetui/utils/HttpManager.php');
  21. require_once(dirname(__FILE__) . '/' . 'igetui/utils/ApiUrlRespectUtils.php');
  22. require_once(dirname(__FILE__) . '/' . 'igetui/utils/LangUtils.php');
  23. Class IGeTui
  24. {
  25. var $appkey; //第三方 标识
  26. var $masterSecret; //第三方 密钥
  27. var $format = "json"; //默认为 json 格式
  28. var $host ="";
  29. var $needDetails = false;
  30. static $appkeyUrlList = array();
  31. var $domainUrlList = array();
  32. var $useSSL = NULL; //是否使用https连接 以该标志为准
  33. var $authToken;
  34. public function __construct($domainUrl, $appkey, $masterSecret, $ssl = NULL)
  35. {
  36. $this->appkey = $appkey;
  37. $this->masterSecret = $masterSecret;
  38. $domainUrl = trim($domainUrl);
  39. if ($ssl == NULL && $domainUrl != NULL && strpos(strtolower($domainUrl), "https:") === 0)
  40. {
  41. $ssl = true;
  42. }
  43. $this->useSSL = ($ssl == NULL ? false : $ssl);
  44. if ($domainUrl == NULL || strlen($domainUrl) == 0)
  45. {
  46. $this->domainUrlList = GTConfig::getDefaultDomainUrl($this->useSSL);
  47. }
  48. else
  49. {
  50. $this->domainUrlList = array($domainUrl);
  51. }
  52. $this->initOSDomain(null);
  53. }
  54. private function initOSDomain($hosts)
  55. {
  56. if($hosts == null || count($hosts) == 0)
  57. {
  58. $hosts = isset(IGeTui::$appkeyUrlList[$this->appkey])?IGeTui::$appkeyUrlList[$this->appkey]:null;
  59. if($hosts == null || count($hosts) == 0)
  60. {
  61. $hosts = $this->getOSPushDomainUrlList($this->domainUrlList,$this->appkey);
  62. IGeTui::$appkeyUrlList[$this->appkey] = $hosts;
  63. }
  64. }
  65. else
  66. {
  67. IGeTui::$appkeyUrlList[$this->appkey] = $hosts;
  68. }
  69. $this->host = ApiUrlRespectUtils::getFastest($this->appkey, $hosts);
  70. return $this->host;
  71. }
  72. public function getOSPushDomainUrlList($domainUrlList,$appkey)
  73. {
  74. $urlList = null;
  75. $postData = array();
  76. $postData['action']='getOSPushDomailUrlListAction';
  77. $postData['appkey'] = $appkey;
  78. $ex = null;
  79. foreach($domainUrlList as $durl)
  80. {
  81. try
  82. {
  83. $response = $this->httpPostJSON($durl,$postData);
  84. $urlList = isset($response["osList"])?$response["osList"]:null;
  85. if($urlList != null && count($urlList) > 0)
  86. {
  87. break;
  88. }
  89. }
  90. catch (Exception $e)
  91. {
  92. $ex = $e;
  93. }
  94. }
  95. if($urlList == null || count($urlList) <= 0)
  96. {
  97. $h = implode(',', $domainUrlList);
  98. throw new Exception("Can not get hosts from ".$h."|error:".$ex);
  99. }
  100. return $urlList;
  101. }
  102. function httpPostJSON($url,$data,$gzip=false)
  103. {
  104. $data['version'] = GTConfig::getSDKVersion();
  105. $data['authToken'] = $this->authToken;
  106. if($url == null){
  107. $url = $this->host;
  108. }
  109. $rep = HttpManager::httpPostJson($url, $data, $gzip);
  110. if($rep != null)
  111. {
  112. if ( 'sign_error' == $rep['result']) {
  113. try
  114. {
  115. if ($this->connect())
  116. {
  117. $data['authToken'] = $this->authToken;
  118. $rep = HttpManager::httpPostJson($url, $data, $gzip);
  119. }
  120. }
  121. catch (Exception $e)
  122. {
  123. throw new Exception("连接异常".$e);
  124. }
  125. }
  126. else if('domain_error' == $rep['result'])
  127. {
  128. $this->initOSDomain(isset($rep["osList"])?$rep["osList"]:null);
  129. $rep = HttpManager::httpPostJson($url, $data, $gzip);
  130. }
  131. }
  132. return $rep;
  133. }
  134. public function connect()
  135. {
  136. $timeStamp = $this->micro_time();
  137. // 计算sign值
  138. $sign = md5($this->appkey . $timeStamp . $this->masterSecret);
  139. //
  140. //var_dump($sign);
  141. $params = array();
  142. $params["action"] = "connect";
  143. $params["appkey"] = $this->appkey;
  144. $params["timeStamp"] = $timeStamp;
  145. $params["sign"] = $sign;
  146. $params["version"] = GTConfig::getSDKVersion();
  147. $rep = HttpManager::httpPostJson($this->host,$params,false);
  148. if ('success' == $rep['result']) {
  149. if($rep["authtoken"] != null){
  150. $this->authToken = $rep["authtoken"];
  151. }
  152. return true;
  153. }
  154. throw new Exception("appKey Or masterSecret is Auth Failed");
  155. }
  156. public function close()
  157. {
  158. $params = array();
  159. $params["action"] = "close";
  160. $params["appkey"] = $this->appkey;
  161. $params["version"] = GTConfig::getSDKVersion();
  162. $params["authtoken"] = $this->authToken;
  163. HttpManager::httpPostJson($this->host,$params,false);
  164. }
  165. /**
  166. * 指定用户推送消息
  167. * @param IGtMessage message
  168. * @param IGtTarget target
  169. * @return Array {result:successed_offline,taskId:xxx} || {result:successed_online,taskId:xxx} || {result:error}
  170. ***/
  171. public function pushMessageToSingle($message, $target, $requestId = null)
  172. {
  173. if($requestId == null || trim($requestId) == "")
  174. {
  175. $requestId = LangUtils::randomUUID();
  176. }
  177. $params = $this->getSingleMessagePostData($message, $target, $requestId);
  178. return $this->httpPostJSON($this->host,$params);
  179. }
  180. function getSingleMessagePostData($message, $target, $requestId = null){
  181. $params = array();
  182. $params["action"] = "pushMessageToSingleAction";
  183. $params["appkey"] = $this -> appkey;
  184. if($requestId != null)
  185. {
  186. $params["requestId"] = $requestId;
  187. }
  188. $params["clientData"] = base64_encode($message->get_data()->get_transparent());
  189. $params["transmissionContent"] = $message->get_data()->get_transmissionContent();
  190. $params["isOffline"] = $message->get_isOffline();
  191. $params["offlineExpireTime"] = $message->get_offlineExpireTime();
  192. // 增加pushNetWorkType参数(0:不限;1:wifi;2:4G/3G/2G)
  193. $params["pushNetWorkType"] = $message->get_pushNetWorkType();
  194. //
  195. $params["appId"] = $target->get_appId();
  196. $params["clientId"] = $target->get_clientId();
  197. $params["alias"] = $target->get_alias();
  198. // 默认都为消息
  199. $params["type"] = 2;
  200. $params["pushType"] = $message->get_data()->get_pushType();
  201. return $params;
  202. }
  203. public function getContentId($message,$taskGroupName = null)
  204. {
  205. return $this->getListAppContentId($message,$taskGroupName);
  206. }
  207. /**
  208. * 取消消息
  209. * @param String contentId
  210. * @return boolean
  211. ***/
  212. public function cancelContentId($contentId)
  213. {
  214. $params = array();
  215. $params["action"] = "cancleContentIdAction";
  216. $params["appkey"] = $this->appkey;
  217. $params["contentId"] = $contentId;
  218. $rep = $this->httpPostJSON($this->host,$params);
  219. return $rep['result'] == 'ok' ? true : false;
  220. }
  221. /**
  222. * 用户黑名单接口
  223. * @param appId
  224. * @param cidList
  225. * @param optType 1: 增加黑名单,2:恢复加入黑名单中的cid列表
  226. * @return
  227. */
  228. private function blackCidList($appId,$cidList,$optType){
  229. $params = array();
  230. $limit = GTConfig::getMaxLenOfBlackCidList();
  231. if($limit < count($cidList)){
  232. throw new Exception("cid size:".count($cidList)." beyond the limit:".$limit);
  233. }
  234. $params["action"] = "blackCidAction";
  235. $params["appkey"] = $this->appkey;
  236. $params["appId"] = $appId;
  237. $params["cidList"] = $cidList;
  238. $params["optType"] = $optType;
  239. return $this->httpPostJSON($this->host,$params);
  240. }
  241. public function addCidListToBlk($appId,$cidList){
  242. return $this->blackCidList($appId,$cidList,1);
  243. }
  244. public function restoreCidListFromBlk($appId,$cidList){
  245. return $this->blackCidList($appId,$cidList,2);
  246. }
  247. /**
  248. * 批量推送信息
  249. * @param String contentId
  250. * @param Array <IGtTarget> targetList
  251. * @return Array {result:successed_offline,taskId:xxx} || {result:successed_online,taskId:xxx} || {result:error}
  252. ***/
  253. public function pushMessageToList($contentId, $targetList)
  254. {
  255. $params = array();
  256. $params["action"] = "pushMessageToListAction";
  257. $params["appkey"] = $this->appkey;//?
  258. $params["contentId"] = $contentId;
  259. $needDetails = GTConfig::isPushListNeedDetails();
  260. $params["needDetails"] = $needDetails;
  261. $async = GTConfig::isPushListAsync();
  262. $params["async"] = $async;
  263. if($async && (!$needDetails))
  264. {
  265. $limit = GTConfig::getAsyncListLimit();
  266. }
  267. else
  268. {
  269. $limit = GTConfig::getSyncListLimit();
  270. }
  271. if(count($targetList) > $limit)
  272. {
  273. throw new Exception("target size:".count($targetList)." beyond the limit:".$limit);
  274. }
  275. $clientIdList = array();
  276. $aliasList= array();
  277. $appId = null;
  278. foreach($targetList as $target)
  279. {
  280. $targetCid = $target->get_clientId();
  281. $targetAlias = $target->get_alias();
  282. if($targetCid != null)
  283. {
  284. array_push($clientIdList,$targetCid);
  285. }elseif($targetAlias != null)
  286. {
  287. array_push($aliasList,$targetAlias);
  288. }
  289. if($appId == null)
  290. {
  291. $appId = $target->get_appId();
  292. }
  293. }
  294. $params["appId"] = $appId;
  295. $params["clientIdList"] = $clientIdList;
  296. $params["aliasList"] = $aliasList;
  297. $params["type"] = 2;
  298. return $this->httpPostJSON($this->host,$params,true);
  299. }
  300. public function stop($contentId)
  301. {
  302. $params = array();
  303. $params["action"] = "stopTaskAction";
  304. $params["appkey"] = $this->appkey;
  305. $params["contentId"] = $contentId;
  306. $rep = $this->httpPostJSON($this->host, $params);
  307. if ("ok" == $rep["result"]) {
  308. return true;
  309. }
  310. return false;
  311. }
  312. public function getClientIdStatus($appId, $clientId)
  313. {
  314. $params = array();
  315. $params["action"] = "getClientIdStatusAction";
  316. $params["appkey"] = $this->appkey;
  317. $params["appId"] = $appId;
  318. $params["clientId"] = $clientId;
  319. return $this->httpPostJSON($this->host, $params);
  320. }
  321. public function setClientTag($appId, $clientId, $tags)
  322. {
  323. $params = array();
  324. $params["action"] = "setTagAction";
  325. $params["appkey"] = $this->appkey;
  326. $params["appId"] = $appId;
  327. $params["clientId"] = $clientId;
  328. $params["tagList"] = $tags;
  329. return $this->httpPostJSON($this->host, $params);
  330. }
  331. /**
  332. * 设置 iphone Badge
  333. * @param badge
  334. * @param appid
  335. * @param deviceTokenList
  336. * @param cidList
  337. * @return
  338. */
  339. private function setBadge($badge,$appid,$deviceTokenList,$cidList){
  340. $params = array();
  341. $params["action"] = "setBadgeAction";
  342. $params["appkey"] = $this->appkey;
  343. $params["badge"] = $badge;
  344. $params["appid"] = $appid;
  345. $params["deviceToken"] = $deviceTokenList;
  346. $params["cid"] = $cidList;
  347. return $this->httpPostJSON($this->host, $params);
  348. }
  349. public function setBadgeForCID($badge,$appid,$cidList){
  350. return $this->setBadge($badge,$appid,array(), $cidList);
  351. }
  352. public function setBadgeForDeviceToken($badge,$appid,$deviceTokenList){
  353. return $this->setBadge($badge,$appid,$deviceTokenList, array());
  354. }
  355. public function pushMessageToApp($message, $taskGroupName = null)
  356. {
  357. $contentId = $this->getListAppContentId($message, $taskGroupName);
  358. $params = array();
  359. $params["action"] = "pushMessageToAppAction";
  360. $params["appkey"] = $this->appkey;
  361. $params["contentId"] = $contentId;
  362. $params["type"] = 2;
  363. return $this->httpPostJSON($this->host,$params);
  364. }
  365. private function getListAppContentId($message, $taskGroupName = null)
  366. {
  367. $params = array();
  368. if (!is_null($taskGroupName) && trim($taskGroupName) != ""){
  369. if(strlen($taskGroupName) > 40){
  370. throw new Exception("TaskGroupName is OverLimit 40");
  371. }
  372. $params["taskGroupName"] = $taskGroupName;
  373. }
  374. $params["action"] = "getContentIdAction";
  375. $params["appkey"] = $this->appkey;
  376. $params["clientData"] = base64_encode($message->get_data()->get_transparent());
  377. $params["transmissionContent"] = $message->get_data()->get_transmissionContent();
  378. $params["isOffline"] = $message->get_isOffline();
  379. $params["offlineExpireTime"] = $message->get_offlineExpireTime();
  380. // 增加pushNetWorkType参数(0:不限;1:wifi;2:4G/3G/2G)
  381. $params["pushNetWorkType"] = $message->get_pushNetWorkType();
  382. $params["pushType"] = $message->get_data()->get_pushType();
  383. $params["type"] = 2;
  384. //contentType 1是appMessage,2是listMessage
  385. if ($message instanceof IGtListMessage){
  386. $params["contentType"] = 1;
  387. } else {
  388. $params["contentType"] = 2;
  389. $params["appIdList"] = $message->get_appIdList();
  390. $params["speed"] = $message->get_speed();
  391. //定时时间
  392. if($message->getPushTime() != null && !empty($message->getPushTime())){
  393. $params["pushTime"] = $message->getPushTime();
  394. }
  395. //$params["personaTags"]
  396. $personaTags = array();
  397. if($message->get_conditions() == null) {
  398. $params["phoneTypeList"] = $message->get_phoneTypeList();
  399. $params["provinceList"] = $message->get_provinceList();
  400. $params["tagList"] = $message->get_tagList();
  401. } else {
  402. $conditions = $message->get_conditions();
  403. $params["conditions"] = $conditions->getCondition();
  404. }
  405. }
  406. $rep = $this->httpPostJSON($this->host,$params);
  407. if($rep['result'] == 'ok')
  408. {
  409. return $rep['contentId'];
  410. }else{
  411. throw new Exception("host:[".$this->host."]" + "获取contentId失败:" . $rep);
  412. }
  413. }
  414. public function getBatch()
  415. {
  416. return new IGtBatch($this->appkey,$this);
  417. }
  418. public function pushAPNMessageToSingle($appId, $deviceToken, $message)
  419. {
  420. $params = array();
  421. $params['action'] = 'apnPushToSingleAction';
  422. $params['appId'] = $appId;
  423. $params['appkey'] = $this->appkey;
  424. $params['DT'] = $deviceToken;
  425. $params['PI'] = base64_encode($message->get_data()->get_pushInfo()->SerializeToString());
  426. return $this->httpPostJSON($this->host,$params);
  427. }
  428. /**
  429. * 根据deviceTokenList群推
  430. * @param $appId
  431. * @param $contentId
  432. * @param $deviceTokenList
  433. * @return mixed
  434. */
  435. public function pushAPNMessageToList($appId, $contentId, $deviceTokenList)
  436. {
  437. $params = array();
  438. $params["action"] = "apnPushToListAction";
  439. $params["appkey"] = $this->appkey;
  440. $params["appId"] = $appId;
  441. $params["contentId"] = $contentId;
  442. $params["DTL"] = $deviceTokenList;
  443. $needDetails = GTConfig::isPushListNeedDetails();
  444. $params["needDetails"]=$needDetails;
  445. return $this->httpPostJSON($this->host,$params);
  446. }
  447. /**
  448. * 获取apn contentId
  449. * @param $appId
  450. * @param $message
  451. * @return string
  452. */
  453. public function getAPNContentId($appId, $message)
  454. {
  455. $params = array();
  456. $params["action"] = "apnGetContentIdAction";
  457. $params["appkey"] = $this->appkey;
  458. $params["appId"] = $appId;
  459. $params["PI"] = base64_encode($message->get_data()->get_pushInfo()->SerializeToString());
  460. $rep = $this->httpPostJSON($this->host,$params);
  461. if($rep['result'] == 'ok'){
  462. return $rep['contentId'];
  463. }else{
  464. throw new Exception("host:[".$this->host."]" + "获取contentId失败:".$rep);
  465. }
  466. }
  467. public function bindAlias($appId, $alias, $clientId)
  468. {
  469. $params = array();
  470. $params["action"] = "alias_bind";
  471. $params["appkey"] = $this->appkey;
  472. $params["appid"] = $appId;
  473. $params["alias"] = $alias;;
  474. $params["cid"] = $clientId;
  475. return $this->httpPostJSON($this->host,$params);
  476. }
  477. public function bindAliasBatch($appId, $targetList)
  478. {
  479. $params = array();
  480. $aliasList = array();
  481. foreach($targetList as $target) {
  482. $user = array();
  483. $user["cid"] = $target->get_clientId();
  484. $user["alias"] = $target->get_alias();
  485. array_push($aliasList, $user);
  486. }
  487. $params["action"] = "alias_bind_list";
  488. $params["appkey"] = $this->appkey;
  489. $params["appid"] = $appId;
  490. $params["aliaslist"] = $aliasList;
  491. return $this->httpPostJSON($this->host,$params);
  492. }
  493. public function queryClientId($appId, $alias)
  494. {
  495. $params = array();
  496. $params["action"] = "alias_query";
  497. $params["appkey"] = $this->appkey;
  498. $params["appid"] = $appId;
  499. $params["alias"] = $alias;;
  500. return $this->httpPostJSON($this->host, $params);
  501. }
  502. public function queryAlias($appId, $clientId)
  503. {
  504. $params = array();
  505. $params["action"] = "alias_query";
  506. $params["appkey"] = $this->appkey;
  507. $params["appid"] = $appId;
  508. $params["cid"] = $clientId;
  509. return $this->httpPostJSON($this->host, $params);
  510. }
  511. public function unBindAlias($appId, $alias, $clientId=null)
  512. {
  513. $params = array();
  514. $params["action"] = "alias_unbind";
  515. $params["appkey"] = $this->appkey;
  516. $params["appid"] = $appId;
  517. $params["alias"] = $alias;
  518. if (!is_null($clientId) && trim($clientId) != "")
  519. {
  520. $params["cid"] = $clientId;
  521. }
  522. return $this->httpPostJSON($this->host, $params);
  523. }
  524. public function unBindAliasAll($appId, $alias)
  525. {
  526. return $this->unBindAlias($appId, $alias);
  527. }
  528. public function getPushResult( $taskId) {
  529. $params = array();
  530. $params["action"] = "getPushMsgResult";
  531. $params["appkey"] = $this->appkey;
  532. $params["taskId"] = $taskId;
  533. return $this->httpPostJson($this->host, $params);
  534. }
  535. public function getPushResultByGroupName($appId,$groupName){
  536. $params = array();
  537. $params["action"] = "getPushResultByGroupName";
  538. $params["appkey"] = $this->appkey;
  539. $params["appId"] = $appId;
  540. $params["groupName"] = $groupName;
  541. return $this->httpPostJSON($this->host, $params);
  542. }
  543. public function getLast24HoursOnlineUserStatistics($appId){
  544. $params = array();
  545. $params["action"] = "getLast24HoursOnlineUser";
  546. $params["appkey"] = $this->appkey;
  547. $params["appId"] = $appId;
  548. return $this->httpPostJSON($this->host, $params);
  549. }
  550. public function getPushResultByTaskidList( $taskIdList) {
  551. return $this->getPushActionResultByTaskids($taskIdList, null);
  552. }
  553. public function getPushActionResultByTaskids( $taskIdList, $actionIdList) {
  554. $params = array();
  555. $params["action"] = "getPushMsgResultByTaskidList";
  556. $params["appkey"] = $this->appkey;
  557. $params["taskIdList"] = $taskIdList;
  558. $params["actionIdList"] = $actionIdList;
  559. return $this->httpPostJson($this->host, $params);
  560. }
  561. public function getUserTags($appId, $clientId) {
  562. $params = array();
  563. $params["action"] = "getUserTags";
  564. $params["appkey"] = $this->appkey;
  565. $params["appId"] = $appId;
  566. $params["clientId"] = $clientId;
  567. return $this->httpPostJson($this->host, $params);
  568. }
  569. public function getUserCountByTags($appId, $tagList) {
  570. $params = array();
  571. $params["action"] = "getUserCountByTags";
  572. $params["appkey"] = $this->appkey;
  573. $params["appId"] = $appId;
  574. $params["tagList"] = $tagList;
  575. $limit = GTConfig::getTagListLimit();
  576. if(count($tagList) > $limit) {
  577. throw new Exception("tagList size:".count($tagList)." beyond the limit:".$limit);
  578. }
  579. return $this->httpPostJSON($this->host, $params);
  580. }
  581. public function getPersonaTags($appId) {
  582. $params = array();
  583. $params["action"] = "getPersonaTags";
  584. $params["appkey"] = $this->appkey;
  585. $params["appId"] = $appId;
  586. return $this->httpPostJSON($this->host, $params);
  587. }
  588. public function queryAppPushDataByDate($appId, $date){
  589. if(!LangUtils::validateDate($date)){
  590. throw new Exception("DateError|".$date);
  591. }
  592. $params = array();
  593. $params["action"] = "queryAppPushData";
  594. $params["appkey"] = $this->appkey;
  595. $params["appId"] = $appId;
  596. $params["date"] = $date;
  597. return $this->httpPostJson($this->host, $params);
  598. }
  599. public function queryAppUserDataByDate($appId, $date){
  600. if(!LangUtils::validateDate($date)){
  601. throw new Exception("DateError|".$date);
  602. }
  603. $params = array();
  604. $params["action"] = "queryAppUserData";
  605. $params["appkey"] = $this->appkey;
  606. $params["appId"] = $appId;
  607. $params["date"] = $date;
  608. return $this->httpPostJson($this->host, $params);
  609. }
  610. public function queryUserCount($appId, $appConditions) {
  611. $params = array();
  612. $params["action"] = "queryUserCount";
  613. $params["appkey"] = $this->appkey;
  614. $params["appId"] = $appId;
  615. if(!is_null($appConditions)) {
  616. $params["conditions"] = $appConditions->condition;
  617. }
  618. return $this->httpPostJson($this->host, $params);
  619. }
  620. public function pushTagMessage($message, $requestId = null) {
  621. if(!$message instanceof IGtTagMessage) {
  622. return $this->get_result("MsgTypeError");
  623. }
  624. if($requestId == null || trim($requestId) == "") {
  625. $requestId = LangUtils::randomUUID();
  626. }
  627. $params = array();
  628. $params["action"] = "pushMessageByTagAction";
  629. $params["appkey"] = $this->appkey;
  630. $params["clientData"] = base64_encode($message->get_data()->get_transparent());
  631. $params["transmissionContent"] = $message->get_data()->get_transmissionContent();
  632. $params["isOffline"] = $message->get_isOffline();
  633. $params["offlineExpireTime"] = $message->get_offlineExpireTime();
  634. $params["pushNetWorkType"] = $message->get_pushNetWorkType();
  635. $params["appIdList"] = $message->get_appIdList();
  636. $params["speed"] = $message->get_speed();
  637. $params["requestId"] = $requestId;
  638. $params["tag"] = $message->get_tag();
  639. return $this->httpPostJSON($this->host, $params);
  640. }
  641. public function pushTagMessageRetry($message) {
  642. return $this->pushTagMessage($message,null);
  643. }
  644. public function getScheduleTask($taskId,$appId){
  645. $params = array();
  646. $params["action"] = "getScheduleTaskAction";
  647. $params["appId"] = $appId;
  648. $params["appkey"] = $this->appkey;
  649. $params["taskId"] = $taskId;
  650. var_dump($this->host);
  651. return $this->httpPostJSON($this->host, $params);
  652. }
  653. public function delScheduleTask($taskId,$appId){
  654. $params = array();
  655. $params["action"] = "delScheduleTaskAction";
  656. $params["appId"] = $appId;
  657. $params["appkey"] = $this->appkey;
  658. $params["taskId"] = $taskId;
  659. return $this->httpPostJSON($this->host, $params);
  660. }
  661. public function bindCidPn($appId,$cidAndPn){
  662. $params = array();
  663. $params["action"] = "bind_cid_pn";
  664. $params["appId"] = $appId;
  665. $params["appkey"] = $this->appkey;
  666. $params["cidpnlist"] = $cidAndPn;
  667. return $this->httpPostJSON($this->host,$params);
  668. }
  669. public function unbindCidPn($appId,$cid){
  670. $params = array();
  671. $params["action"] = "unbind_cid_pn";
  672. $params["appId"] = $appId;
  673. $params["appkey"] = $this->appkey;
  674. $params["cids"] = $cid;
  675. return $this->httpPostJSON($this->host,$params);
  676. }
  677. public function queryCidPn($appId,$cid){
  678. $params = array();
  679. $params["action"] = "query_cid_pn";
  680. $params["appId"] = $appId;
  681. $params["appkey"] = $this->appkey;
  682. $params["cids"] = $cid;
  683. return $this->httpPostJSON($this->host,$params);
  684. }
  685. public function stopSendSms($appId,$taskId){
  686. $params = array();
  687. $params["action"] = "stop_sms";
  688. $params["appId"] = $appId;
  689. $params["appkey"] = $this->appkey;
  690. $params["taskId"] = $taskId;
  691. return $this->httpPostJSON($this->host,$params);
  692. }
  693. private function get_result($info) {
  694. $ret = array();
  695. $ret["result"] = $info;
  696. return $ret;
  697. }
  698. private function micro_time()
  699. {
  700. list($usec, $sec) = explode(" ", microtime());
  701. $time = ($sec . substr($usec, 2, 3));
  702. return $time;
  703. }
  704. }