无法在服务器上发送推送消息(黑莓-安卓运行时)


Unable to send push message on server (Blackberry - Android Runtime)

我已经成功地从我的设备获得注册id (pin),但我停留在服务器端开发,我希望有人能帮助我:Helpsmilie:

我遵循了这三个参考:

  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. 服务器端问题:PHP向Blackberry推送消息

但是我没有得到预期的结果,相反,我总是得到这样的ERROR CODE 2000:

Our PUSH-ID: 1401179949.8267
An error has occured
Error CODE: 2000
Error DESC: 2000
string(217) " "

字符串(217)" "包含:

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

我使用的代码:

    $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;

我得到的注册id已经在没有前缀的正确形式,我做错了什么?

我终于找到了适合我的答案,从这里:

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

谢谢马克的回答。

然后我改变下面的代码

stripslashes($message)

:

json_encode($message)

完整代码如下,做了必要的修改:

<?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();
    }
}
?>

欢呼