Created
February 9, 2017 06:34
-
-
Save tedshd/e3a84edd2434011384534b69898c4e79 to your computer and use it in GitHub Desktop.
push cms
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$serverKey = $_POST['serverKey']; | |
$iid = $_POST['iid']; | |
$title = $_POST['title']; | |
$message = $_POST['message']; | |
$icon = $_POST['icon']; | |
$title_web = $_POST['title']; | |
$body_web = $_POST['body']; | |
$icon_web = $_POST['icon']; | |
$click_action = $_POST['click_action']; | |
$type = $_POST['type']; | |
$notification_style = $_POST['notification_style']; | |
$message_id = $_POST['message_id']; | |
$ts = $_POST['ts']; | |
$platform = $_POST['platform']; | |
if (empty($iid)) { | |
$iid = '/topics/' . $_POST['topic']; | |
$body = $body . $_POST['topic']; | |
} | |
if ($platform === 'web') { | |
$command = 'curl -X POST -H "Authorization: key=' . $serverKey . '" -H "Content-Type: application/json" -d \'{ | |
"notification": { | |
"title": "' . $title_web . '", | |
"body": "' . $body_web . '", | |
"icon": "' . $icon_web . '", | |
"click_action": "' . $click_action . '" | |
}, | |
"time_to_live": 60, | |
"to": "' . $iid . '", | |
"priority": "high" | |
}\' "https://fcm.googleapis.com/fcm/send"'; | |
} | |
if ($platform === 'app') { | |
$command = 'curl -X POST -H "Authorization: key=' . $serverKey . '" -H "Content-Type: application/json" -d \'{ | |
"time_to_live": 60, | |
"to": "' . $iid . '", | |
"data": { | |
"type": "' . $type . '", | |
"notification_style": "' . $notification_style . '", | |
"title": "' . $title . '", | |
"message": "' . $message . '", | |
"url": "' . $click_action . '", | |
"user": null, | |
"message_id": "' . $message_id . '", | |
"icon": "' . $icon . '", | |
"timestamp": "' . $ts . '" | |
}, | |
"priority": "high" | |
}\' "https://fcm.googleapis.com/fcm/send"'; | |
} | |
exec($command, $output, $return_var); | |
echo json_encode($output); | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"> | |
<title>Send</title> | |
<link href="https://cdnjs.cloudflare.com/ajax/libs/pure/0.6.0/pure-min.css" rel="stylesheet"> | |
<!-- <link rel="stylesheet" href="https://unpkg.com/purecss@0.6.2/build/base-min.css"> --> | |
<link rel="stylesheet" href="https://unpkg.com/purecss@0.6.2/build/grids-min.css"> | |
<link rel="stylesheet" href="https://unpkg.com/purecss@0.6.2/build/grids-responsive-min.css"> | |
<style> | |
pre {outline: 1px solid #ccc; padding: 5px; margin: 5px; } | |
.string { color: green; } | |
.number { color: darkorange; } | |
.boolean { color: blue; } | |
.null { color: magenta; } | |
.key { color: red; } | |
</style> | |
</head> | |
<body> | |
<form class="pure-form pure-form-aligned"> | |
<h1>Push service</h1> | |
<div class="pure-g"> | |
<div class="pure-u pure-u-md-1-3 pure-u-lg-1-3"> | |
<h2>Push service</h2> | |
<fieldset> | |
<div class="pure-control-group"> | |
<label for="name">server key</label> | |
<input id="name" type="text" placeholder="server key" value=""> | |
</div> | |
<div class="pure-control-group"> | |
<label for="iid">IID token to</label> | |
<input id="iid" type="text" placeholder="" value=""> | |
</div> | |
</fieldset> | |
</div> | |
<div class="pure-u pure-u-md-1-3 pure-u-lg-1-3"> | |
<h2>App</h2> | |
<fieldset> | |
<div class="pure-control-group"> | |
<label for="type">type</label> | |
<input id="type" type="text" placeholder="this is type" value=""> | |
</div> | |
<div class="pure-control-group"> | |
<label for="notification_style">notification_style</label> | |
<input id="notification_style" type="text" placeholder="this is notification_style" value=""> | |
</div> | |
<div class="pure-control-group"> | |
<label for="title">title</label> | |
<input id="title" type="text" placeholder="this is title" value=""> | |
</div> | |
<div class="pure-control-group"> | |
<label for="message">message</label> | |
<input id="message" type="text" placeholder="this is message" value=""> | |
</div> | |
<div class="pure-control-group"> | |
<label for="url">url</label> | |
<input id="url" type="text" placeholder="this is url" value=""> | |
</div> | |
<div class="pure-control-group"> | |
<label for="message_id">message_id</label> | |
<input id="message_id" type="text" placeholder="this is message_id" value=""> | |
</div> | |
<div class="pure-control-group"> | |
<label for="icon">icon</label> | |
<input id="icon" type="text" placeholder="this is icon" value=""> | |
</div> | |
<div class="pure-control-group"> | |
<label for="timestamp">timestamp</label> | |
<input id="timestamp" type="text" placeholder="this is timestamp" value=""> | |
</div> | |
<fieldset> | |
<div class="pure-controls"> | |
<button id="app" type="submit" class="pure-button pure-button-primary">Push App</button> | |
</div> | |
</div> | |
<div class="pure-u pure-u-md-1-3 pure-u-lg-1-3"> | |
<h2>Web</h2> | |
<fieldset> | |
<div class="pure-control-group"> | |
<label for="title_web">title</label> | |
<input id="title_web" type="text" placeholder="" value="this is title"> | |
</div> | |
<div class="pure-control-group"> | |
<label for="body_web">body</label> | |
<input id="body_web" type="text" placeholder="Enter something here..." value="Enter content"> | |
</div> | |
<div class="pure-control-group"> | |
<label for="icon_web">icon</label> | |
<input id="icon_web" type="text" placeholder="" value="demo/fcm/quickstart-js/messaging/firebase-logo.png"> | |
</div> | |
<div class="pure-control-group"> | |
<label for="click_action">click_action</label> | |
<input id="click_action" type="text" placeholder="Enter url" value="http://tedshd.io"> | |
</div> | |
<div class="pure-control-group"> | |
<label for="topic">topic</label> | |
<select name="topic" id="topic"> | |
<option value="movie">movie</option> | |
<option value="3c">3c</option> | |
</select> | |
</div> | |
<div class="pure-controls"> | |
<button id="web" type="submit" class="pure-button pure-button-primary">Push Web</button> | |
</div> | |
</fieldset> | |
</div> | |
</div> | |
</form> | |
<div id="log"> | |
</div> | |
</body> | |
<script src="https://rawgit.com/tedshd/ajax/master/ajax.js"></script> | |
<script> | |
document.querySelector('#message_id').value = new Date().getTime(); | |
document.querySelector('#timestamp').value = new Date().getTime(); | |
document.querySelector('#app').addEventListener('click', function (e) { | |
e.preventDefault(); | |
e.stopPropagation(); | |
ajax({ | |
method: 'POST', | |
url: 'json.php', | |
data: { | |
serverKey: document.querySelector('#name').value, | |
iid: document.querySelector('#iid').value, | |
title: document.querySelector('#title').value, | |
message: document.querySelector('#message').value, | |
icon: document.querySelector('#icon').value, | |
click_action: document.querySelector('#click_action').value, | |
type: document.querySelector('#type').value, | |
notification_style: document.querySelector('#notification_style').value, | |
message_id: document.querySelector('#message_id').value, | |
ts: document.querySelector('#timestamp').value, | |
platform: 'app' | |
}, | |
response: 'json', | |
success: function (data) { | |
console.log(data); | |
document.querySelector('#log').innerHTML = syntaxHighlight(JSON.stringify(data)); | |
}, | |
error: function(status, data) { | |
// status = http status | |
// do something | |
document.querySelector('#log').innerHTML = syntaxHighlight(JSON.stringify(data)); | |
} | |
}); | |
}); | |
document.querySelector('#web').addEventListener('click', function (e) { | |
e.preventDefault(); | |
e.stopPropagation(); | |
ajax({ | |
method: 'POST', | |
url: 'json.php', | |
data: { | |
serverKey: document.querySelector('#name').value, | |
iid: document.querySelector('#iid').value, | |
title: document.querySelector('#title_web').value, | |
body: document.querySelector('#body_web').value, | |
icon: document.querySelector('#icon_web').value, | |
click_action: document.querySelector('#click_action').value, | |
topic: document.querySelector('#topic').value, | |
platform: 'web' | |
}, | |
response: 'json', | |
success: function (data) { | |
console.log(data); | |
document.querySelector('#log').innerHTML = syntaxHighlight(JSON.stringify(data)); | |
}, | |
error: function(status, data) { | |
// status = http status | |
// do something | |
document.querySelector('#log').innerHTML = syntaxHighlight(JSON.stringify(data)); | |
} | |
}); | |
}); | |
function syntaxHighlight(json) { | |
if (typeof json != 'string') { | |
json = JSON.stringify(json, undefined, 2); | |
} | |
json = json.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>'); | |
return json.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, function (match) { | |
var cls = 'number'; | |
if (/^"/.test(match)) { | |
if (/:$/.test(match)) { | |
cls = 'key'; | |
} else { | |
cls = 'string'; | |
} | |
} else if (/true|false/.test(match)) { | |
cls = 'boolean'; | |
} else if (/null/.test(match)) { | |
cls = 'null'; | |
} | |
return '<span class="' + cls + '">' + match + '</span>'; | |
}); | |
} | |
</script> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment