Heute möchte ich eine Aufgabe zum Hochladen einer PDF-Datei mithilfe der Chat-API für WhatsApp erstellen.
Die Aufgabe werde ich vielleicht auf der Windows-Shell ausführen, aber jetzt Ich teste es mit einer PHP-Datei.
Ich verwende die Dokumentation wie folgt
Code: Select all
$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;
?>
Code: Select all
{"error":"Unsupported file type"}
Code: Select all
{"sent":false,"message":"Message was not sent: empty body. Please provide message text in body parameter in JSON POST."}
Code: Select all
$getExtension = explode(".",$imageLocation);
$base64 = 'data:image/'.$getExtension[1].';base64,'.file_get_contents($imageLocation);
Vielen Dank