Dreamweaver+Bootstrap+PHP EP.30 การเขียน php ส่งข้อความ แจ้งเตือน line notify api
Dreamweaver+Bootstrap+PHP EP.30 การเขียน php
ส่งข้อความ แจ้งเตือน line notify api คือการส่งข้อความ
ผ่านหน้าเว็บ แล้วให้แจ้งเตือนผ่าน Line
หน้า from ส่งข้อมูล s_l.html
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 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" integrity="sha384-9gVQ4dYFwwWSjIDZnLEWnxCjeSWFphJiwGPXr1jddIhOegiu1FwO5qRGvFXOdJZ4" crossorigin="anonymous"> <title>Untitled Document</title> </head> <body> <br /> <br /> <br /> <br /> <br /> <div class="container"> <div class="row"> <div class="col-md-2"> </div> <div class="col-md-8"> <div class="row"> <div class="col-md-12 mx-auto"> <div class="card border-secondary"> <div class="card-header"> <h3 class="mb-0 my-2">php sent line</h3> </div> <div class="card-body"> <form action="s_lok.php" method="post" enctype="multipart/form-data" class="form" role="form" autocomplete="off"> <div class="form-group"> <label for="exampleFormControlTextarea1">Message</label> <textarea name="mesg" rows="7" class="form-control" id="exampleFormControlTextarea1" placeholder="Message"> </textarea> </div> <div class="form-group"> <button type="submit" class="btn btn-success btn-xs btn-block">Sentline</button> </div> </form> </div> </div> </div> </div> <!--/row--> </div> <!--/col--> </div> <!--/row--> <div class="col-md-2"> </div> </div> <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js" integrity="sha384-cs/chFZiN24E4KMATLdqdvsezGxaGsi4hLGOzlXwp5UZB1LY//20VyM2taTB4QvJ" crossorigin="anonymous"></script> <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js" integrity="sha384-uefMccjFJAIv6A+rW+L4AHf99KvxDjWSu1z9VI8SKNVmz4sk7buKt/6v9KI65qnm" crossorigin="anonymous"></script> </body> </html> |
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 |
<?php function send_line_notify($message, $token) { $ch = curl_init(); curl_setopt( $ch, CURLOPT_URL, "https://notify-api.line.me/api/notify"); curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt( $ch, CURLOPT_POST, 1); curl_setopt( $ch, CURLOPT_POSTFIELDS, "message=$message"); curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1); $headers = array( "Content-type: application/x-www-form-urlencoded", "Authorization: Bearer $token", ); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1); $result = curl_exec( $ch ); curl_close( $ch ); return $result; } $mesg = $_POST['mesg']; $message = $mesg; $token = 'ใส่token'; echo send_line_notify($message, $token); ?> |