-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
350 lines (281 loc) · 11.3 KB
/
index.php
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>FCM & APNS Push Sender</title>
<link rel="stylesheet" href="assets/css/bootstrap-reboot.min.css">
<link rel="stylesheet" href="assets/css/bootstrap.min.css">
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
<script src="assets/ace/ace.js"></script>
<script type="text/javascript" src="assets/js/bootstrap.bundle.min.js"></script>
<style>
.jumbotron {
padding-top: 3rem;
padding-bottom: 3rem;
margin-bottom: 0;
background-color: #fff;
}
@media (min-width: 768px) {
.jumbotron {
padding-top: 6rem;
padding-bottom: 6rem;
}
}
.jumbotron p:last-child {
margin-bottom: 0;
}
.jumbotron-heading {
font-weight: 300;
}
.jumbotron .container {
max-width: 40rem;
}
footer {
padding-top: 3rem;
padding-bottom: 3rem;
}
footer p {
margin-bottom: .25rem;
}
.ace_editor {
border: 1px solid lightgray;
margin: auto;
height: 200px;
}
.scrollmargin {
height: 80px;
text-align: center;
}
</style>
</head>
<body>
<header>
<div class="navbar navbar-dark bg-dark shadow-sm">
<div class="container d-flex justify-content-between">
<a href="/" class="navbar-brand d-flex align-items-center">
<strong>Pusher</strong>
</a>
</div>
</div>
</header>
<main role="main">
<section class="jumbotron text-center">
<div class="container">
<h1 class="jumbotron-heading">Pusher</h1>
<p class="lead text-muted">
Send push notification to android & ios devices.
<br>
This utility is only for testing purpose.
</p>
<p>
<a href="#" class="btn btn-secondary my-2" id="android-btn">Android</a>
<a href="#" class="btn btn-secondary my-2" id="ios-btn">IOS</a>
</p>
</div>
</section>
<div class="album py-5 bg-light">
<div class="container">
<div class="row justify-content-md-center">
<div class="alert alert-primary col col-lg-9" style="display: none;" role="alert">
This is a primary alert—check it out!
</div>
</div>
<div class="row justify-content-md-center">
<div class="col col-lg-6" id="android-form">
<form>
<div class="form-group">
<label for="android[serverKey]">Server Key</label>
<input type="text" class="form-control" name="android[server_key]"
placeholder="Server Key">
</div>
<div class="form-group">
<label for="android[title]">Device Token</label>
<input type="text" class="form-control" name="android[device_token]" placeholder="Device Token">
</div>
<div class="form-group">
<label for="android[json]">JSON</label>
<div id="android[json]" style="height: 400px;"></div>
</div>
<input type="hidden" name="isAndroid" value="true">
<button type="submit" class="btn btn-primary">Send</button>
</form>
</div>
<div class="col col-lg-6" id="ios-form" style="display: none;">
<form id="android-sending">
<div class="form-group">
<label for="ios[pemFile]">Pem File</label>
<input type="file" class="form-control-file" id="ios[pemFile]" name="ios[pemFile]">
</div>
<div class="form-group">
<label for="ios[pass_phrase]">Password or Passphrase</label>
<input type="text" class="form-control" id="ios[pass_phrase]" name="ios[pass_phrase]" placeholder="Password or passphrase">
</div>
<div class="form-group">
<label for="ios[device_token]">Device Token</label>
<input type="text" class="form-control" id="ios[device_token]" name="ios[device_token]" placeholder="Device Token">
</div>
<div class="form-group">
<label for="ios[json]">JSON</label>
<div id="ios[json]" style="height: 400px;"></div>
</div>
<!--<div class="form-group">
<label for="ios[is_production]">Production</label>
<input type="checkbox" id="ios[is_production]">
</div>-->
<input type="hidden" name="isIOS" value="true">
<button type="submit" class="btn btn-primary">Submit</button>
</form>
</div>
</div>
</div>
</div>
<script type="text/javascript">
var editorAndroid = ace.edit("android[json]", {
theme: "ace/theme/clouds",
mode: "ace/mode/json"
});
var editorIOS = ace.edit("ios[json]", {
theme: "ace/theme/clouds",
mode: "ace/mode/json"
});
function getFormData($form){
var unindexed_array = $form.serializeArray();
var indexed_array = {};
$.map(unindexed_array, function(n, i){
indexed_array[n['name']] = n['value'];
});
return indexed_array;
}
jQuery(document).ready(function($) {
let androidJson = JSON.stringify({
"message":"message",
"title":"title",
"vibrate":1,
"sound":1,
"type":"brand",
"id":"2",
"image":"https://www.savyour.com.pk/assets/images/deal_avail_banner.png",
"icon":"http://pngimg.com/uploads/google/google_PNG19635.png"
}, null, 2);
editorAndroid.setValue(androidJson, 1);
let iosJson = JSON.stringify({
"aps": {
"alert": {
"body": "Body for the notification.",
"title": "Super!"
},
"badge" : 0,
"sound":"default",
"mutable-content": 1,
"category": "imageCategory"
},
"data": {
"id": 2,
"outlet_id":240,
"type": "brand",
"image": "https://www.savyour.com.pk/assets/images/deal_avail_banner.png"
}
}, null, 2);
editorIOS.setValue(iosJson, 1);
let $androidForm = $("#android-form");
let $iosForm = $("#ios-form");
$("#android-btn").on('click', function(e){
e.preventDefault();
hideMessage();
$iosForm.fadeOut(function() {
$androidForm.fadeIn();
});
});
$("#ios-btn").on('click', function(e){
e.preventDefault();
hideMessage();
$androidForm.fadeOut(function() {
$iosForm.fadeIn();
});
});
$androidForm.on('submit', 'form', function(e) {
e.preventDefault();
let $this = $(this);
let $data = getFormData($this);
disableBtn($this, true);
$data['android[json]'] = editorAndroid.getValue();
$.ajax({
'url': 'sender.php',
'method': 'POST',
'data': $data
}).success(function(response) {
response = JSON.parse(response);
console.log(response);
showMessage(response.status ? response.message : response.error, response.status);
disableBtn($this, false);
}).error(function() {
showMessage("Some thing went wrong!", false);
disableBtn($this, false);
})
});
$iosForm.on('submit', 'form', function(e) {
e.preventDefault();
let $this = $(this);
let $data = $this.serializeArray();
let fileObj = $("input[type='file']")[0];
//disableBtn($this, true);
let formData = new FormData();
for(let $fieldIndex in $data) {
let field = $data[$fieldIndex];
formData.append(field.name, field.value);
}
formData.append('ios[json]', editorIOS.getValue());
if(fileObj.files.length <= 0) {
showMessage("Please select .pem file", false);
return;
}
hideMessage();
formData.append("certificate", fileObj.files[0], 'certificate.pem');
disableBtn($this, true);
$.ajax({
'url': 'sender.php',
'method': 'POST',
'data': formData,
cache: false,
processData: false,
contentType: false,
}).success(function(response) {
response = JSON.parse(response);
console.log(response);
showMessage(response.status ? response.message : response.error, response.status);
disableBtn($this, false);
}).error(function() {
showMessage("Some thing went wrong!", false);
disableBtn($this, false);
})
});
function showMessage(message, success) {
let alert = $('.alert');
alert.removeClass('alert-success');
alert.removeClass('alert-danger');
let currentClass = success ? 'alert-success': 'alert-danger';
alert.addClass(currentClass);
alert.text(message);
alert.show();
}
function hideMessage() {
$(".alert").hide();
}
function disableBtn(form, isDisable) {
form.find('button').eq(0).prop('disabled', isDisable)
}
});
</script>
</main>
<footer class="text-muted">
<div class="container">
<p class="float-right">
<a href="#">Back to top</a>
</p>
</div>
</footer>
</body>
</html>