This repository has been archived by the owner on Sep 1, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
WindowsNotification.txt
191 lines (165 loc) · 7.67 KB
/
WindowsNotification.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
<?
class WindowsNotification
{
private $header1 = 'Content-Type: text/xml';
private $header2 = 'X-WNS-Type: ';
private $header3 = 'Authorization: Bearer ';
private $header4 = 'X-WNS-Tag: ';
private $deviceURI;
private $authToken;
private $Debug = false;
private $WNSMsgToken = "abc";
function __construct($ObjID)
{
$deviceToken = GetValueString($ObjID);
$data = explode("###",$deviceToken);
if (count($data) > 1)
{
$this->deviceURI = $data[0];
$this->authToken = $data[1];
}
}
public function EnableDebug($Debug)
{
$this->Debug = $Debug;
}
public function SetWNSMsgToken($Token)
{
$this->WNSMsgToken = "abc".$Token;
}
public function sendBagdeNotification($Value)
{
$headers = array($this->header1,$this->header2.'wns/badge',$this->header3.$this->authToken);
$body = '<?xml version="1.0" encoding="utf-8"?><badge version="1" value="'.$Value.'"/>';
if ($this->Debug)
{
echo "headers\n";
print_r($headers);
echo "body\n".$body."\n";
}
$response = $this->sendNotification($headers,$body);
return $response;
}
public function sendToastNotification($text1,$text2)
{
$headers = array($this->header1,$this->header2.'wns/toast',$this->header3.$this->authToken);
$body = '<?xml version="1.0" encoding="utf-8"?><toast><visual><binding template="ToastText02">'.
'<text id="1">'.$text1.'</text><text id="2">'.$text2.'</text>'.
'</binding></visual></toast>';
if ($this->Debug)
{
echo "headers\n";
print_r($headers);
echo "body\n".$body."\n";
}
$response = $this->sendNotification($headers,$body);
return $response;
}
public function sendTileNotification($text1,$text2,$text3, $text4)
{
$text1 = utf8_encode($text1);
$text2 = utf8_encode($text2);
$text3 = utf8_encode($text3);
$text4 = utf8_encode($text4);
$body_medium = '<binding template="TileSquare150x150PeekImageAndText03" fallback="TileSquarePeekImageAndText01">'.
'<image id="1" src="ms-appx:///assets/House-white.100.png" alt="ipsControlImage"/>'.
'<text id="1">'.$text1.'</text><text id="2">'.$text2.'</text><text id="3">'.$text3.'</text><text id="4">'.$text4.'</text>'.
'</binding>';
$body_large = '<binding template="TileWide310x150PeekImageAndText02" fallback="TileWidePeekImage02">'.
'<image id="1" src="ms-appx:///assets/House-white.100.png" alt="ipsControlImage"/>'.
'<text id="1">'.$text1.'</text><text id="2">'.$text2.'</text><text id="3">'.$text3.'</text><text id="4">'.$text4.'</text>'.
'</binding>';
$headers = array($this->header1,$this->header2.'wns/tile',$this->header4.$this->WNSMsgToken,$this->header3.$this->authToken );
$body = '<tile><visual version="2">'.$body_medium.$body_large.'</visual></tile>';
if ($this->Debug)
{
echo "headers\n";
print_r($headers);
echo "body\n".$body."\n";
}
$response = $this->sendNotification($headers,$body);
return $response;
}
public function sendTileNotification_gross($text1,$text2,$text3)
{
$headers = array($this->header1,$this->header2.'wns/tile',$this->header4.$this->WNSMsgToken,$this->header3.$this->authToken );
$body = '<tile><visual version="3"><binding template="TileWide310x150IconWithBadgeAndText">'.
'<image id="1" src="ms-appx:///assets/House-white.100.png" alt="ipsControlImage"/>'.
'<text id="1">'.$text1.'</text><text id="2">'.$text2.'</text><text id="3">'.$text3.'</text>'.
'</binding></visual></tile>';
if ($this->Debug)
{
echo "headers\n";
print_r($headers);
echo "body\n".$body."\n";
}
$response = $this->sendNotification($headers,$body);
return $response;
}
public function sendTileNotification_mittel($text1,$text2,$text3)
{
$headers = array($this->header1,$this->header2.'wns/tile',$this->header4.$this->WNSMsgToken,$this->header3.$this->authToken );
$body = '<tile><visual version="3"><binding template="TileSquare150x150IconWithBadge">'.
'<image id="1" src="ms-appx:///assets/House-white.100.png" alt="ipsControlImage"/>'.
'</binding></visual></tile>';
if ($this->Debug)
{
echo "headers\n";
print_r($headers);
echo "body\n".$body."\n";
}
$response = $this->sendNotification($headers,$body);
return $response;
}
public function sendTileNotification_klein($text1,$text2,$text3)
{
$headers = array($this->header1,$this->header2.'wns/tile',$this->header4.$this->WNSMsgToken,$this->header3.$this->authToken );
$body = '<tile><visual version="3"><binding template="TileSquare71x71IconWithBadge"><image id="1" src="ms-appx:///assets/House-white.100.png" alt="ipsControlImage"/></binding></visual></tile>';
if ($this->Debug)
{
echo "headers\n";
print_r($headers);
echo "body\n".$body."\n";
}
$response = $this->sendNotification($headers,$body);
return $response;
}
private function sendNotification($headers,$body)
{
if ($this->Debug)
{
echo "URL:\n".$this->deviceURI."\n";
}
if ($this->deviceURI != "")
{
// use Client URL Library
$ch = curl_init();
// set an options for a cURL transfer
// look options here: http://www.php.net/manual/en/function.curl-setopt.php
// and what are needed here: http://msdn.microsoft.com/en-us/library/windowsphone/develop/hh202970(v=vs.92).aspx
curl_setopt($ch, CURLOPT_URL, $this->deviceURI);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER,$headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
// perform a cURL session
$response = curl_exec($ch);
// Check for errors
if($response === FALSE)
{
echo "Error in WindowsNotifications->sendNotifications: ".curl_error($ch);
}
// close a cURL session
curl_close($ch);
if($response === FALSE)
return "Error in WindowsNotifications->sendNotifications: ".curl_error($ch);
else
return true;
}
else
return "Error in WindowsNotifications->sendNotifications: DeviceURI is null! Will skip message";
}
}
?>