我在服务器上有一个小PHP脚本,它从远程服务器上的curl命令获取数据的JSON转储。
php脚本通过邮戳给我发电子邮件,但是它只是通过电子邮件发送原始的JSON数据,这显然是非常难以理解的。
我想在发送之前美化然后解析数据。
所以当前的PHP脚本是
<?php
$payload = file_get_contents('php://input');
$serverToken = "*****";
$json = json_encode(array(
'From' => 'email',
'To' => 'email',
'Subject' => 'Server Info',
'HtmlBody' => $payload,
'TextBody' => $payload
));
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://api.postmarkapp.com/email');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Accept: application/json',
'Content-Type: application/json',
'X-Postmark-Server-Token: ' . $serverToken
));
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
$response = json_decode(curl_exec($ch), true);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
我将通过电子邮件发送给您......
{ "IP": "78.122.144", "SERIAL" : "C02SQ5888TUA", "Date", "Fri 23 Jun 2017 18:05:01 BST" }
在线美化将把它变成
{
"IP": "78.122.144",
"SERIAL": "C02SQ5888TUA",
"DATE": "Fri 23 Jun 2017 18:05:01 BST"
}
但我真的很喜欢这封电子邮件的内容......
IP: 78.122.144
SERIAL: C02SQ5888TUA
DATE: Fri 23 Jun 2017 18:05:01 BST
{}&#34;并且,删除。
有人可以建议如何让脚本/服务器这样做,并且锦上添花就是将序列号放在电子邮件的主题上。
示例curl命令是:
curl -H "Content-Type: application/json" https://url.com/first.php -d '{ "IP Address": "'"$(dig +short myip.opendns.com @resolver1.opendns.com)"'", "SERIAL": "'"$(system_profiler SPHardwareDataType | awk '/Serial/ {print $4}')"'", "Date", "'"$(date)"'" }'
答案 0 :(得分:1)
您可以这样做(用脚本替换脚本中的第一行)
$payload = file_get_contents('php://input');
$jsonArray = json_decode($payload);
$payload = "";
foreach($jsonArray as $key => $value){
$payload .= $key . ": " . $value . "\n";
}
这应该使有效载荷成为一个漂亮的字符串。
要将序列号添加到电子邮件主题,您需要做的只是
...
'Subject' => "Server Info " . $jsonArray['SERIAL'],
...
或者你可以做到
$payload = file_get_contents('php://input');
$payload = print_r($payload, true);
答案 1 :(得分:0)
你可以制作
{
"authHost": "http://pikirler.dev",
"authEndpoint": "/broadcasting/auth",
"clients": [
{
"appId": "2051a3c22fdd8a43",
"key": "500c9e2934af4f6e93892f56abfcdc27"
}
],
"database": "redis",
"databaseConfig": {
"redis": {
"port": "6379",
"host": "127.0.0.1"
},
"sqlite": {
"databasePath": "/database/laravel-echo-server.sqlite"
}
},
"devMode": true,
"host": "pikirler.dev",
"port": "6001",
"protocol": "http",
"socketio": {},
"sslCertPath": "",
"sslKeyPath": ""}