0

I have successfully getting registration id (pin) from my device, but i stuck on server side development, I hope someone could help me :Helpsmilie:

I have followed these 3 references:

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

  2. http://supportforums.blackberry.com/t5/Android-Runtime-Development/Not-receiving-push-notification-o...

  3. server-side problemt: PHP Push message to Blackberry

But I don't get the result as expected, instead i always get ERROR CODE 2000 like this:

Our PUSH-ID: 1401179949.8267

An error has occured
Error CODE: 2000
Error DESC: 2000

string(217) " "

The string(217) " " contains:

<pap>
    <badmessage-response bad-message-fragment="2000" desc="2000" code="2000"></badmessage-response>
</pap>

The code I use:

    $appid = '4746-6135ee38Dm11ro8094c98i7900xxxxxxxxx';
    $password = 'xxxxxxxx';
    $boundary = "mPsbVQo0a68eIL3OAxnm";

    $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_ids as $value) {
        $addresses .= '<address address-value=' . $value . '/>';
    }

    // Open connection
    $ch = curl_init();
    $err = false;
    $messageid = microtime(true);

    $data =
        '--' . $boundary . "\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" .
        '--' . $boundary . "\r\n" .
        // 'Content-Encoding: binary' . "\r\n" .
        'Content-Type: text/plain' . "\r\n" .
        'Push-Message-ID: ' . $messageid . "\r\n\r\n" .
        '{
            "key":"value",
            "key2":"value2"
        }'. "\r\n" .
        '--' . $boundary . '--' . "\n\r";

    $url = 'https://cp4746.pushapi.eval.blackberry.com/mss/PD_pushRequest';
    // Set the url, number of POST vars, POST data
    curl_setopt($ch, CURLOPT_URL, $url);
    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_POST, 1);
    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", "Connection: keep-alive"));

    // 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) {
        $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);
    }
    var_dump($vals);
    return $xmldata;

where registration id i get is already in correct form without prefix, what did I do wrong?

Community
  • 1
  • 1
Victorio Pui
  • 358
  • 1
  • 3
  • 11

1 Answers1

0

I finaly found the right answer for me, from here:

http://supportforums.blackberry.com/t5/BlackBerry-Push-Development/BB-BIS-push-PHP-server-works-on-p...

Thank you marcboo for the answer.

And then I change the code below

stripslashes($message)

to:

json_encode($message)

Full code below, with neccessary changes:

<?php
class BBPUSH {

    //put your code here
    // constructor
    function __construct() {

    }

    public function send_notification($addresstosendto, $message) {
    // 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: application/json' . "\r\n" .
                    //'Content-Encoding: binary'. "\r\n" .
            'Push-Message-ID: ' . $messageid . "\r\n\r\n" .
            json_encode($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();
    }
}
?>

Cheers

Victorio Pui
  • 358
  • 1
  • 3
  • 11