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
marcboo
Posts: 36
Registered: ‎02-13-2011
My Device: Curve 9300
Accepted Solution

BB BIS push PHP server works on push_all but not on specified PIN

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-Push-Development/Push-API-sample-code-needed/td-p/...

 

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_pushRequest");
			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

Regards,



MBK
Developer
marcboo
Posts: 36
Registered: ‎02-13-2011
My Device: Curve 9300

Re: BB BIS push PHP server works on push_all but not on specified PIN

okay i'm a little bit of confused now......

the problem is already solved without any single change on my code (both device and server).............

i think it's a blackberry service problem...... or anything else, i dunno...... *huff*
Regards,



MBK
New Contributor
twinsari
Posts: 2
Registered: ‎07-15-2011
My Device: 8310

Re: BB BIS push PHP server works on push_all but not on specified PIN

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.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_pushRequest");
            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....

Developer
marcboo
Posts: 36
Registered: ‎02-13-2011
My Device: Curve 9300

Re: BB BIS push PHP server works on push_all but not on specified PIN

yes me too. check your firewall and there's a field about not encrypted message blocked.... maybe it's your push message...
Regards,



MBK
Trusted Contributor
foufou
Posts: 109
Registered: ‎11-15-2011
My Device: blackberry 9800

Re: BB BIS push PHP server works on push_all but not on specified PIN

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

 

Trusted Contributor
icecappacino
Posts: 152
Registered: ‎02-12-2011
My Device: Not Specified

Re: BB BIS push PHP server works on push_all but not on specified PIN

Did you ever find out what caused the "Invalid Document end"? I am having a similar issue