【问题标题】:Payload error while using PHP to update live tiles windows phone 8使用 PHP 更新动态磁贴 Windows Phone 8 时的有效负载错误
【发布时间】:2014-06-03 11:57:56
【问题描述】:

我在使用 PHP 通过推送通知更新我的动态图块时遇到问题。对于正常的 Toast 消息,没有任何错误。但是当我尝试使用相同的编码并更改电话目标以及通知类时。我收到了有效载荷错误。这是我的源代码,想知道我是否做错了什么。

谢谢!

<?php
   if( isset($_POST['push_action']) && $_POST['push_action'] == "1") {
   $tileMessage = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" .
                "<wp:Notification xmlns:wp=\"WPNotification\">" .
                   "<wp:Tile>" .
                    "<wp:BackgroundImage>" . $_POST["push_msg0"] . 
"</wp:BackgroundImage>" +
                    "<wp:Count>" . $_POST["push_msg1"] . "</wp:Count>" +
                    "<wp:Title>" . $_POST["push_msg2"] . "</wp:Title>" +
                    "<wp:BackBackgroundImage>" . $_POST["push_msg3"] . "</wp:BackBackgroundImage>" +
                    "<wp:BackTitle>" . $_POST["push_msg4"] . "</wp:BackTitle>" +
                    "<wp:BackContent>" . $_POST["push_msg5"] . "</wp:BackContent>" +
                 "</wp:Tile> " .
              "</wp:Notification>";



    // Create request to send
    $r = curl_init();
    curl_setopt($r, CURLOPT_URL, $_POST["push_uri"]);
    curl_setopt($r, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($r, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_HEADER, true); 

    // add headers
    $httpHeaders=array('Content-type: text/xml; charset=utf-8', 'X-WindowsPhone-Target: token',
                    'Accept: application/*', 'X-NotificationClass: 1','Content-Length:'.strlen($tileMessage));
    curl_setopt($r, CURLOPT_HTTPHEADER, $httpHeaders);

    // add message
    curl_setopt($r, CURLOPT_POSTFIELDS, $tileMessage);

    // execute request
    $output = curl_exec($r);
    curl_close($r);
}
  ?>  

<form method="post" action="push2.php">
<h3>Push through php</h3>
<input type="text" name="push_uri" id="push_uri" placeholder="Push Uri" style="width:50%;padding:5px;" autofocus required/> <br><br>
<input type="text" name="push_msg0" id="push_msg0" placeholder="Background Image"  style="width:50%;padding:5px;" required/> <br><br>
<input type="text" name="push_msg1" id="push_msg1" placeholder="Count"  style="width:50%;padding:5px;" required/> <br><br>
<input type="text" name="push_msg2" id="push_msg2" placeholder="Title"  style="width:50%;padding:5px;" required/> <br><br>
<input type="text" name="push_msg3" id="push_msg3" placeholder="Back Background Image"  style="width:50%;padding:5px;" required/> <br><br>
<input type="text" name="push_msg4" id="push_msg4" placeholder="Back Title"  style="width:50%;padding:5px;" required/> <br><br>
<input type="text" name="push_msg5" id="push_msg5" placeholder="Back Content"  style="width:50%;padding:5px;" required/> <br><br>
<input type="hidden" name="push_action" value="1" />


<input type="submit" value="Push" style="width:50%;padding:5px;"/>

【问题讨论】:

  • 你能把你得到的完整错误文本吗?您发送的某些值似乎无效。客户端应用程序有哪些类型的磁贴(标志性、翻转)?你检查过这个类似的问题吗stackoverflow.com/questions/13267261/…
  • @stipe 我收到的错误消息是“”XML 有效负载包含无效或格式不正确的 XML,或者标头中指定的通知类型与使用的有效负载类型不匹配。该频道已关闭。检查您的 XML 有效负载是否有错误并重新打开频道以获取新的 URI。”我正在尝试更新翻转图块。不是标志性的。谢谢

标签: php windows-phone-8 push-notification mpns


【解决方案1】:

显然我错过了导致它无法工作的 Version=2.0、Tile ID & Tile 模板。这是这两行的更新,之后我可以通过推送通知更新磁贴。

"<wp:Notification xmlns:wp=\"WPNotification\" Version=\"2.0\">"
"<wp:Tile Id=\"/MainPage.xaml?Name=flip\" Template=\"FlipTile\">"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-06-25
    • 1970-01-01
    • 2013-04-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多