使用php脚本向BB 5

使用php脚本向BB 5,php,blackberry,push-notification,push,Php,Blackberry,Push Notification,Push,我正在尝试在BB OS 5应用程序中发送推送通知。当我使用RIM提供的低水平样品时,一切正常,我得到了推动 但是,我正在使用php构建Apache服务器,因此使用Tomcat的java示例不适合我 我搜索了很多,找到了一个简单的php脚本来发送推送通知。最后我找到了3,我将在这里提供,但由于不同类型的错误,它们都不起作用 也许有人能帮我修复其中一个,或者给我提供另一个解决方案 剧本一 ----------------------------------------------- 剧本三 观察 首

我正在尝试在BB OS 5应用程序中发送推送通知。当我使用RIM提供的低水平样品时,一切正常,我得到了推动

但是,我正在使用php构建Apache服务器,因此使用Tomcat的java示例不适合我

我搜索了很多,找到了一个简单的php脚本来发送推送通知。最后我找到了3,我将在这里提供,但由于不同类型的错误,它们都不起作用

也许有人能帮我修复其中一个,或者给我提供另一个解决方案

剧本一

----------------------------------------------- 剧本三

观察 首先,唯一有效的脚本是3号。然而,我从来没有得到推动的设备。也是唯一一个使用apport参数的,该参数由RIM在我获得的凭证邮件中提供

*当我使用java服务器时,设备正常接收通知,这意味着BIS工作正常,因此问题在于代码,而不是设备


非常感谢您的任何帮助。

您是否有可以收听推送消息的客户端应用程序?当然有。我还能往哪里推呢?客户端应用程序运行良好,因为当我使用RIM提供的java代码时,我得到了推动。但是我需要php代码。无效的文档endOur PUSH-ID:1368443045.6832发生错误注意:第83行C:\xampp\htdocs\PushToBlackBerryServer\Rinces.php中未定义的偏移量:1错误代码:注意:第85行C:\xampp\htdocs\PushToBlackBerryServer\Rinces.php中未定义的偏移量:1错误描述:添加
<?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";
  }
?>
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-- 
<?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";
}


?>
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: 
<?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();
    // ---------------------------------------------------------------------------------------------------------------
?>
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.