CodeIgniter 中的 Blackberry 推送通知实现



是否有任何代码点火器库来实现黑莓应用程序的推送通知(版本 5-7)。或者任何人都可以帮助在codeigniter中实现黑莓的推送通知服务。

我认为没有任何

代码点火器 - 黑莓推送通知的库。

以下是实现黑莓推送通知的过程和代码,我们目前正在许多应用程序和 Web 服务中使用黑莓推送通知。

$appid = '311-hh81l706993itR79O4021oom4847e332o472';
// Password provided by RIM
$password = 'SNuwGoR7';
// Application device port
$appport =33489;
//Deliver before timestamp
$deliverbefore = gmdate('Y-m-dTH:i:sZ', strtotime('+10 minutes'));
//here $deviceToken is the device tiken of device to which you want to send message //Example: b568t452
$addresses = '<address address-value="' .$deviceToken. '"/>';

//$data is an array of data which you want to send via push message
$messages=json_encode($data);
// create a new cURL resource
$err = false;
$ch = curl_init();
$messageid = microtime(true);
$data = '--asdwewe. "rn" .Content-Type: application/xml; charset=UTF-8' ."rnrn" .'<?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>' . "rn" .        '--asdwewe' . "rn" .        'Content-Type: text/plain' . "rn" .                    'Push-Message-ID: ' . $messageid . "rnrn" .$messages. "rn" .        '--asdwewe--' . "rn";
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "https://cp311.pushapi.na.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 Server1.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";
}

最新更新