1

BB OS 5 アプリケーションでプッシュ通知を送信しようとしています。RIM が提供する low-level-sample を使用すると、すべてが正常に機能し、プッシュが得られます。

ただし、私は php を使用して Apache Server を構築しているため、Tomcat を使用する Java サンプルは私には適していません。

プッシュ通知を送信するための単純な php スクリプトを見つけるために、LOT を検索しました。最後に、ここで提供する 3 を見つけましたが、さまざまな種類のエラーが原因で、どれも機能しません。

誰かがそれらの1つを修正するのを手伝ってくれるか、別の解決策を提供してくれるかもしれません。

スクリプト no1

<?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 = '3582-M4687r9k9k836r980kO2d95i32i67y10n34';

  // Password provided by RIM
  $password = '7cZUUVhG';

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

  $BBPin = "321EF989";

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

  //boundry
  $boundry = "asdlfkjiudrgdgdgdrwghasf";

  //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";
  }
?>

スクリプトのエラー no1

An error has occured
Invalid document end
Our PUSH-ID: 1368441279.3452

Notice: Undefined offset: 1 in C:\xampp\htdocs\PushToBlackBerryServer\BBpushing.php on line 97
Error CODE: 

Notice: Undefined offset: 1 in C:\xampp\htdocs\PushToBlackBerryServer\BBpushing.php on line 98
Error DESC: 
DeliveryTimeSchedule 2013-05-13T10:39:39Z
Data to be sent : 
--asdlfkjiudrgdgdgdrwghasf 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="1368441279.3452" deliver-before- timestamp="2013-05-13T10:39:39Z" source-reference="3582-M4687r9k9k836r980kO2d95i32i67y10n34">
<address address-value="WAPPUSH=321EF989%3A100/TYPE=USER@rim.net"/>
<quality-of-service delivery-method="unconfirmed"/>
</push-message>
</pap>
--asdlfkjiudrgdgdgdrwghasf Content-Type: text/plain Push-Message-ID: 1368441279.3452 Hi, This is Blackberry Push Message Test from PHP Script --asdlfkjiudrgdgdgdrwghasf-- 

-------------------------------------------------- --------------------------------------------

スクリプト no2

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

// APP ID provided by RIM
$appid = '3582-M4687r9k9k836r980kO2d95i32i67y10n34';
// Password provided by RIM
$password = '7cZUUVhG';

//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[] = '321EF989';

$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, "https://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";
}


?>

スクリプトのエラー No2

Invalid document endOur PUSH-ID: 1368441579.0673

An error has occured


Notice: Undefined offset: 1 in C:\xampp\htdocs\PushToBlackBerryServer\newPush.php on line 78
Error CODE: 

Notice: Undefined offset: 1 in C:\xampp\htdocs\PushToBlackBerryServer\newPush.php on line 79
Error DESC: 

-------------------------------------------------- --------------------------------------------

スクリプト no3

<?php

    // APP ID provided by RIM
    $appid = "3582-M4687r9k9k836r980kO2d95i32i67y10n34";
    // Password provided by RIM
    $password = "7cZUCDgG";
    // Application device port
    $appport = "33387";

    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 = '320EF999';
        //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();
    // ---------------------------------------------------------------------------------------------------------------
?>

スクリプト no3 のログ

Operasi push berhasil Our PUSH-ID: 1368441801.8001
array(5) { [0]=> array(3) { ["tag"]=> string(3) "PAP" ["type"]=> string(4) "open" ["level"]=> int(1) } [1]=> array(4) { ["tag"]=> string(13) "PUSH-RESPONSE" ["type"]=> string(4) "open" ["level"]=> int(2) ["attributes"]=> array(4) { ["PUSH-ID"]=> string(15) "1368441801.8001" ["SENDER-ADDRESS"]=> string(53) "http://pushapi.eval.blackberry.com/mss/PD_pushRequest" ["SENDER-NAME"]=> string(21) "RIM Push-Data Service" ["REPLY-TIME"]=> string(20) "2013-05-13T10:43:21Z" } } [2]=> array(4) { ["tag"]=> string(15) "RESPONSE-RESULT" ["type"]=> string(8) "complete" ["level"]=> int(3) ["attributes"]=> array(2) { ["CODE"]=> string(4) "1001" ["DESC"]=> string(45) "The request has been accepted for processing." } } [3]=> array(3) { ["tag"]=> string(13) "PUSH-RESPONSE" ["type"]=> string(5) "close" ["level"]=> int(2) } [4]=> array(3) { ["tag"]=> string(3) "PAP" ["type"]=> string(5) "close" ["level"]=> int(1) } } PUSH-ID: 1368441801.8001
REPLY-TIME: 2013-05-13T10:43:21Z
Response CODE: 1001
Response DESC: The request has been accepted for processing.

観察


まず、機能しているように見える唯一のスクリプトは no3 です。ただし、デバイスをプッシュすることはありません。また、取得した資格情報のメールで RIM によって提供されるapportパラメーターを使用する唯一のものです。

*Javaサーバーを使用すると、デバイスは通常どおり通知を受信します。つまり、BISが正しく機能していることを意味します。したがって、問題はデバイスではなくコードにあります。

どんな助けでも大歓迎です。

4

0 に答える 0