|
 |
|
ส่งรูปผ่าน Line notify อย่างไรครับ ดึง path จาก server แล้วให้แสดงใน line |
|
 |
|
|
 |
 |
|
กำลังพัฒนาระบบแจ้งเตือนผ่าน line notify ครับ
ปัญหาคือ หาวิธีแนบรูปจาก Local ไม่ได้เลยครับ
ถ้าเป็นผ่าน url จะไม่มีปัญหา อัพขึ้น server ชี้ path เต็มๆ ก็ไม่ได้ครับ
เช่น http://172.17.99.99/images/test.jpg ก็ยังไม่ได้ครับ
แต่ถ้าเอา url มาตรวจสอบ จะขึ้นรูป แต่ผ่าน Line จะไม่ได้ครับ
ขอคำชี้แนะด้วยครับ
Code (PHP)
/*-------------line noti----------------------*/
$line_api = 'https://notify-api.line.me/api/notify';
$access_token = 'token_code';
$message = 'test'; //text max 1,000 charecter
$image_thumbnail_url = 'https://dummyimage.com/1024x1024/f598f5/fff.jpg'; // max size 240x240px JPEG
$image_fullsize_url = 'https://dummyimage.com/1024x1024/844334/fff.jpg'; //max size 1024x1024px JPEG
$imageFile = 'copy/240.jpg';
$sticker_package_id = ''; // Package ID sticker
$sticker_id = ''; // ID sticker
$message_data = array(
'imageThumbnail' => $image_thumbnail_url,
'imageFullsize' => $image_fullsize_url,
'message' => $message,
'imageFile' => $imageFile,
'stickerPackageId' => $sticker_package_id,
'stickerId' => $sticker_id
);
$result = send_notify_message($line_api, $access_token, $message_data);
echo '<pre>';
print_r($result);
echo '</pre>';
}
/*-------------line noti----------------------*/
function send_notify_message($line_api, $access_token, $message_data){
$headers = array('Method: POST', 'Content-type: multipart/form-data', 'Authorization: Bearer '.$access_token );
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $line_api);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POSTFIELDS, $message_data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
// Check Error
if(curl_error($ch))
{
$return_array = array( 'status' => '000: send fail', 'message' => curl_error($ch) );
}
else
{
$return_array = json_decode($result, true);
}
curl_close($ch);
return $return_array;
}
Line Document


Tag : PHP, HTML5, JavaScript, jQuery

|
|
 |
 |
 |
 |
Date :
2018-06-14 13:11:13 |
By :
clubp_mark |
View :
15860 |
Reply :
2 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เท่าที่เคยกับ LINE BOT ต้องเป็น HTTPS
|
 |
 |
 |
 |
Date :
2018-06-14 15:15:39 |
By :
Krungsri |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
/*-------------line noti----------------------*/
$line_api = 'https://notify-api.line.me/api/notify';
$access_token = 'token_code';
$message = 'test'; //text max 1,000 charecter
$image_thumbnail_url = 'https://dummyimage.com/1024x1024/f598f5/fff.jpg'; // max size 240x240px JPEG
$image_fullsize_url = 'https://dummyimage.com/1024x1024/844334/fff.jpg'; //max size 1024x1024px JPEG
$imageFile = 'copy/240.jpg';
$sticker_package_id = ''; // Package ID sticker
$sticker_id = ''; // ID sticker
if (function_exists('curl_file_create')) {
$cFile = curl_file_create($imageFile );
} else {
$cFile = '@'.realpath($imageFile );
}
$message_data = array(
'imageThumbnail' => $image_thumbnail_url,
'imageFullsize' => $image_fullsize_url,
'message' => $message,
'imageFile' => $cFile ,
'stickerPackageId' => $sticker_package_id,
'stickerId' => $sticker_id
);
$result = send_notify_message($line_api, $access_token, $message_data);
echo '<pre>';
print_r($result);
echo 'function send_notify_message($line_api, $access_token, $message_data){
$headers = array('Method: POST', 'Content-type: multipart/form-data', 'Authorization: Bearer '.$access_token );
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $line_api);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POSTFIELDS, $message_data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
// Check Error
if(curl_error($ch))
{
$return_array = array( 'status' => '000: send fail', 'message' => curl_error($ch) );
}
else
{
$return_array = json_decode($result, true);
}
curl_close($ch);
return $return_array;
}</pre>';
}
/*-------------line noti----------------------*/
|
 |
 |
 |
 |
Date :
2018-07-06 16:41:46 |
By :
DomiNick7 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 04
|