PushApiTest.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. <?php
  2. require_once(dirname(__FILE__) . '/' . '../GTClient.php');
  3. define("APPKEY","*");
  4. define("APPID","*");
  5. define("MS","*");
  6. define("URL","*");
  7. define("CID1","*");
  8. define("CID2","*");
  9. define("CID3","*");
  10. $token = null;
  11. $taskId = null;
  12. $api = new GTClient(URL,APPKEY,APPID,MS);
  13. pushToSingleByCid();
  14. //pushToSingleByAlias();
  15. //pushBatchByCid();
  16. //pushBatchByAlias();
  17. //createListMsg();
  18. //pushListByCid();
  19. //pushListByAlias();
  20. //pushAll();
  21. //pushByTag();
  22. //pushByFastCustomTag();
  23. //stoppushApi();
  24. //queryScheduleTask();
  25. //deleteScheduleTask();
  26. function pushToSingleByCid(){
  27. $push = getParam();
  28. $push->setCid(CID3);
  29. global $api;
  30. echo json_encode($api->pushApi()->pushToSingleByCid($push));
  31. }
  32. function pushToSingleByAlias(){
  33. $push = getParam();
  34. $push->setAlias("cccc");
  35. global $api;
  36. echo json_encode($api->pushApi()->pushToSingleByAlias($push));
  37. }
  38. function pushBatchByCid(){
  39. $batch = new GTPushBatchRequest();
  40. $push = getParam();
  41. $push->setCid(CID3);
  42. // $push1 = getParam();
  43. // $push1->setCid(CID1);
  44. $batch->setMsgList(array($push));
  45. // $batch->addMsgList($push1);
  46. $batch->setIsAsync(false);
  47. global $api;
  48. echo json_encode($api->pushApi()->pushBatchByCid($batch));
  49. }
  50. function pushBatchByAlias(){
  51. $batch = new GTPushBatchRequest();
  52. $push = getParam();
  53. $push->setAlias("cccc");
  54. $batch->addMsgList($push);
  55. $batch->setIsAsync(true);
  56. global $api;
  57. echo json_encode($api->pushApi()->pushBatchByAlias($batch));
  58. }
  59. function createListMsg(){
  60. $push = getParam();
  61. $push->setGroupName("1202test");
  62. global $api;
  63. echo json_encode($api->pushApi()->createListMsg($push));
  64. }
  65. function pushListByCid(){
  66. $user = new GTAudienceRequest();
  67. $user->setIsAsync(true);
  68. $user->setTaskid("taskid");
  69. $user->setCidList(array(CID3));
  70. global $api;
  71. echo json_encode($api->pushApi()->pushListByCid($user));
  72. }
  73. function pushListByAlias(){
  74. $user = new GTAudienceRequest();
  75. $user->setIsAsync(true);
  76. $user->setTaskid("taskid");
  77. $user->setAliasList(array("cccc"));
  78. global $api;
  79. echo json_encode($api->pushApi()->pushListByAlias($user));
  80. }
  81. function pushAll(){
  82. $push = getParam();
  83. $push->setGroupName("test");
  84. global $api;
  85. echo json_encode($api->pushApi()->pushAll($push));
  86. }
  87. function pushByTag(){
  88. $push = getParam();
  89. $tag1 = new GTCondition();
  90. $tag1->setOptType("and");
  91. $tag1->setKey("phone_type");
  92. $tag1->setValues(array("IOS"));
  93. $push->setTagList(array($tag1));
  94. global $api;
  95. echo json_encode($api->pushApi()->pushByTag($push));
  96. }
  97. function pushByFastCustomTag(){
  98. $push = getParam();
  99. $push->setFastCustomTag("tag2");
  100. global $api;
  101. echo json_encode($api->pushApi()->pushByFastCustomTag($push));
  102. }
  103. function stoppushApi(){
  104. global $api;
  105. echo json_encode($api->pushApi()->stopPush("taskid"));
  106. }
  107. function queryScheduleTask(){
  108. global $api;
  109. echo json_encode($api->pushApi()->queryScheduleTask("taskid"));
  110. }
  111. function deleteScheduleTask(){
  112. global $api,$tasId;
  113. echo json_encode($api->pushApi()->deleteScheduleTask("taskid"));
  114. }
  115. function getParam(){
  116. $push = new GTPushRequest();
  117. $push->setRequestId(micro_time());
  118. //设置setting
  119. $set = new GTSettings();
  120. $set->setTtl(3600000);
  121. // $set->setSpeed(1000);
  122. // $set->setScheduleTime(1591794372930);
  123. $strategy = new GTStrategy();
  124. $strategy->setDefault(GTStrategy::STRATEGY_THIRD_FIRST);
  125. // $strategy->setIos(GTStrategy::STRATEGY_GT_ONLY);
  126. // $strategy->setOp(GTStrategy::STRATEGY_THIRD_FIRST);
  127. // $strategy->setHw(GTStrategy::STRATEGY_THIRD_ONLY);
  128. $set->setStrategy($strategy);
  129. $push->setSettings($set);
  130. //设置PushMessage,
  131. $message = new GTPushMessage();
  132. //通知
  133. $notify = new GTNotification();
  134. $notify->setTitle("notdifyddd");
  135. $notify->setBody("notify bdoddy");
  136. $notify->setBigText("bigTdext");
  137. //与big_text二选一
  138. // $notify->setBigImage("BigImage");
  139. $notify->setLogo("push.png");
  140. $notify->setLogoUrl("LogoUrl");
  141. $notify->setChannelId("Default");
  142. $notify->setChannelName("Default");
  143. $notify->setChannelLevel(2);
  144. $notify->setClickType("none");
  145. $notify->setIntent("intent:#Intent;component=你的包名/你要打开的 activity 全路径;S.parm1=value1;S.parm2=value2;end");
  146. $notify->setUrl("url");
  147. $notify->setPayload("Payload");
  148. $notify->setNotifyId(22334455);
  149. $notify->setRingName("ring_name");
  150. $notify->setBadgeAddNum(1);
  151. // $message->setNotification($notify);
  152. //透传 ,与通知、撤回三选一
  153. $message->setTransmission("试试透传");
  154. //撤回
  155. $revoke = new GTRevoke();
  156. $revoke->setForce(true);
  157. $revoke->setOldTaskId("taskId");
  158. // $message->setRevoke($revoke);
  159. $push->setPushMessage($message);
  160. $message->setDuration("1590547347000-1590633747000");
  161. //厂商推送消息参数
  162. $pushChannel = new GTPushChannel();
  163. //ios
  164. $ios = new GTIos();
  165. $ios->setType("notify");
  166. $ios->setAutoBadge("1");
  167. $ios->setPayload("ios_payload");
  168. $ios->setApnsCollapseId("apnsCollapseId");
  169. //aps设置
  170. $aps = new GTAps();
  171. $aps->setContentAvailable(0);
  172. $aps->setSound("com.gexin.ios.silenc");
  173. $aps->setCategory("category");
  174. $aps->setThreadId("threadId");
  175. $alert = new GTAlert();
  176. $alert->setTitle("alert title");
  177. $alert->setBody("alert body");
  178. $alert->setActionLocKey("ActionLocKey");
  179. $alert->setLocKey("LocKey");
  180. $alert->setLocArgs(array("LocArgs1","LocArgs2"));
  181. $alert->setLaunchImage("LaunchImage");
  182. $alert->setTitleLocKey("TitleLocKey");
  183. $alert->setTitleLocArgs(array("TitleLocArgs1","TitleLocArgs2"));
  184. $alert->setSubtitle("Subtitle");
  185. $alert->setSubtitleLocKey("SubtitleLocKey");
  186. $alert->setSubtitleLocArgs(array("subtitleLocArgs1","subtitleLocArgs2"));
  187. $aps->setAlert($alert);
  188. $ios->setAps($aps);
  189. $multimedia = new GTMultimedia();
  190. $multimedia->setUrl("url");
  191. $multimedia->setType(1);
  192. $multimedia->setOnlyWifi(false);
  193. $multimedia2 = new GTMultimedia();
  194. $multimedia2->setUrl("url2");
  195. $multimedia2->setType(2);
  196. $multimedia2->setOnlyWifi(true);
  197. $ios->setMultimedia(array($multimedia));
  198. $ios->addMultimedia($multimedia2);
  199. $pushChannel->setIos($ios);
  200. //安卓
  201. $android = new GTAndroid();
  202. $ups = new GTUps();
  203. // $ups->setTransmission("ups Transmission");
  204. $thirdNotification = new GTThirdNotification();
  205. $thirdNotification->setTitle("title".micro_time());
  206. $thirdNotification->setBody("body".micro_time());
  207. $thirdNotification->setClickType(GTThirdNotification::CLICK_TYPE_URL);
  208. $thirdNotification->setIntent("intent:#Intent;component=你的包名/你要打开的 activity 全路径;S.parm1=value1;S.parm2=value2;end");
  209. $thirdNotification->setUrl("http://docs.getui.com/getui/server/rest_v2/push/");
  210. $thirdNotification->setPayload("payload");
  211. $thirdNotification->setNotifyId(456666);
  212. $ups->addOption("HW","badgeAddNum",1);
  213. $ups->addOption("OP","channel","Default");
  214. $ups->addOption("OP","aaa","bbb");
  215. $ups->addOption(null,"a","b");
  216. $ups->setNotification($thirdNotification);
  217. $android->setUps($ups);
  218. $pushChannel->setAndroid($android);
  219. $push->setPushChannel($pushChannel);
  220. return $push;
  221. }
  222. function micro_time()
  223. {
  224. list($usec, $sec) = explode(" ", microtime());
  225. $time = ($sec . substr($usec, 2, 3));
  226. return $time;
  227. }