2
我嘗試在WP8.1上發送推送通知。應用程序由Cordova構建。推送通知WP8.1「無效的頻道URL」
客戶端
- 我創建https://dev.windows.com一個新的新的應用程序>控制面板
- 與Visual Studio 2015年的社區,我在我的應用程序到新的應用程序 (關聯右鍵單擊項目>商店>助理)
- 在
- 有能力appxmanifest文件吐司檢查我的應用程序的身份是確定的
在我的代碼(從https://github.com/phonegap/phonegap-plugin-push):
try {
pushNotifications.PushNotificationChannelManager.
createPushNotificationChannelForApplicationAsync().done(
function (channel) {
var result = {};
result.registrationId = channel.uri;
myApp.channel = channel;
channel.addEventListener("pushnotificationreceived",
onNotificationReceived);
myApp.notificationEvent = onNotificationReceived;
onSuccess(result, { keepCallback: true });
}, function (error) {
onFail(error);
});
} catch (ex) {
onFail(ex);
}
我可以從這個函數得到通知URI並將其存儲在我的數據庫。 服務器端 我嘗試從PHP
<?php
$sid = urlencode("ms-app://s-1-15-2-xxxxxxxxx");
$secret = urlencode("mysecret");
$uri = 'https://db5.notify.windows.com/?token=xxx';//From database
$str = "grant_type=client_credentials&client_id=$sid&
client_secret=$secret&scope=notify.windows.com";
$url = "https://login.live.com/accesstoken.srf";
$ch = curl_init($url);
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,
array('Content-Type: application/x-www-form-urlencoded'));
curl_setopt($ch, CURLOPT_POSTFIELDS, "$str");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
$output = json_decode($output);
var_dump($output);
if(isset($output->error)){
throw new Exception($output->error_description);
}
$accessToken = $output->access_token;
$sendPush = curl_init();
curl_setopt($sendPush, CURLOPT_URL, $uri);
//TOAST MESSAGE
$toastMessage = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" .
"<wp:Notification xmlns:wp=\"WPNotification\">" .
"<wp:Toast>" .
"<wp:Text1>Text...</wp:Text1>" .
"<wp:Text2>text..</wp:Text2>" .
"</wp:Toast>" .
"</wp:Notification>";
curl_setopt($sendPush, CURLOPT_HEADER, true);
$headers = array('Content-Type: text/xml',"Content-Type: text/xml",
"X-WNS-RequestForStatus:1", "X-WNS-Type: wns/toast",
"Content-Length: " . strlen($toastMessage),
"X-NotificationClass:2" ,
"X-WindowsPhone-Target: toast","Authorization: Bearer $accessToken");
curl_setopt($sendPush, CURLOPT_HTTPHEADER, $headers);
curl_setopt($sendPush, CURLOPT_RETURNTRANSFER, true);
curl_setopt($sendPush,CURLOPT_POST, true);
curl_setopt($sendPush, CURLOPT_POSTFIELDS, $toastMessage);
$output = curl_exec($sendPush);
var_dump($output);
curl_close($sendPush);
這個和平的代碼的輸出發送Toast通知始終是相同的:
"HTTP/1.1 404 Not Found
Content-Length: 0
X-WNS-NOTIFICATIONSTATUS: dropped
X-WNS-STATUS: dropped
X-WNS-ERROR-DESCRIPTION: Invalid channel URL
X-WNS-MSG-ID: 6A7ABBBB65E14731
X-WNS-DEBUG-TRACE: DB5SCH101122042
Strict-Transport-Security: max-age=31536000; includeSubDomains
Date: Mon, 02 Nov 2015 13:11:26 GMT
任何想法幫助我嗎? 謝謝!
感謝您的回覆。你是對的。我必須對uri的'token'部分進行編碼才能使其工作 – grandv22
@marcinax我嘗試用WNS java庫將推送通知發送到windows phone 8.1.I獲取相同的錯誤無效的通道URL。正如您在上面的答案。我沒有收到頻道URL,從https://db5.notify.windows.com/或https://db3.notify.windows.com/開始。訂閱頻道URL我開始使用https: //hk2.notify.windows.com/?token="*************「就像這樣。請幫我解決這個問題。 – bhadram