开发者

iPhone push notification on windows azure

The following code is a working example that works fine under linux server, but when I try the exact same code 开发者_如何学编程in Azure I get a generic 500 Internal server error.

All relative files are uploaded correctly and I have configured php (php.ini) in Azure to use SSL.

Anyone knows why this valid code fails in Azure?

<?php

function pushOne($deviceToken, $message, $badge)
{   
    try {
        $body = array();
        $body['aps'] = array('alert' => $message);  
        $body['aps']['badge'] = $badge;
        $body['aps']['sound'] = 'RM.caf';

        $ctx = stream_context_create();
        stream_context_set_option($ctx, 'ssl', 'local_cert', 'ck.pem');         
        $fp = stream_socket_client('ssl://gateway.sandbox.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT, $ctx);
        //$fp = stream_socket_client('ssl://gateway.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT, $ctx);
        if (!$fp) {
            return "Failed to connect $err $errstrn";
        }
        $payload = json_encode($body);
        $msg = chr(0) . pack("n",32) . pack('H*', str_replace(' ', '', $deviceToken)) . pack("n",strlen($payload)) . $payload;
        fwrite($fp, $msg);
        fclose($fp);
        return 'ok';
    } catch (Exception $e) 
    {                                       
        return 'Exception: '  .  $e->getMessage();
    }       
}
$deviceToken='11111111 22222222 33333333 44444444 55555555 66666666 77777777 88888888';

pushOne($deviceToken, 'Hello World', '1'); echo 'STOP';?>


Try including this on the top of your script:

error_reporting(E_ALL);
ini_set('display_errors', '1');

This will show all php errors instead of giving a 500 internal server error.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜