 |
|
ที่ทำแบบนี้เพราะว่าพอเปิดแล้วดันส่งแจ้งเตือนย้อนหลังค่ะ มันแจ้งเตือนถี่มากเป็น 500 กว่า
<html>
<head>
<meta charset="utf-8">
<title>แจ้งเตือนอุณหภูมิเกิน</title><!<META HTTP-EQUIV='Refresh' CONTENT = '0;URL=show.php'>
</head>
<body>
<?php
// กรณีต้องการตรวจสอบการแจ้ง error ให้เปิด 3 บรรทัดล่างนี้ให้ทำงาน กรณีไม่ ให้ comment ปิดไป
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
// กรณีมีการเชื่อมต่อกับฐานข้อมูล
include "Connect_DB.php";
//$accToken = "cN4mvyfMPuavWZNivK0ryRQ9hdK3amGveVOSpqz8J1";
date_default_timezone_set("Asia/Bangkok");
$Date = date('Y-m-d');
$Time = date('H:i:s');
$sql = "SELECT * FROM tb_Linenotify ORDER BY ID";
$rsuser = mysqli_query($Connect,$sql);
$sqltem = "SELECT * FROM esp8266 where StrDate ='".$Date."' ";
//$sqltem = "SELECT * FROM esp8266 where StrDate ='".$Date."' group by StrDate";
if ($rstem = mysqli_query($Connect, $sqltem)) {
while ($rowtem = mysqli_fetch_row($rstem)) {
$temperature= $rowtem[1];
if ($temperature > 23){
if ($rsuser = mysqli_query($Connect, $sql)) {
while ($rouser = mysqli_fetch_row($rsuser)) {
$accToken = $rouser[2];
$notifyURL = "https://notify-api.line.me/api/notify";
$headers = array(
'Content-Type: application/x-www-form-urlencoded',
'Authorization: Bearer '.$accToken
);
$mesg= " Temperature = " . $temperature . " ํC อุณหภูมิเกินกำหนด";
$data = array(
'message' => "$mesg",
);
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, $notifyURL);
curl_setopt( $ch, CURLOPT_POST, 1);
curl_setopt( $ch, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec( $ch );
curl_close( $ch );
// ตรวจสอบค่าข้อมูล ว่าเป็นตัวแปร ปรเภทไหน ข้อมูลอะไร
var_dump($result);
// การเช็คสถานะการทำงาน
$result = json_decode($result,TRUE);
if(!is_null($result) && array_key_exists('status',$result)){
echo $result['status'];
if($result['status']==200){
echo "Notify Send Success";
}
}
}
//mysqli_free_result($rouser);
}
}else{
//mysqli_free_result($rouser);
//mysqli_free_result($rowtem);
}
}
//mysqli_free_result($rowtem);
}
mysqli_close($Connect);
?>
</body>
</html>
[/php]
[/php]
[/java]
[/php]
Tag : PHP, MySQL, HTML, jQuery
|
|
 |
 |
 |
 |
Date :
2020-11-26 11:34:13 |
By :
cond525 |
View :
686 |
Reply :
2 |
|
 |
 |
 |
 |
|
|
|
 |