【发布时间】: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