我有一個PHP腳本,它會向iPhone發送通知(下面)我在C#中使用了我的網站代碼。我想要做的是將來自C#的信息傳遞給PHP腳本。將數據從C#傳遞到PHP
PHP腳本
<?php
// Put your device token here (without spaces):
$deviceToken = ''; //Get from C#
// Put your private key's passphrase here:
$passphrase = ''; //Get from C#
// Put your alert message here:
$message = 'New Message';
////////////////////////////////////////////////////////////////////////////////
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', 'ck.pem');
stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
// Open a connection to the APNS server
$fp = stream_socket_client(
'ssl://gateway.push.apple.com:2195', $err,
$errstr, 30, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);
if (!$fp)
exit("Failed to connect: $err $errstr" . PHP_EOL);
echo 'Connected to APNS' . PHP_EOL;
// Create the payload body
$body['aps'] = array(
'alert' => $message,
'sound' => 'default'
);
// Encode the payload as JSON
$payload = json_encode($body);
// Build the binary notification
$msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload;
// Send it to the server
$result = fwrite($fp, $msg, strlen($msg));
if (!$result)
echo 'Message not delivered' . PHP_EOL;
else
echo 'Message successfully delivered' . PHP_EOL;
// Close the connection to the server
fclose($fp);
?>
我想通過deviceToken和密碼給該腳本。我擁有同一臺服務器上的所有內容,並將它們放在服務器上的相同位置。
我想從這裏啓動PHP腳本的C#代碼。這個代碼基本上是獲得我必須發送通知的所有devicetokens。在那個foreach循環裏面我需要調用PHP腳本。
private void SendAppleNotifications(List<NotificationInfo> AppleNotifications)
{
ApplePushNotification push = new ApplePushNotification(false, AppleCertificate, ApplePassword);
List<NotificationPayload> notificationList = new List<NotificationPayload>();
List<string> returnStrings = new List<string>();
foreach (NotificationInfo ni in AppleNotifications)
{
}
returnStrings = push.SendToApple(notificationList);
}
任何幫助將不勝感激。由於
使用GET或POST參數 – Tearsdontfalls 2013-03-05 15:29:33
如何執行php腳本? – user1950929 2013-03-05 15:30:20
是C#程序集和你的php腳本在同一臺Windows機器上運行?你有IIS服務器運行嗎? – 2013-03-05 15:33:15