11

I'm a web developer (PHP). I would like to searching for push notification to windows phone 7 using PHP but the result is always .NET.

Please someone can help me.

UPDATE : How to send multi-devices at once? because the delay time is around 1 second, so if I have 1000 devices to push, I may need 1000 seconds to wait.

Eran
  • 387,369
  • 54
  • 702
  • 768
Kannika
  • 2,538
  • 2
  • 27
  • 38
  • 1
    Have you got the answer to send message to multiple device at once? If so please post it. – viji Feb 04 '13 at 12:39

3 Answers3

9

The following is the PHP code to send a toast notification to the URL "_URL_TO_SEND_TO_" which is the token received from the MPNS:

<?php
   // Create the toast message
   $toastMessage = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" .
                "<wp:Notification xmlns:wp=\"WPNotification\">" .
                   "<wp:Toast>" .
                        "<wp:Text1>" . "SendToast" . "</wp:Text1>" .
                        "<wp:Text2>" . "Text Message" . "</wp:Text2>" .
                        "</wp:Toast> " .
                "</wp:Notification>";

    // Create request to send
    $r = curl_init();
    curl_setopt($r, CURLOPT_URL,_URL_TO_SEND_TO_);
    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: toast',
                    'Accept: application/*', 'X-NotificationClass: 2','Content-Length:'.strlen($toastMessage));
    curl_setopt($r, CURLOPT_HTTPHEADER, $httpHeaders);

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

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

If this is the code you need, please check this answer.

Ameen
  • 1,857
  • 2
  • 23
  • 30
  • 1
    how do i get _URL_TO_SEND_TO_ from MPNS ? – Rizky Ramadhan Dec 31 '11 at 11:54
  • new 'HttpNotificationChannel( ).ChannelUri.AbsoluteUri;' you will have to send the uri to your server, along with the guid of the phone, since the URI changes after you close the app, and you don't save alot of useless uri's – GeekPeek Feb 07 '12 at 12:07
  • this code suggests that the push notification is only sent to one single uri/device. this means that my service needs to send multiple requests and this might lead to network/blocking i/o problems. –  Jan 15 '15 at 21:56
4

You don't need to implement it in .NET. You just need to send the correct XML payload to the URL given by the phone.

Take a look at this article on implementing push notifications on Windows Phone 7.

The basic steps are:

  1. Obtain PUSH Notification end point URL (this is done via your app on the phone).
  2. Send that URL to your web service (this web service be in PHP, .NET, whatever you like).
  3. Send your XML payload to the URL obtained in Step 1 and the user will get a PUSH notification.
Frazell Thomas
  • 6,031
  • 1
  • 20
  • 21
  • yep I've the URL from the phone but the problem is that I don't know how to write the code (PHP) to send the XML payload to that URL provided. – Kannika Oct 26 '11 at 09:44
1

Try this ready solution http://phpwindowsphonepush.codeplex.com/SourceControl/changeset/view/18482#58320. Very easy.

Alexandr
  • 1,891
  • 3
  • 32
  • 48