Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

BlackBerry Push Development

Reply
Developer
sho3ebovich
Posts: 120
Registered: ‎12-22-2011
My Device: ---

push notification issue , please help me

 

Dears I'm trying to send push notification from php service via the following code : 

 

public function push_bb($message, $pin = 'push_all', $ad_id = null) {
  // APP ID provided by RIM
  $appid = '';
  // Password provided by RIM
  $password = '';

  //Deliver before timestamp
  $deliverbefore = gmdate('Y-m-d\TH:i:s\Z', strtotime('+5 minutes'));

  //An array of address must be in PIN format or "push_all"
  //$addresstosendto[] =  'push_all';
  //$pin = array('');
  if (is_array($pin)) {
   $addresstosendto = $pin;
  } else {
   $addresstosendto[] = $pin;
  }

  $addresses = '';

  foreach ($addresstosendto as $value) {
   $addresses .= '<address address-value="' . $value . '"/>';
  }

  // create a new cURL resource
  $err = false;
  $ch = curl_init();
  $messageid = microtime(true);

  $data = '--mPsbVQo0a68eIL3OAxnm' . "\r\n" . 'Content-Type: application/xml; charset=UTF-8' . "\r\n\r\n" . '<?xml version="1.0"?><!DOCTYPE pap PUBLIC "-//WAPFORUM//DTD PAP 2.1//EN" "http://www.openmobilealliance.org/tech/DTD/pap_2.1.dtd"><pap><push-message push-id="'.$messageid.'"  deliver-before-timestamp="' . $deliverbefore . '" source-reference="' . $appid . '">' . $addresses . '<quality-of-service delivery-method="confirmed"/></push-message></pap>' . "\r\n" . '--mPsbVQo0a68eIL3OAxnm' . "\r\n" . 'Content-Type: text/plain' . "\r\n" . 'Push-Message-ID: ' . $messageid . "\r\n\r\n" . stripslashes($message) . "\r\n" . '--mPsbVQo0a68eIL3OAxnm--' . "\n\r";


  // set URL and other appropriate options
  curl_setopt($ch, CURLOPT_URL, "https://pushapi.eval.blackberry.com/mss/PD_pushRequest");
  //curl_setopt($ch, CURLOPT_URL, "https://cp2550.pushapi.eval.blackberry.com/mss/PD_pushRequest");
  curl_setopt($ch, CURLOPT_HEADER, false);
  curl_setopt($ch, CURLOPT_USERAGENT, "Hallgren Networks BB Push Server/1.0");
  curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
  curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
  curl_setopt($ch, CURLOPT_USERPWD, $appid . ':' . $password);
  curl_setopt($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  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"));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  // grab URL and pass it to the browser
  $xmldata = curl_exec($ch);

  // close cURL resource, and free up system resources
  curl_close($ch);

  //Start parsing response into XML data that we can read and output
  $p = xml_parser_create();
  xml_parse_into_struct($p, $xmldata, $vals);
  
  $errorcode = xml_get_error_code($p);
  if ($errorcode > 0) {
   echo xml_error_string($errorcode);
   $err = true;
  }
  xml_parser_free($p);

  echo 'Our PUSH-ID: ' . $messageid . "
<br \>
\n";
  if (!$err && $vals[1]['tag'] == 'PUSH-RESPONSE') {
   echo 'PUSH-ID: ' . $vals[1]['attributes']['PUSH-ID'] . "
<br \>
\n";
   echo 'REPLY-TIME: ' . $vals[1]['attributes']['REPLY-TIME'] . "
<br \>
\n";
   echo 'Response CODE: ' . $vals[2]['attributes']['CODE'] . "
<br \>
\n";
   echo 'Response DESC: ' . $vals[2]['attributes']['DESC'] . "
<br \>
\n";
  } else {
   echo '
<p>
 An error has occured
</p>
' . "\n";
   echo 'Error CODE: ' . $vals[1]['attributes']['CODE'] . "
<br \>
\n";
   echo 'Error DESC: ' . $vals[1]['attributes']['DESC'] . "
<br \>
\n";
  }

 }

But unfortunatly , I got this error :

 

Invalid document endOur PUSH-ID: 1381159090.1309 
An error has occured

Error CODE: 
Error DESC:

 

Can any one help me what is the error ?

 

Retired
gbeukeboom
Posts: 2,559
Registered: ‎10-16-2009
My Device: BlackBerry Z10

Re: push notification issue , please help me

Check out this thread:

http://supportforums.blackberry.com/t5/BlackBerry-Push-Development/Problem-with-SEND-Push-Notificati...

 

The dev there was able to send a push using PHP :smileyhappy:

Garett
@garettBeuk
--
Goodbye everybody!
Developer
sho3ebovich
Posts: 120
Registered: ‎12-22-2011
My Device: ---

Re: push notification issue , please help me

Dear  

 

I'm trying to use the same code posted on the link you posted in the previous reply ,

and adding new lines but i still get 

 

Our PUSH-ID: 1381237403.2695
An XML parser error has occured

Invalid document end
Response

 

the code i used 

public function sendNotificationBlackBerry($registatoin_tokens, $message) {
$appid = '2550-53737re03i2O7651e5c79i252597aa6s4B6'; // 4038-8si785997a3eir572168c5f821291rl8a84
//$password = 'Ja50N4Hu1d';
$password = 'dsvoolM5';
$boundary = "JcX58MAjkOhziP7";
$boundary = "mPsbVQo0a68eIL3OAxnm";
$appport = "33872";
$deliverbefore = gmdate('Y-m-d\TH:i:s\Z', strtotime('+2 minutes'));
//An array of address must be in PIN format or "push_all"
$addresses = '';
foreach ($registatoin_tokens as $value) {
$addresses .= '<address address-value=' . $value . '/>';
}
// create a new cURL resource
$ch = curl_init();
$messageid = microtime(true);
$data = '--' . $boundary . "\r\n" .
'<?xml version="1.0" charset="UTF-8"?>
<!DOCTYPE pap PUBLIC "-//WAPFORUM//DTD PAP 2.1//EN" "http://www.openmobilealliance.org/tech/DTD/pap_2.1.dtd">
<pap>
<push-message push-id="' . $messageid . '" source-reference="' . $appid . '" deliver-before-timestamp="' . $deliverbefore . '">'
. $addresses .
'<quality-of-service delivery-method="confirmed"/>
</push-message>
</pap>' . "\r\n" .
'--' . $boundary . "\r\n" .
'Content-Type: text/plain' . "\r\n\n" .
'Push-Message-ID: ' . $messageid . "\r\n\r\n" .
stripslashes($message) . "\r\n\n" .
'--' . $boundary . '--' . "\n\r";
// set URL and other appropriate options
// curl_setopt($ch, CURLOPT_URL, "https://pushapi.eval.blackberry.com/mss/PD_pushRequest"); //Erro code 2000 The request is invalid.
curl_setopt($ch, CURLOPT_URL, "https://cp2550.pushapi.eval.blackberry.com/mss/PD_pushRequest"); // Error CODE: 2000
// curl_setopt($ch, CURLOPT_URL, "https://pushapi.eval.blackberry.com"); // Invalid document end
// curl_setopt($ch, CURLOPT_URL, "https://cp2550.pushapi.eval.blackberry.com"); //Invalid document end
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_USERAGENT, "SAA push application");
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, $appid . ':' . $password);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: multipart/related; boundary=" . $boundary . "; type=application/xml", "Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2", "Connection: keep-alive"));
// grab URL and pass it to the browser
$xmldata = curl_exec($ch);
curl_close($ch);
 
//-----------------------------
//Start parsing response into XML data that we can read and output
$p = xml_parser_create();
xml_parse_into_struct($p, $xmldata, $vals);
$errorcode = xml_get_error_code($p);
if ($errorcode > 0) {
$err = true;
}
xml_parser_free($p);
echo 'Our PUSH-ID: ' . $messageid . "<br \>\n";
if (!$err && $vals[1]['tag'] == 'PUSH-RESPONSE') {
echo 'PUSH-ID: ' . $vals[1]['attributes']['PUSH-ID'] . "<br \>\n";
echo 'REPLY-TIME: ' . $vals[1]['attributes']['REPLY-TIME'] . "<br \>\n";
echo 'Response CODE: ' . $vals[2]['attributes']['CODE'] . "<br \>\n";
echo 'Response DESC: ' . $vals[2]['attributes']['DESC'] . "<br \> \n";
} elseif ($err) {
echo '<p>An XML parser error has occured</p>' . "\n";
echo '<pre>' . xml_error_string($errorcode) . "</pre>\n";
echo '<p>Response</p>' . "\n";
echo '<pre>' . $xmldata . '</pre>' . "\n";
} else {
echo '<p>An error has occured</p>' . "\n";
echo 'Error CODE: ' . $vals[1]['attributes']['CODE'] . "<br \>\n";
echo 'Error DESC: ' . $vals[1]['attributes']['DESC'] . "<br \>\n";
echo '<pre>' . $xmldata . '</pre>' . "\n";
var_dump($xmldata);
}
// -----------------------------
 
return $xmldata;
}

 

please help me 

Retired
gbeukeboom
Posts: 2,559
Registered: ‎10-16-2009
My Device: BlackBerry Z10

Re: push notification issue , please help me

What is the exact XML produced by your code?

Garett
@garettBeuk
--
Goodbye everybody!
Developer
sho3ebovich
Posts: 120
Registered: ‎12-22-2011
My Device: ---

Re: push notification issue , please help me

after invoking the function and print the returned xml i got respone an empty String

Retired
gbeukeboom
Posts: 2,559
Registered: ‎10-16-2009
My Device: BlackBerry Z10

Re: push notification issue , please help me

What is the XML you are trying to post? If that is empty then I would focus on fixing that first.

Garett
@garettBeuk
--
Goodbye everybody!
Developer
sho3ebovich
Posts: 120
Registered: ‎12-22-2011
My Device: ---

Re: push notification issue , please help me

i'm trying to send this text :

 

sendNotificationBlackBerry('2830384D','test');

Retired
gbeukeboom
Posts: 2,559
Registered: ‎10-16-2009
My Device: BlackBerry Z10

Re: push notification issue , please help me

I'm looking for the contents of the $data object. Did you write this code? If not I would recommend asking for support from the author.

Garett
@garettBeuk
--
Goodbye everybody!
Developer
sho3ebovich
Posts: 120
Registered: ‎12-22-2011
My Device: ---

Re: push notification issue , please help me

the $data content 

 

--mPsbVQo0a68eIL3OAxnm
Content-Type: text/plain

Push-Message-ID: 1381242549.5734

test

--mPsbVQo0a68eIL3OAxnm

 

Retired
gbeukeboom
Posts: 2,559
Registered: ‎10-16-2009
My Device: BlackBerry Z10

Re: push notification issue , please help me

That's missing most of the required data. It should resemble this:

http://docs.blackberry.com/en/developers/deliverables/25167/Code_sample_push_request_604335_11.jsp

Garett
@garettBeuk
--
Goodbye everybody!