Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > Mobile > Mobile Forum > How to send toast notification from php using cloud service in windwos phone 8?



 

How to send toast notification from php using cloud service in windwos phone 8?

 



Topic : 099546



โพสกระทู้ ( 4 )
บทความ ( 0 )



สถานะออฟไลน์




Hi i am developing one windows phone app, i need to send and receive toast push notification from my app.i am using php for send push notification and i want to know ,how to communicating with my cloud service and send uri to cloud service.i am using code given below, please any one help how to send push notification from my app using php

Code (C#)
/// Holds the push channel that is created or found.
            HttpNotificationChannel pushChannel;

            // The name of our push channel.
            string channelName = "ToastSampleChannel";

            // Try to find the push channel.
            pushChannel = HttpNotificationChannel.Find(channelName);

            // If the channel was not found, then create a new connection to the push service.
            if (pushChannel == null)
            {
                pushChannel = new HttpNotificationChannel(channelName);

                // Register for all the events before attempting to open the channel.
                pushChannel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(PushChannel_ChannelUriUpdated);
                pushChannel.ErrorOccurred += new EventHandler<NotificationChannelErrorEventArgs>(PushChannel_ErrorOccurred);

                // Register for this notification only if you need to receive the notifications while your application is running.
                pushChannel.ShellToastNotificationReceived += new EventHandler<NotificationEventArgs>(PushChannel_ShellToastNotificationReceived);

                pushChannel.Open();

                // Bind this new channel for toast events.
                pushChannel.BindToShellToast();

            }
            else
            {
                // The channel was already open, so just register for all the events.
                pushChannel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(PushChannel_ChannelUriUpdated);
                pushChannel.ErrorOccurred += new EventHandler<NotificationChannelErrorEventArgs>(PushChannel_ErrorOccurred);

                // Register for this notification only if you need to receive the notifications while your application is running.
                pushChannel.ShellToastNotificationReceived += new EventHandler<NotificationEventArgs>(PushChannel_ShellToastNotificationReceived);

                // Display the URI for testing purposes. Normally, the URI would be passed back to your web service at this point.
                System.Diagnostics.Debug.WriteLine(pushChannel.ChannelUri.ToString());
                MessageBox.Show(String.Format("Channel Uri is {0}",
                    pushChannel.ChannelUri.ToString()));

            }

 void PushChannel_ChannelUriUpdated(object sender, NotificationChannelUriEventArgs e)
        {

            Dispatcher.BeginInvoke(() =>
            {
                // Display the new URI for testing purposes.   Normally, the URI would be passed back to your web service at this point.
                System.Diagnostics.Debug.WriteLine(e.ChannelUri.ToString());
                MessageBox.Show(String.Format("Channel Uri is {0}",
                    e.ChannelUri.ToString()));

            });
        }
        void PushChannel_ErrorOccurred(object sender, NotificationChannelErrorEventArgs e)
        {
            // Error handling logic for your particular application would be here.
            Dispatcher.BeginInvoke(() =>
                MessageBox.Show(String.Format("A push notification {0} error occurred.  {1} ({2}) {3}",
                    e.ErrorType, e.Message, e.ErrorCode, e.ErrorAdditionalData))
                    );
        }
        void PushChannel_ShellToastNotificationReceived(object sender, NotificationEventArgs e)
        {
            StringBuilder message = new StringBuilder();
            string relativeUri = string.Empty;

            message.AppendFormat("Received Toast {0}:\n", DateTime.Now.ToShortTimeString());

            // Parse out the information that was part of the message.
            foreach (string key in e.Collection.Keys)
            {
                message.AppendFormat("{0}: {1}\n", key, e.Collection[key]);

                if (string.Compare(
                    key,
                    "wp:Param",
                    System.Globalization.CultureInfo.InvariantCulture,
                    System.Globalization.CompareOptions.IgnoreCase) == 0)
                {
                    relativeUri = e.Collection[key];
                }
            }

            // Display a dialog of all the fields in the toast.
            Dispatcher.BeginInvoke(() => MessageBox.Show(message.ToString()));

        }


Code (PHP)
<?php 
/**
*Windows Phone 7 Push Notification in php by Rudy HUYN
**/
final class WindowsPhonePushDelay
{

const Immediate=0;

 private function __construct(){}
}

class WindowsPhonePushNotification
{
    private $notif_url = '';
 
    function WindowsPhonePushNotification($notif_url)
    {
    	
        $this->notif_url = $notif_url;
    }

 

    public function push_toast($message,$delay = WindowsPhonePushDelay::Immediate, $message_id)
    {
        $msg =	"<?xml version=\"1.0\" encoding=\"utf-8\"?>" .
				"<wp:Notification xmlns:wp=\"WPNotification\">" .
				"<wp:Toast>" .
				"<wp:Text2>".htmlspecialchars($message)."</wp:Text2>" .
				"</wp:Toast>" .
				"</wp:Notification>";
        return $this->push('toast',$delay+2,$message_id, $msg);
    }
	

    private function push($target,$delay,$message_id,$msg)
    {
		$sendedheaders=  array(
                            'Content-Type: text/xml',
                            'Accept: application/*',
							"X-NotificationClass: $delay"
                            );
		if($message_id!=NULL)
		$sendedheaders[]="X-MessageID: $message_id";
		if($target!=NULL)
		$sendedheaders[]="X-WindowsPhone-Target:$target";
		
		
		$req = curl_init();
        curl_setopt($req, CURLOPT_HEADER, true); 
		curl_setopt($req, CURLOPT_HTTPHEADER,$sendedheaders); 
        curl_setopt($req, CURLOPT_POST, true);
        curl_setopt($req, CURLOPT_POSTFIELDS, $msg);
        curl_setopt($req, CURLOPT_URL, $this->notif_url);
        curl_setopt($req, CURLOPT_RETURNTRANSFER, 1);
//        echo $req;
		$response = curl_exec($req);
		echo $response;
		curl_close($req);
 
		$result=array();
		foreach(explode("\n",$response) as $line)
		{
		$tab=explode(":",$line,2);
		if(count($tab)==2)
			$result[$tab[0]]=trim($tab[1]);
		}
//		echo $result."ghghgh";
		return $result;
     }
}

?>


Code (PHP)
<?php

$con=mysqli_connect("localhost","root","root","buk");

if (isset($_GET["regId"]) || isset($_GET["message"])) {
    $regId = $_GET["regId"];
    $message_id = $_GET["id"];
    $registatoin_ids=array($regId);
    $notif_url = $_GET["notify"];
    $message = $_GET["message"];
	$customer_id = $_GET["customer_id"];
    include_once './GCM.php';
    $query = mysqli_query($con,"select count(offer) as count from pim_productdeal where customer_id='$customer_id' and offer!=''");
	$count = mysqli_fetch_array($query);
	echo $count['count'];
//    exit;
    $gcm = new GCM();
    $registatoin_ids = array($regId);
    include_once './windowspush.php';
    $windows_push = new WindowsPhonePushNotification($notif_url);
    $res = $windows_push->push_toast($message,$delay = WindowsPhonePushDelay::Immediate, $message_id);
	$result = $gcm->send_notification($registatoin_ids,$customer_id, $message);

         echo json_encode($result);

    echo $result;
}
?>


This is am using mycode, i got error given below:
This is am using mycode i got error like given below:

HTTP/1.1 400 Bad Request
Cache-Control: private
Content-Type: text/html
Server: Microsoft-IIS/7.5
ActivityId: dbe7bdce-ecfe-4eb5-aaf6-80854d4b663d
X-Server: AM3MPNSM023
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Fri, 23 Aug 2013 13:38:06 GMT
Content-Length: 11

Please any one tell me how to solve in this issue and how to communicate with cloud service using php file



Tag : Mobile, Device (Mobile), C#, Windows Phone, Windows, Clound Service







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2013-08-24 14:06:25 By : Dashi View : 1704 Reply : 1
 

 

No. 1



โพสกระทู้ ( 1,458 )
บทความ ( 0 )



สถานะออฟไลน์
Twitter Facebook Blogger

https://docs.microsoft.com/en-us/azure/notification-hubs/notification-hubs-php-push-notification-tutorial






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2020-05-23 22:28:25 By : PhrayaDev
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : How to send toast notification from php using cloud service in windwos phone 8?
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 01
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่