1

最終的なEDIT作業コード(時間をかけて解決してくれたClausに感謝します):

class WindowsPhonePushDelay
{
    const Immediate=0;
    const In450Sec=10;
    const In900Sec=20;
}

class WindowsPhonePushNotification
{
    private $notif_url = '';

    function WindowsPhonePushNotification($notif_url)
    {
        $this->notif_url = $notif_url;
    }

    public function send_raw($msg,$message_id=NULL, $delay = WindowsPhonePushDelay::Immediate)
    {
        return $this->send_push(NULL,$delay+3,$message_id, $msg);
    }

    public function send_normal_tile($image_url, $title, $count,$message_id=NULL, $delay = WindowsPhonePushDelay::Immediate)
    {
        $msg =  "<?xml version=\"1.0\" encoding=\"utf-8\"?>" .
                "<wp:Notification xmlns:wp=\"WPNotification\">" .
                "<wp:Tile>" .
                "<wp:BackgroundImage>$image_url</wp:BackgroundImage>" .
                "<wp:Count>$count</wp:Count>" .
                "<wp:Title>$title</wp:Title>" .
                "</wp:Tile>" .
                "</wp:Notification>";
                return $this->send_push('token',$delay+1, $message_id,$msg);
    }
       public function send_iconic_tile($image_url_large, $image_url_small, $wide1, $wide2, $wide3, $title, $count,$message_id=NULL, $delay = WindowsPhonePushDelay::Immediate)
    {
        $msg =  "<?xml version=\"1.0\" encoding=\"utf-8\"?>" .
                "<wp:Notification xmlns:wp=\"WPNotification\" Version=\"2.0\">" .
                "<wp:Tile Id=\"\" Template=\"IconicTile\">" .
                "<wp:SmallIconImage>$image_url_small</wp:SmallIconImage>" .
                "<wp:IconImage>$image_url_large</wp:IconImage>" .
                "<wp:WideContent1>$wide1</wp:WideContent1>" .
                "<wp:WideContent2>$wide2</wp:WideContent2>" .
                "<wp:WideContent3>$wide3</wp:WideContent3>" .
                "<wp:Count>$count</wp:Count>" .
                "<wp:Title>$title</wp:Title>" .
                "<wp:BackgroundColor>#00FFFFFF</wp:BackgroundColor>" .
                "</wp:Tile>" .
                "</wp:Notification>";
       echo $msg;
    return $this->send_push('token',$delay+1, $message_id,$msg);
    }

    public function send_toast($title, $message,$message_id=NULL, $delay = WindowsPhonePushDelay::Immediate)
    {
        $msg =  "<?xml version=\"1.0\" encoding=\"utf-8\"?>" .
                "<wp:Notification xmlns:wp=\"WPNotification\">" .
                "<wp:Toast>" .
                "<wp:Text1>$title</wp:Text1>" .
                "<wp:Text2>$message</wp:Text2>" .
                "</wp:Toast>" .
                "</wp:Notification>";

        return $this->send_push('toast',$delay+2,$message_id, $msg);
    }

    private function send_push($target,$delay,$message_id,$msg)
    {
        $sendedheaders=  array(
                            'Content-Type: text/xml; charset=utf-8 ',
                            'Accept: application/*',
                            "X-NotificationClass: $delay"
                            );
        if($message_id!=NULL)
        $sendedheaders[]="X-MessageID: $message_id";
        if($target!=NULL)
            $sendedheaders[]="X-WindowsPhone-Target:$target";

        $req = curl_init();
        curl_setopt($req, CURLOPT_HEADER, true); 
        curl_setopt($req, CURLOPT_HTTPHEADER,$sendedheaders);
        curl_setopt($req, CURLOPT_POST, true);
        curl_setopt($req, CURLOPT_POSTFIELDS, $msg);
        curl_setopt($req, CURLOPT_URL, $this->notif_url);
        curl_setopt($req, CURLOPT_RETURNTRANSFER, 1);
        $response = curl_exec($req);
        curl_close($req);

        $result=array();
        foreach(explode("\n",$response) as $line)
        {

        $tab=explode(":",$line,2);
        if(count($tab)==2)
            $result[$tab[0]]=trim($tab[1]);
        }

        return $result;
     }
}

EDIT : XML (ローカル イメージとリモート イメージの両方で試行)

<?xml version="1.0" encoding="utf-16"?><wp:Notification xmlns:wp="WPNotification" Version="2.0"><wp:Tile Id="/" Template="IconicTile"><wp:SmallIconImage Action="Clear">/Images/LiveTiles/asot_iconic_small.png</wp:SmallIconImage><wp:IconImage Action="Clear">/Images/LiveTiles/asot_iconic_large.png</wp:IconImage><wp:WideContent1 Action="Clear">Test1</wp:WideContent1><wp:WideContent2 Action="Clear">Test2</wp:WideContent2><wp:WideContent3 Action="Clear">Test3</wp:WideContent3><wp:Count Action="Clear">1</wp:Count><wp:Title Action="Clear">Title</wp:Title><wp:BackgroundColor Action="Clear">#00FFFFFF</wp:BackgroundColor></wp:Tile></wp:Notification>

EDIT2 完全なエラー メッセージ:

"The XML payload contains invalid or improperly formatted XML or the notification type specified in the header does not match the payload type used.  The channel has been closed.  Check your XML payload for errors and reopen the channel to obtain a new URI."

EDIT3 サーバーの応答

HTTP/1.1 200 OK Cache-Control: private Server: Microsoft-IIS/7.5 X-DeviceConnectionStatus: Connected X-NotificationStatus: Received X-SubscriptionStatus: Active X-MessageID: 00000000-0000-0000-0000-000000000000 ActivityId: 5bd4c4b6-1d79-4964-9a56-7d49e2aa5972 X-Server: DB3MPNSM018 X-AspNet-Version: 4.0.30319 X-Powered-By: ASP.NET Date: Wed, 07 Nov 2012 19:35:59 GMT Content-Length: 0

プッシュ通知を送信しようとするときに、上記のコード (Rudy Huyn によって作成) を使用しています。通常のタイルを送信しても問題なく動作しますが、代わりにアイコン タイルを受信できるようにアプリを更新しようとしています。send_iconic_tile を自分で追加しました。

ただし、アイコン タイル通知を送信すると、電話で PayloadFormatError が発生します。ペイロードはマイクロソフトがここに書いたものと一致しているように見えるので、コードにエラーは見られません: http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj207009(v=vs.105 .aspx

4

1 に答える 1

4

あなたのペイロードは確かに無効です。

は(透明の場合) の HEX 形式である必要があり、 は である必要BackgroundColorがあります。#FF00000000FFFFFFId="/"Id=""

背景色の 16 進値の前後に空白を入れることはできないことに注意してください。

于 2012-11-07T10:14:53.230 に答える