我确定access_token
&sid & secret
是对的。
我不知道什么会导致 404 错误。
这是我的 PHP 代码:
public function build_tile_xml($title, $img){
return '<?xml version="1.0" encoding="utf-8"?>'.
'<toast launch="additionalContextParameters">'.
'<visual lang="en-US">'.
'<binding template="ToastImageAndText01">'.
'<text id="1">'.$title.'</text>'.
'</binding>'.
'</visual>'.
'</toast>';
}
public function post_tile($uri, $xml_data, $type = WPNTypesEnum::Toast, $tileTag = ''){
if($this->access_token == ''){
$this->get_access_token();
}
$headers = array('Content-Type: text/xml', "Content-Length: " . strlen($xml_data), "X-WNS-Type: $type", "Authorization: Bearer $this->access_token");
if($tileTag != ''){
array_push($headers, "X-WNS-Tag: $tileTag");
}
$ch = curl_init($uri);
// Tiles: http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh868263.aspx
// http://msdn.microsoft.com/en-us/library/windows/apps/hh465435.aspx
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, "$xml_data");
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
$response = curl_getinfo( $ch );
curl_close($ch);
$code = $response['http_code'];
if($code == 200){
echo 'Successfully sent message'. "<br>";
return new WPNResponse('Successfully sent message', $code);
}
else if($code == 401){
echo '$code == 401' . "<br>";
$this->access_token = '';
return $this->post_tile($uri, $xml_data);
}
else if($code == 410 || $code == 404){
echo 'Expired or invalid URI ' . $code . "<br>";
return new WPNResponse('Expired or invalid URI ', $code, true);
}
else{
echo 'Unknown error while sending message ' . $code . "<br>";
return new WPNResponse('Unknown error while sending message', $code, true);
}
}`