我有一个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