Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/299.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将数据从C#传递到PHP_C#_Php_Apple Push Notifications - Fatal编程技术网

将数据从C#传递到PHP

将数据从C#传递到PHP,c#,php,apple-push-notifications,C#,Php,Apple Push Notifications,我有一个PHP脚本,可以向iPhone发送通知。(如下)我的网站代码是C#。我要做的是将信息从C#传递到PHP脚本 private void SendAppleNotifications(List<NotificationInfo> AppleNotifications) { ApplePushNotification push = new ApplePushNotification(false, AppleCertificate, ApplePass

我有一个PHP脚本,可以向iPhone发送通知。(如下)我的网站代码是C#。我要做的是将信息从C#传递到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);
    }
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);

?>

在PHP脚本中使用$\u POST获取deviceToken和密码短语

<?php

// Put your device token here (without spaces):
$deviceToken = $_POST['deviceToken'];
// Put your private key's passphrase here:
$passphrase = $_POST['passphrase'];

?>
最后调用这个方法

String deviceToken = HttpUtility.UrlEncode("YourDeviceToken");
String passphrase = HttpUtility.UrlEncode("YourPassphrase");

SendPost("http://yourphpsite.com/xxx.php", String.Format("deviceToken={0}&passphrase={1}", deviceToken, passphrase));

使用GET或POST参数show是否执行php脚本?C#汇编和php脚本是否在同一台windows机器上运行?您是否运行IIS服务器?有一种方法可以使用interop公开您的C#类。或者您可以编写一个C#WCF web服务。我的脚本有问题,但就连接2而言,这是可行的。Thanks@makimPhp应用程序将如何显示从C#SendPost方法接收到的内容?
String deviceToken = HttpUtility.UrlEncode("YourDeviceToken");
String passphrase = HttpUtility.UrlEncode("YourPassphrase");

SendPost("http://yourphpsite.com/xxx.php", String.Format("deviceToken={0}&passphrase={1}", deviceToken, passphrase));