2011-09-20 149 views
1

嗨,我想在黑莓推送通知。我已經搜索了答案,並得到了推送服務指南。我閱讀本指南。本指南不提供客戶端應用程序的任何代碼信息。它講述了推送服務器sdk及其安裝,但並不知道如何編寫客戶端代碼來推送通知。那麼是否有提供推送通知概念的示例代碼?黑莓推送通知

感謝

+0

你嘗試推送通知城市飛艇在黑莓 – koti

+0

是的,我已經看到了城市airship.It不能自由 – kehnar

+0

提供這種服務對於客戶端的代碼示例參考HTTP ://supportforums.blackberry.com/t5/BlackBerry-Push-Development/Simplified-BIS-Push-client-sample/ta-p/693857 – kehnar

回答

1

對於客戶端代碼,請參閱此鏈接Blackberry push

以此作爲服務器端代碼 -

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

// APP ID provided by RIM 
$appid = ''; 
// Password provided by RIM 
$password = ''; 

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

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


?> 
+0

如何在沒有app_id的情況下測試推送通知。 –

+0

你不能測試沒有應用程序ID推送通知。 – Signare

+0

在eval url上測試推送通知並請求生產新appId後。在從eval模式更改爲生產模式時,代碼中是否存在來自評估網址和生產網址的更改。 –