Сегодня я хочу выполнить задачу по загрузке PDF-файла с помощью Chat-API WhatsApp.
Может быть, эту задачу я буду запускать в оболочке Windows, но сейчас я тестирую ее на PHP-файле.
Я использую такую документацию
Код: Выделить всё
$to = 'myPhone';
$url = 'https://chat-apiurl?andtokenhere';
$imageLocation = 'http://localhost/chat-api/file.pdf';
$data = [
'phone'=> $to,
'body' =>$imageLocation,
'filename'=>"filepdf.jpg",
'caption'=>'test',
];
$send = json_encode($data);
$options = stream_context_create(['http' => [
'method' => 'POST',
'header' => 'Content-type: application/json',
'content' => $send,
]
]);
// Send a request
$result = file_get_contents($url, false, $options);
echo $result;
?>
Код: Выделить всё
{"error":"Unsupported file type"}Код: Выделить всё
{"sent":false,"message":"Message was not sent: empty body. Please provide message text in body parameter in JSON POST."}Код: Выделить всё
$getExtension = explode(".",$imageLocation);
$base64 = 'data:image/'.$getExtension[1].';base64,'.file_get_contents($imageLocation);
Большое спасибо
Подробнее здесь: https://stackoverflow.com/questions/631 ... p-chat-api
Мобильная версия