Advertisement
anta40

push.php

Jul 16th, 2012
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.06 KB | None | 0 0
  1.  <?php
  2. ini_set('display_errors','1');
  3. error_reporting(E_ALL);
  4.  
  5. // APP ID provided by RIM
  6. $appid = '2717-685030D1411044r3352cc2ele73eshh6256';
  7. // Password provided by RIM
  8. $password = 'Tny8mm7o44';
  9.  
  10. //Deliver before timestamp
  11. $deliverbefore = gmdate('Y-m-d\TH:i:s\Z', strtotime('+15 minutes'));
  12.  
  13. //An array of address must be in PIN format or "push_all"
  14. $addresstosendto[] = 'push_all';
  15.  
  16. $addresses = '';
  17. foreach ($addresstosendto as $value) {
  18. $addresses .= '<address address-value="' . $value . '"/>';
  19. }
  20.  
  21. // create a new cURL resource
  22. $err = false;
  23. $ch = curl_init();
  24. $messageid = "Message @ ".microtime(true);
  25.  
  26. $data = '--mPsbVQo0a68eIL3OAxnm'. "\r\n" .
  27. 'Content-Type: application/xml; charset=UTF-8' . "\r\n\r\n" .
  28. '<?xml version="1.0"?>
  29. <!DOCTYPE pap PUBLIC "-//WAPFORUM//DTD PAP 2.1//EN" "http://www.openmobilealliance.org/tech/DTD/pap_2.1.dtd">
  30. <pap>
  31. <push-message push-id="' . $messageid . '" deliver-before-timestamp="' . $deliverbefore . '" source-reference="' . $appid . '">'
  32. . $addresses .
  33. '<quality-of-service delivery-method="confirmed"/>
  34. </push-message>
  35. </pap>' . "\r\n" .
  36. '--mPsbVQo0a68eIL3OAxnm' . "\r\n" .
  37. 'Content-Type: text/plain' . "\r\n" .
  38. 'Push-Message-ID: ' . $messageid . "\r\n\r\n" .
  39. stripslashes('This is my message') . "\r\n" .
  40. '--mPsbVQo0a68eIL3OAxnm--' . "\n\r";
  41.  
  42. // set URL and other appropriate options
  43. curl_setopt($ch, CURLOPT_URL, "https://pushapi.eval.blackberry.com/mss/PD_pushRequest");
  44. curl_setopt($ch, CURLOPT_HEADER, false);
  45. curl_setopt($ch, CURLOPT_USERAGENT, "Hallgren Networks BB Push Server/1.0");
  46. curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
  47. curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
  48. curl_setopt($ch, CURLOPT_USERPWD, $appid . ':' . $password);
  49. curl_setopt($ch, CURLOPT_POST, 1);
  50. curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  51. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  52. curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: multipart/related; boundary=mPsbVQo0a68eIL3OAxnm; type=application/xml", "Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2", "Connection: keep-alive"));
  53.  
  54. // grab URL and pass it to the browser
  55. echo $xmldata = curl_exec($ch);
  56.  
  57. // close cURL resource, and free up system resources
  58. curl_close($ch);
  59.  
  60. //Start parsing response into XML data that we can read and output
  61. $p = xml_parser_create();
  62. xml_parse_into_struct($p, $xmldata, $vals);
  63. $errorcode = xml_get_error_code($p);
  64. if ($errorcode > 0) {
  65. echo xml_error_string($errorcode);
  66. $err = true;
  67. }
  68. xml_parser_free($p);
  69.  
  70. echo 'Our PUSH-ID: ' . $messageid . "<br \>\n";
  71. if (!$err && $vals[1]['tag'] == 'PUSH-RESPONSE') {
  72. echo 'PUSH-ID: ' . $vals[1]['attributes']['PUSH-ID'] . "<br \>\n";
  73. echo 'REPLY-TIME: ' . $vals[1]['attributes']['REPLY-TIME'] . "<br \>\n";
  74. echo 'Response CODE: ' . $vals[2]['attributes']['CODE'] . "<br \>\n";
  75. echo 'Response DESC: ' . $vals[2]['attributes']['DESC'] . "<br \> \n";
  76. } else {
  77. echo '<p>An error has occured</p>' . "\n";
  78. echo 'Error CODE: ' . $vals[1]['attributes']['CODE'] . "<br \>\n";
  79. echo 'Error DESC: ' . $vals[1]['attributes']['DESC'] . "<br \>\n";
  80. }
  81.  
  82.  
  83. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement