06-28-2011 06:05 AM
Okay this time i already develop my client apps,
and i found this problem when i try to make the PHP apps according to http://supportforums.blackberry.com/t5/BlackBerry-
when i send the message with address push_all :
<address address-value="push_all" />
it works greatly on my device, but when i send the message with specified PIN Address :
<address address-value="ABCDEF12" />
once again, the message is blocked by firewall (THE FIREWALL IS DISABLED) as NOT ENCRYPTED MESSAGE.
this is my code :
<?php
// APP ID provided by RIM
$appid = 'XXXX-XXXXXXXXXXXXXXXXX';
// Password provided by RIM
$password = 'XXXXXX';
// Application device port
$appport = XXXXXX;
try {
// Message to send :
$message = "testing testing";
//Deliver before timestamp
$deliverbefore = gmdate('Y-m-d\TH:i:s\Z', strtotime('+10 minutes'));
// An array of address must be in PIN format or "push_all"
// Format = WAPPUSH=PIN%3APORT/TYPE=USER@rim.com
$addresstosendto[] = 'push_all';
$addresses = '';
foreach ($addresstosendto as $value) {
$addresses .= '<address address-value="' . $value . '" />';
}
// create a new cURL resource
$err = false;
$ch = curl_init();
$messageid = microtime(true);
$data = '--asdwewe. "\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="unconfirmed"/>
</push-message>
</pap>' . "\r\n" .
'--asdwewe' . "\r\n" .
'Content-Type: text/plain' . "\r\n" .
//'Content-Encoding: binary'. "\r\n" .
'Push-Message-ID: ' . $messageid . "\r\n\r\n" .
stripslashes($message) . "\r\n" .
'--asdwewe--' . "\r\n";
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "https://pushapi.eval.blackberry.com/mss/PD_pushReq uest");
curl_setopt($ch, CURLOPT_PORT , 443);
curl_setopt($ch, CURLOPT_SSLVERSION, 3);
curl_setopt($ch, CURLOPT_CAINFO, getcwd()."\cacert.pem");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_USERAGENT, "My 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);
$__extra_Headers = array(
"Content-Type: multipart/related; boundary=asdwewe; type=application/xml",
"Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2",
"Connection: keep-alive",
"X-Rim-Push-Dest-Port: ".$appport,
"X-RIM-PUSH-ID: ".$messageid,
"X-RIM-Push-Reliability-Mode: APPLICATION"
);
curl_setopt($ch, CURLOPT_HTTPHEADER, $__extra_Headers);
// grab URL and pass it to the browser
$xmldata = curl_exec($ch);
if($xmldata === false){
echo 'Error pada CURL : ' . curl_error($ch)."\n";
}else{
echo 'Operasi push berhasil'."\n";
}
// 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)."\n";
$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";
}
} catch (Exception $e) {
var_dump($e->getMessage());
}
exit();
// -------------------------------------------------- -------------------------------------------------- -----------
?>
I appreciate any helpful post....... Thanks for help and your attention
Solved! Go to Solution.
06-30-2011 02:39 AM
07-15-2011 03:20 AM
I use the code and got the response below. but I did not get a notification in my device. what can I do?
code :
<?php
// APP ID provided by RIM
$appid = "xxxx-xxxxxxxxxxxxxxxxxxxxx";
// Password provided by RIM
$password = "xxxxxx";
// Application device port
$appport = "xxxxx";
try {
// Message to send :
$message = "testing";
//Deliver before timestamp
$deliverbefore = gmdate('Y-m-d\TH:i:s\Z', strtotime('+1 minutes'));
// An array of address must be in PIN format or "push_all"
// Format = WAPPUSH=PIN%3APORT/TYPE=USER@rim.com
//$addresstosendto[] = 'WAPPUSH=21E1106x%3A30018/TYPE=USER@rim.com';
$addresses = '';
//foreach ($addresstosendto as $value) {
$addresses .= '<address address-value="21E1106x" />';
//}
// create a new cURL resource
$err = false;
$ch = curl_init();
$messageid = microtime(true);
$data = '--asdwewe'. "\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
<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" .
'--asdwewe' . "\r\n" .
'Content-Type: text/plain' . "\r\n" .
//'Content-Encoding: binary'. "\r\n" .
'Push-Message-ID: ' . $messageid . "\r\n\r\n" .
stripslashes($message) . "\r\n" .
'--asdwewe--' . "\r\n";
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "https://pushapi.eval.blackberry.com/mss/PD_pushReq
curl_setopt($ch, CURLOPT_PORT , 443);
curl_setopt($ch, CURLOPT_SSLVERSION, 3);
curl_setopt($ch, CURLOPT_CAINFO, getcwd()."\cacert.pem");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_USERAGENT, "My 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);
$__extra_Headers = array(
"Content-Type: multipart/related; boundary=asdwewe; type=application/xml",
"Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2",
"Connection: keep-alive",
"X-Rim-Push-Dest-Port: ".$appport,
"X-RIM-PUSH-ID: ".$messageid,
"X-RIM-Push-Reliability-Mode: APPLICATION"
);
curl_setopt($ch, CURLOPT_HTTPHEADER, $__extra_Headers);
// grab URL and pass it to the browser
$xmldata = curl_exec($ch);
if($xmldata === false){
echo 'Error pada CURL : ' . curl_error($ch)."\n";
}else{
echo 'Operasi push berhasil'."\n";
}
// 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)."\n";
$err = true;
}
xml_parser_free($p);
echo 'Our PUSH-ID: ' . $messageid . "<br \>\n";
$cek = var_dump($vals);
echo $cek;
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";
}
} catch (Exception $e) {
var_dump($e->getMessage());
}
exit();
// --------------------------------------------------
?>
response :
PUSH-ID: 1310712285.4237
REPLY-TIME: 2011-07-15T06:44:49Z
Response CODE: 1001
Response DESC: The request has been accepted for processing.
please help me....
07-15-2011 03:51 AM
12-13-2011 10:30 AM
I used your code and I obtain this error. What is Application device port? is that the push port sent by RIM registration??
An XML parser error has occured
Invalid document end
Response
12-14-2011 08:42 AM
Did you ever find out what caused the "Invalid Document end"? I am having a similar issue