CodeIgniter中的Blackberry推送通知实现

时间:2013-09-25 12:42:44

标签: php codeigniter blackberry push-notification blackberry-push

是否有任何codeigniter库可以实现Blackberry应用程序的推送通知(版本5-7)。或者任何人都可以帮助在codeigniter中实现blackberry的推送通知服务。

1 个答案:

答案 0 :(得分:0)

我认为没有任何代码点火器库 - 黑莓推送通知。

但是

以下是实施黑莓推送通知的流程和代码,我们目前正在这么多的应用和网络服务中使用。

$appid = '311-hh81l706993itR79O4021oom4847e332o472';

// Password provided by RIM
$password = 'SNuwGoR7';

// Application device port
$appport =33489;

//Deliver before timestamp
$deliverbefore = gmdate('Y-m-d\TH:i:s\Z', 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. "\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" .                    'Push-Message-ID: ' . $messageid . "\r\n\r\n" .$messages. "\r\n" .        '--asdwewe--' . "\r\n";

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