我有一个 PHP 脚本,它将向 iPhone 发送通知。(下)我的网站代码是用 C# 编写的。我想要做的是将信息从 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# 代码在这里。这段代码基本上是获取我必须发送通知的所有设备令牌。在 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);
}
任何帮助将不胜感激。谢谢