首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >黑莓推送通知在CodeIgniter中的实现

黑莓推送通知在CodeIgniter中的实现
EN

Stack Overflow用户
提问于 2013-09-25 20:42:44
回答 1查看 240关注 0票数 0

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

EN

回答 1

Stack Overflow用户

发布于 2014-05-15 19:53:38

我不认为有任何库用于代码触发器-黑莓推送通知。

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

代码语言:javascript
运行
复制
$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";
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19005257

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档