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
New Developer
Posts: 46
Registered: ‎07-05-2010
My Device: 9630
My Carrier: Telus

Re: Cannot send PHP Push message using Blackberry Push Essentials service

I did a test like your test using CShap to send a PAP push to PPG, in this test I used the Application ID, Pwd supplied by RIM push service as user name and password and the Source IP is a static IP registered to RIM push service, I got the Access Forbidden Error when I sent a push request to URL:"https://pushapi.eval.blackberry.com/mss/PD_pushRequest".

Somebody can explain why as an evaluation site, there is this problem for basic test.

Developer
Posts: 137
Registered: ‎09-30-2009
My Device: Torch 9800

Re: Cannot send PHP Push message using Blackberry Push Essentials service

@shendz

Were you able to do the registration process from PHP? I could post data to push server but not sure how to subscribe

----------------------
Press like if you find a message helpful
---------
Visitor
Posts: 1
Registered: ‎12-10-2010
My Device: Curve 8520
My Carrier: AIRTEL

Re: Cannot send PHP Push message using Blackberry Push Essentials service

Hi

 

I am also using similar code and getting same error "Invalid Document End"

 

Here is the code which I used :

<?php

  //PAP URL
  $papURL = "https://pushapi.eval.blackberry.com";
  //$papURL = "https://pushapi.eval.blackberry.com/mss/PD_pushReq?uest";

  // APP ID provided by RIM
  $appid = '<App Id provided by RIM>';
		
  // Password provided by RIM
  $password = '<pwd provided by RIM >';

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

  $BBPin = "<Blackberry mobile pin no>";

  $Msg = "Hi, This is Blackberry Push Message Test from PHP Script";

  //boundry
  $boundry = "asdlfkjiurwghasf";

  //An array of address must be in PIN format or "push_all" Commented for testing single mobile device
  //$addresstosendto[] = '';
  //$addresses = '';
  //foreach ($addresstosendto as $value) {
  //$addresses .= '<address address-value="' . $value . '"/>';
  //}
		
  //$addresses = '<address address-value="' . $BBPin . '"/>';
  $addresses = '<address address-value="WAPPUSH='. $BBPin .'%3A100/TYPE=USER@rim.net"/>';

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

  $data = '--' . $boundry . "\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" [<?wap-pap-ver supported-versions="2.1,2.0,1.*"?>]>' .
  '<pap>' .
  '<push-message push-id="' . $messageid . '" deliver-before- timestamp="' . $deliverbefore . '" source-reference="' . $appid . '">'
  . $addresses .
  '<quality-of-service delivery-method="unconfirmed"/>' .
  '</push-message>' .
  '</pap>' . "\r\n" .
  '--' . $boundry . "\r\n" .
  'Content-Type: text/plain' . "\r\n" .
  'Push-Message-ID: ' . $messageid . "\r\n\r\n" .
  stripslashes($Msg) . "\r\n" .
  '--' . $boundry . '--' . "\r\n";
		

  // set URL and other appropriate options
  curl_setopt($ch, CURLOPT_URL, $papURL);
  curl_setopt($ch, CURLOPT_HEADER, false);
  curl_setopt($ch, CURLOPT_USERAGENT, "HashMe 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, urlencode($data));
  curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: multipart/related; boundary=" . $boundry . "; 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 '<h4>An error has occured</h4>' . "\n";
    echo '<strong>' . xml_error_string($errorcode) . '</strong>';
    echo '<br \>';
    $err = true;
  }
  xml_parser_free($p);
			
		
  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 'Our PUSH-ID: ' . $messageid . "<br \>\n";
    echo 'Error CODE: ' . $vals[1]['attributes']['CODE'] . "<br \>\n";
    echo 'Error DESC: ' . $vals[1]['attributes']['DESC'] . "<br \>\n";
    echo 'DeliveryTimeSchedule ' . $deliverbefore . "<br \>\n";
    $dispdata = str_replace(">","&gt;<br />",str_replace("<","&lt;",$data));
    echo 'Data to be sent : <br/> ' . $dispdata . "<br \>\n";
  }
?>

 

Here is my output:

An error has occured
Invalid document endOur PUSH-ID: 1291997220.5107
Error CODE: 
Error DESC: 
DeliveryTimeSchedule 2010-12-10T16:12:00Z
Data to be sent : 
--asdlfkjiurwghasf Content-Type: application/xml; charset=UTF-8 <?xml version="1.0"?>
<!DOCTYPE pap PUBLIC "-//WAPFORUM//DTD PAP 2.1//EN" "http://www.openmobilealliance.org/tech/DTD/pap_2.1.dtd" [<?wap-pap-ver supported-versions="2.1,2.0,1.*"?>
]>
<pap>
<push-message push-id="1291997220.5107" deliver-before-timestamp="2010-12-10T16:12:00Z" source-reference="APPID">
<address address-value="WAPPUSH=PINNO%3A100/TYPE=USER@rim.net"/>
<quality-of-service delivery-method="unconfirmed"/>
</push-message>
</pap>
--asdlfkjiurwghasf Content-Type: text/plain Push-Message-ID: 1291997220.5107 Hi, This is Blackberry Push Message Test from PHP Script --asdlfkjiurwghasf-- 

 

Did you get any solution ??? Please help

 

Somdev

New Developer
Posts: 52
Registered: ‎12-21-2010
My Device: Not Specified

Re: Cannot send PHP Push message using Blackberry Push Essentials service

check if you have configured PHP and curl correctly, i used to have the same problem until i reconfigured my php, apache, and curl.

Contributor
Posts: 47
Registered: ‎01-29-2013
My Device: BB10
My Carrier: BlackBerry

Re: Cannot send PHP Push message using Blackberry Push Essentials service

Good morning,

 

Did you get the solution to this problem cause I got the same one with the PHP code that is runing under my server, but I'm using the Rim URL.

 

Regards,

Thanks.

Developer
Posts: 45
Registered: ‎08-29-2013
My Device: Blackberry curve-9360 and Blackberry bold-9860
My Carrier: Company

Re: Cannot send PHP Push message using Blackberry Push Essentials service

set Push URL to "http://cpxxxx.pushapi.eval.blackberry.com/mss/PD_pushRequest"

 

Where xxxx is your CPID provided by RIM.

 

Please Use the following PHP script

 

<?php
ini_set('display_errors','1');
error_reporting(E_ALL);

// APP ID provided by RIM
$appid = '';
// Password provided by RIM
$password = '';

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

//An array of address must be in PIN format or "push_all"
$addresstosendto[] = '';

$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('This is my message') . "\r\n" .
'--mPsbVQo0a68eIL3OAxnm--' . "\n\r";

// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "http://cpxxxx.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"));

// grab URL and pass it to the browser
echo $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";
}

?>

 

This is works for me

I got the following response

 

Our PUSH-ID: 1396333729.4507
PUSH-ID: 1396333729.4507
REPLY-TIME: 2014-04-01T06:28:49Z
Response CODE: 1001
Response DESC: The request has been accepted for processing.

New Contributor
Posts: 4
Registered: ‎04-08-2014
My Device: z10
My Carrier: Orange

Re: Cannot send PHP Push message using Blackberry Push Essentials service

Thank you @brijmohanyadav, the code you provided works for me using the BlackBerry Push Service Production Credentials. Also would like to add that i used instead of client url(http://cpxxx.pushapi.na.blackberry.com) the server Push URL(https://cpxxxx.pushapi.na.blackberry.com).

Highlighted
Developer
Posts: 45
Registered: ‎08-29-2013
My Device: Blackberry curve-9360 and Blackberry bold-9860
My Carrier: Company

Re: Cannot send PHP Push message using Blackberry Push Essentials service

yes you can change it according to server configuration (Either client or server side).