demo.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. <?php
  2. require_once ('XingeApp.php');
  3. var_dump(DemoPushSingleDeviceNotification());
  4. // var_dump(DemoPushSingleDeviceMessage());
  5. // var_dump(DemoPushSingleDeviceIOS());
  6. // var_dump(DemoPushSingleAccount());
  7. // var_dump(DemoPushAccountList());
  8. // var_dump(DemoPushSingleAccountIOS());
  9. // var_dump(DemoPushAllDevices());
  10. // var_dump(DemoPushTags());
  11. // var_dump(DemoQueryPushStatus());
  12. // var_dump(DemoQueryDeviceCount());
  13. // var_dump(DemoQueryTags());
  14. // var_dump(DemoQueryTagTokenNum());
  15. // var_dump(DemoQueryTokenTags());
  16. // var_dump(DemoCancelTimingPush());
  17. // var_dump(DemoBatchDelTag());
  18. // var_dump(DemoBatchSetTag());
  19. // var_dump(DemoPushAccountListMultipleNotification());
  20. // var_dump(DemoPushDeviceListMultipleNotification());
  21. // var_dump(DemoQueryInfoOfToken());
  22. // var_dump(DemoQueryTokensOfAccount());
  23. // var_dump(DemoDeleteTokenOfAccount());
  24. // var_dump(DemoDeleteAllTokensOfAccount());
  25. //单个设备下发通知消息
  26. function DemoPushSingleDeviceNotification()
  27. {
  28. $push = new XingeApp(000, 'secret_key');
  29. $mess = new Message();
  30. $mess->setType(Message::TYPE_NOTIFICATION);
  31. $mess->setTitle("title");
  32. $mess->setContent("中午");
  33. $mess->setExpireTime(86400);
  34. //$style = new Style(0);
  35. #含义:样式编号0,响铃,震动,不可从通知栏清除,不影响先前通知
  36. $style = new Style(0,1,1,0,0);
  37. $action = new ClickAction();
  38. $action->setActionType(ClickAction::TYPE_URL);
  39. $action->setUrl("http://xg.qq.com");
  40. #打开url需要用户确认
  41. $action->setComfirmOnUrl(1);
  42. $custom = array('key1'=>'value1', 'key2'=>'value2');
  43. $mess->setStyle($style);
  44. $mess->setAction($action);
  45. $mess->setCustom($custom);
  46. $acceptTime1 = new TimeInterval(0, 0, 23, 59);
  47. $mess->addAcceptTime($acceptTime1);
  48. $ret = $push->PushSingleDevice('token', $mess);
  49. return($ret);
  50. }
  51. //单个设备下发透传消息 注:透传消息默认不展示
  52. function DemoPushSingleDeviceMessage()
  53. {
  54. $push = new XingeApp(000, 'secret_key');
  55. $mess = new Message();
  56. $mess->setTitle('title');
  57. $mess->setContent('content');
  58. $mess->setType(Message::TYPE_MESSAGE);
  59. $ret = $push->PushSingleDevice('token', $mess);
  60. return $ret;
  61. }
  62. //下发IOS设备消息
  63. function DemoPushSingleDeviceIOS()
  64. {
  65. $push = new XingeApp(000, 'secret_key');
  66. $mess = new MessageIOS();
  67. $mess->setExpireTime(86400);
  68. //$mess->setSendTime("2014-03-13 16:00:00");
  69. $mess->setAlert("ios test");
  70. //$mess->setAlert(array('key1'=>'value1'));
  71. $mess->setBadge(1);
  72. $mess->setSound("beep.wav");
  73. $custom = array('key1'=>'value1', 'key2'=>'value2');
  74. $mess->setCustom($custom);
  75. $acceptTime = new TimeInterval(0, 0, 23, 59);
  76. $mess->addAcceptTime($acceptTime);
  77. $raw = '{"xg_max_payload":1,"accept_time":[{"start":{"hour":"20","min":"0"},"end":{"hour":"23","min":"59"}}],"aps":{"alert":"="}}';
  78. $mess->setRaw($raw);
  79. $ret = $push->PushSingleDevice('token', $mess, XingeApp::IOSENV_DEV);
  80. return $ret;
  81. }
  82. //单个设备下发通知Intent
  83. //setIntent()的内容需要使用intent.toUri(Intent.URI_INTENT_SCHEME)方法来得到序列化后的Intent(自定义参数也包含在Intent内)
  84. //终端收到后通过intent.parseUri()来反序列化得到Intent
  85. function DemoPushSingleDeviceNotificationIntent()
  86. {
  87. $push = new XingeApp(000, 'secret_key');
  88. $mess = new Message();
  89. $mess->setExpireTime(86400);
  90. $mess->setType(Message::TYPE_NOTIFICATION);
  91. $mess->setTitle("title");
  92. $mess->setContent("通知点击执行Intent测试");
  93. $style = new Style(0);
  94. $style = new Style(0,1,1,0);
  95. $action = new ClickAction();
  96. $action->setActionType(ClickAction::TYPE_INTENT);
  97. $action->setIntent('intent:10086#Intent;scheme=tel;action=android.intent.action.DIAL;S.key=value;end');
  98. $mess->setStyle($style);
  99. $mess->setAction($action);
  100. $ret = $push->PushSingleDevice('token', $mess);
  101. return($ret);
  102. }
  103. //下发单个账号
  104. function DemoPushSingleAccount()
  105. {
  106. $push = new XingeApp(000, 'secret_key');
  107. $mess = new Message();
  108. $mess->setExpireTime(86400);
  109. $mess->setTitle('title');
  110. $mess->setContent('content');
  111. $mess->setType(Message::TYPE_MESSAGE);
  112. $ret = $push->PushSingleAccount(0, 'joelliu', $mess);
  113. return ($ret);
  114. }
  115. //下发多个账号, IOS下发多个账号参考DemoPushSingleAccountIOS进行相应修改
  116. function DemoPushAccountList()
  117. {
  118. $push = new XingeApp(000, 'secret_key');
  119. $mess = new Message();
  120. $mess->setExpireTime(86400);
  121. $mess->setTitle('title');
  122. $mess->setContent('content');
  123. $mess->setType(Message::TYPE_MESSAGE);
  124. $accountList = array('joelliu');
  125. $ret = $push->PushAccountList(0, $accountList, $mess);
  126. return ($ret);
  127. }
  128. //下发IOS账号消息
  129. function DemoPushSingleAccountIOS()
  130. {
  131. $push = new XingeApp(000, 'secret_key');
  132. $mess = new MessageIOS();
  133. $mess->setExpireTime(86400);
  134. $mess->setAlert("ios test");
  135. //$mess->setAlert(array('key1'=>'value1'));
  136. $mess->setBadge(1);
  137. $mess->setSound("beep.wav");
  138. $custom = array('key1'=>'value1', 'key2'=>'value2');
  139. $mess->setCustom($custom);
  140. $acceptTime1 = new TimeInterval(0, 0, 23, 59);
  141. $mess->addAcceptTime($acceptTime1);
  142. $ret = $push->PushSingleAccount(0, 'joelliu', $mess, XingeApp::IOSENV_DEV);
  143. return $ret;
  144. }
  145. //下发所有设备
  146. function DemoPushAllDevices()
  147. {
  148. $push = new XingeApp(000, 'secret_key');
  149. $mess = new Message();
  150. $mess->setType(Message::TYPE_NOTIFICATION);
  151. $mess->setTitle("title");
  152. $mess->setContent("中午");
  153. $mess->setExpireTime(86400);
  154. $style = new Style(0);
  155. #含义:样式编号0,响铃,震动,不可从通知栏清除,不影响先前通知
  156. $style = new Style(0,1,1,0,0);
  157. $action = new ClickAction();
  158. $action->setActionType(ClickAction::TYPE_URL);
  159. $action->setUrl("http://xg.qq.com");
  160. #打开url需要用户确认
  161. $action->setComfirmOnUrl(1);
  162. $mess->setStyle($style);
  163. $mess->setAction($action);
  164. $ret = $push->PushAllDevices(0, $mess);
  165. return ($ret);
  166. }
  167. //下发标签选中设备
  168. function DemoPushTags()
  169. {
  170. $push = new XingeApp(000, 'secret_key');
  171. $mess = new Message();
  172. $mess->setExpireTime(86400);
  173. $mess->setTitle('title');
  174. $mess->setContent('content');
  175. $mess->setType(Message::TYPE_MESSAGE);
  176. $tagList = array('Demo3');
  177. $ret = $push->PushTags(0, $tagList, 'OR', $mess);
  178. return ($ret);
  179. }
  180. //查询消息推送状态
  181. function DemoQueryPushStatus()
  182. {
  183. $push = new XingeApp(000, 'secret_key');
  184. $pushIdList = array('31','32');
  185. $ret = $push->QueryPushStatus($pushIdList);
  186. return ($ret);
  187. }
  188. //查询设备数量
  189. function DemoQueryDeviceCount()
  190. {
  191. $push = new XingeApp(000, 'secret_key');
  192. $ret = $push->QueryDeviceCount();
  193. return ($ret);
  194. }
  195. //查询标签
  196. function DemoQueryTags()
  197. {
  198. $push = new XingeApp(000, 'secret_key');
  199. $ret = $push->QueryTags(0,100);
  200. return ($ret);
  201. }
  202. //查询某个tag下token的数量
  203. function DemoQueryTagTokenNum()
  204. {
  205. $push = new XingeApp(000, 'secret_key');
  206. $ret = $push->QueryTagTokenNum("tag");
  207. return ($ret);
  208. }
  209. //查询某个token的标签
  210. function DemoQueryTokenTags()
  211. {
  212. $push = new XingeApp(000, 'secret_key');
  213. $ret = $push->QueryTokenTags("token");
  214. return ($ret);
  215. }
  216. //取消定时任务
  217. function DemoCancelTimingPush()
  218. {
  219. $push = new XingeApp(000, 'secret_key');
  220. $ret = $push->CancelTimingPush("32");
  221. return ($ret);
  222. }
  223. // 设置标签
  224. function DemoBatchSetTag() {
  225. // 切记把这里的示例tag和示例token修改为你的真实tag和真实token
  226. $pairs = array();
  227. array_push($pairs, new TagTokenPair("tag1","token00000000000000000000000000000000001"));
  228. array_push($pairs, new TagTokenPair("tag1","token00000000000000000000000000000000001"));
  229. $push = new XingeApp(000, 'secret_key');
  230. $ret = $push->BatchSetTag($pairs);
  231. return $ret;
  232. }
  233. // 删除标签
  234. function DemoBatchDelTag() {
  235. // 切记把这里的示例tag和示例token修改为你的真实tag和真实token
  236. $pairs = array();
  237. array_push($pairs, new TagTokenPair("tag1","token00000000000000000000000000000000001"));
  238. array_push($pairs, new TagTokenPair("tag1","token00000000000000000000000000000000001"));
  239. $push = new XingeApp(000, 'secret_key');
  240. $ret = $push->BatchDelTag($pairs);
  241. return $ret;
  242. }
  243. //大批量下发给账号 android
  244. //iOS 请构建MessageIOS 消息
  245. function DemoPushAccountListMultipleNotification()
  246. {
  247. $push = new XingeApp(000, 'secret_key');
  248. $mess = new Message();
  249. $mess->setExpireTime(86400);
  250. $mess->setTitle('title');
  251. $mess->setContent('content');
  252. $mess->setType(Message::TYPE_NOTIFICATION);
  253. $ret = $push->CreateMultipush($mess, XingeApp::IOSENV_DEV);
  254. if (!($ret['ret_code'] === 0))
  255. return $ret;
  256. else
  257. {
  258. $result=array();
  259. $accountList1 = array('joelliu', 'joelliu2', 'joelliu3');
  260. array_push($result, $push->PushAccountListMultiple($ret['result']['push_id'], $accountList1));
  261. $accountList2 = array('joelliu4', 'joelliu5', 'joelliu6');
  262. array_push($result, $push->PushAccountListMultiple($ret['result']['push_id'], $accountList2));
  263. return ($result);
  264. }
  265. }
  266. //大批量下发给设备 android
  267. //iOS 请构建MessageIOS 消息
  268. function DemoPushDeviceListMultipleNotification()
  269. {
  270. $push = new XingeApp(000, 'secret_key');
  271. $mess = new Message();
  272. $mess->setExpireTime(86400);
  273. $mess->setTitle('title');
  274. $mess->setContent('content');
  275. $mess->setType(Message::TYPE_NOTIFICATION);
  276. $ret = $push->CreateMultipush($mess, XingeApp::IOSENV_DEV);
  277. if (!($ret['ret_code'] === 0))
  278. return $ret;
  279. else
  280. {
  281. $result=array();
  282. $deviceList1 = array('token1', 'token2', 'token3');
  283. array_push($result, $push->PushDeviceListMultiple($ret['result']['push_id'], $deviceList1));
  284. $deviceList2 = array('token4', 'token5', 'token6');
  285. array_push($result, $push->PushDeviceListMultiple($ret['result']['push_id'], $deviceList2));
  286. return ($result);
  287. }
  288. }
  289. //查询某个token的信息
  290. function DemoQueryInfoOfToken()
  291. {
  292. $push = new XingeApp(000, 'secret_key');
  293. $ret = $push->QueryInfoOfToken("token");
  294. return ($ret);
  295. }
  296. //查询某个account绑定的token
  297. function DemoQueryTokensOfAccount()
  298. {
  299. $push = new XingeApp(000, 'secret_key');
  300. $ret = $push->QueryTokensOfAccount("nickName");
  301. return ($ret);
  302. }
  303. //删除某个account绑定的所有token
  304. function DemoDeleteAllTokensOfAccount()
  305. {
  306. $push = new XingeApp(000, 'secret_key');
  307. $ret = $push->DeleteAllTokensOfAccount("nickName");
  308. return ($ret);
  309. }