我正在尋找可以發送推送通知給ios設備和android設備的php代碼。蘋果推送通知爲iOS和谷歌雲消息傳遞爲Android使用PHP?
單獨我已經使用easyapns的ios推送通知和gcm的android推送通知。
我想合併兩個代碼,併爲這兩個設備發送推送通知的單個代碼。
我只在php部分工作。有什麼解決方案可以讓它變得簡單嗎?
我正在尋找可以發送推送通知給ios設備和android設備的php代碼。蘋果推送通知爲iOS和谷歌雲消息傳遞爲Android使用PHP?
單獨我已經使用easyapns的ios推送通知和gcm的android推送通知。
我想合併兩個代碼,併爲這兩個設備發送推送通知的單個代碼。
我只在php部分工作。有什麼解決方案可以讓它變得簡單嗎?
我的研究後,我發現了一個解決方案適用於iOS的工作的罰款。
public function send_notification($registration_id,$message,$ios_certificate,$badge,$tHost){
// Provide the Host Information.
//$tHost = 'gateway.sandbox.push.apple.com';
$tPort = 2195;
// Provide the Certificate and Key Data.
//$tCert = 'certificates/meetmethere/apns-dev-cert.pem';
$tPassphrase = '';
//$tToken = 'efdf10632aa4e711ef8c57abf2a3cdec51e7c42811bb998c3e26de2876bac8fa';
//$tAlert = 'this is the test message ';
// The Badge Number for the Application Icon (integer >=0).
$tBadge = 0;
// Audible Notification Option.
$tSound = 'default';
// The content that is returned by the LiveCode "pushNotificationReceived" message.
$tPayload = 'message';
// Create the message content that is to be sent to the device.
$tBody['aps'] = array (
'alert' => $message,
'badge' => $badge,
'sound' => $tSound,
);
$tBody ['payload'] = $tPayload;
$tBody = json_encode ($tBody);
// Create the Socket Stream.
$tContext = stream_context_create();
stream_context_set_option ($tContext, 'ssl', 'local_cert', $ios_certificate);
// Remove this line if you would like to enter the Private Key Passphrase manually.
stream_context_set_option ($tContext, 'ssl', 'passphrase', $tPassphrase);
// Open the Connection to the APNS Server.
$tSocket = stream_socket_client ('ssl://'.$tHost.':'.$tPort, $error, $errstr, 30, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $tContext);
// Check if we were able to open a socket.
if (!$tSocket)
$status=false;
// Build the Binary Notification.
$tMsg = chr (0) . chr (0) . chr (32) . pack ('H*', $registration_id) . pack ('n', strlen ($tBody)) . $tBody;
// Send the Notification to the Server.
$tResult = fwrite ($tSocket, $tMsg, strlen ($tMsg));
if ($tResult)
$status=true;
else
$status=false;
fclose ($tSocket);
return $status;
}`
給你一些鏈接的希望,這樣可以幫助你在Android設備上發送推送通知。
,如果您有任何疑問,請讓我知道我可以幫你Send Push Notification on android devide
我已經解決了這個問題,在DB中有一個字段,告訴每個設備的類型。我分組他們,並推動Android設備在一起和IOS設備在一起 – zozelfelfo 2014-10-08 11:04:40
我會感激,如果你提供我的代碼,因爲這是我所需要的。我已經在具有列設備類型的數據庫中創建了一個表。和入門將只有ios或Android – kabir 2014-10-08 11:14:44
對不起,我沒有代碼,因爲我在Java做的,而不是PhP,但你可以使用相同的邏輯 – zozelfelfo 2014-10-08 11:20:00