|
 |
|
สอบถามเรื่อง line notify callback token ต้องการเก็บ token ลงใน Database |
|
 |
|
|
 |
 |
|
ตอนนี้สามารถลงทะเบียน และขอรับ token ได้แล้ว แต่ถ้าผมต้องการที่จะเก็บ token ลง Database นี่ต้องเขียนเพิ่มยังไงครับ
หลังจากขอ token
callback.php (PHP)
<?php
@ini_set('display_errors', '0');
include "../../include/mySqlFunc.php";
query("Use safety");
define('CLIENT_ID', 'HdfQavbz6uVwANktu6y4Dw');
define('CLIENT_SECRET', 'QT1AzBAm8mzeB3krP7C1TZYM6BNi4Na2iBSi0pj1oI7');
define('LINE_API_URI', 'https://notify-bot.line.me/oauth/token');
define('CALLBACK_URI', 'https://www.my-vngs.com/main/safetyv2/outsource/callback_line.php');
parse_str($_SERVER['QUERY_STRING'], $queries);
$fields = [
'grant_type' => 'authorization_code',
'code' => $queries['code'],
'redirect_uri' => CALLBACK_URI,
'client_id' => CLIENT_ID,
'client_secret' => CLIENT_SECRET,
];
try {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, LINE_API_URI);
curl_setopt($ch, CURLOPT_POST, count($fields));
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$res = curl_exec($ch);
curl_close($ch);
if ($res == false) {
throw new Exception(curl_error($ch), curl_errno($ch));
}
$json = json_decode($res, true);
var_dump($json);
} catch (Exception $e) {
var_dump($e);
}
?>
<html>
<a href="https://notify-bot.line.me/oauth/authorize?response_type=code&client_id=HdfQavbz6uVwANktu6y4Dw&redirect_uri=https://www.my-vngs.com/main/safetyv2/outsource/callback_line.php&scope=notify&state=QT1AzBAm8mzeB3krP7C1TZYM6BNi4Na2iBSi0pj1oI7">
รับการแจ้งเตือนผ่าน LINE Notify
</a>
</html>
Tag : PHP, Ajax, jQuery, Web API

|
ประวัติการแก้ไข 2023-05-26 14:57:03
|
 |
 |
 |
 |
Date :
2023-05-26 14:56:07 |
By :
benlovehi5 |
View :
891 |
Reply :
2 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
หลังจากได้ response หรือมีการ request ไปยัง Line API
Code (PHP)
//...
$data = json_decode($response, true);
if (array_key_exists("access_token", $data)) {
if (!empty($data["access_token"])) {
$access_token = $data["access_token"];
// Insert the access token into the table
$sql = "INSERT INTO line_access_tokens (access_token) VALUES ('$access_token')";
$result = $mysqli->query($sql);
if ($result) {
echo "Access token saved successfully";
} else {
echo "Error saving access token: " . $mysqli->error;
}
} else {
echo "The access token is not valid";
}
} else {
echo "The access token key is not present in the JSON response";
}
จาก กวี 
|
 |
 |
 |
 |
Date :
2023-05-26 22:44:31 |
By :
009 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 02
|