通过使用 WhatsApp api 和 Ultramsg 发送 excel 文件作为 base64
send excel file as base64 via using WhatsApp api with Ultramsg
我正在尝试将 excel 文件转换为 base64 以使用 Ultramsg 发送 WhatsApp API :
<?php
require_once ('vendor/autoload.php'); // if you use Composer
//require_once('ultramsg.class.php'); // if you download ultramsg.class.php
$token=""; // Ultramsg.com token
$instance_id=""; // Ultramsg.com instance id
$client = new UltraMsg\WhatsAppApi($token,$instance_id);
$to="";
$filename="test.xlsx";
$document = base64_encode(file_get_contents("test.xlsx"));
$api=$client->sendDocumentMessage($to,$filename,$document);
print_r($api);
但是我看到这个错误:
Array
(
[error] => Array
(
[0] => Array
(
[document] => file extension not supported
)
)
)
您需要为 Microsoft 添加 MIME 类型 Excel
.xls=application/vnd.ms-excel
要么
.xlsx=application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
$document ="data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;base64,".$document;
所以,试试这个代码块并享受 (: :
<?php
require_once ('vendor/autoload.php'); // if you use Composer
//require_once('ultramsg.class.php'); // if you download ultramsg.class.php
$token=""; // Ultramsg.com token
$instance_id=""; // Ultramsg.com instance id
$client = new UltraMsg\WhatsAppApi($token,$instance_id);
$to="";
$filename="test.xlsx";
$document = base64_encode(file_get_contents("test.xlsx"));
$document ="data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;base64,".$document;
$api=$client->sendDocumentMessage($to,$filename,$document);
print_r($api);
我正在尝试将 excel 文件转换为 base64 以使用 Ultramsg 发送 WhatsApp API :
<?php
require_once ('vendor/autoload.php'); // if you use Composer
//require_once('ultramsg.class.php'); // if you download ultramsg.class.php
$token=""; // Ultramsg.com token
$instance_id=""; // Ultramsg.com instance id
$client = new UltraMsg\WhatsAppApi($token,$instance_id);
$to="";
$filename="test.xlsx";
$document = base64_encode(file_get_contents("test.xlsx"));
$api=$client->sendDocumentMessage($to,$filename,$document);
print_r($api);
但是我看到这个错误:
Array
(
[error] => Array
(
[0] => Array
(
[document] => file extension not supported
)
)
)
您需要为 Microsoft 添加 MIME 类型 Excel .xls=application/vnd.ms-excel 要么 .xlsx=application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
$document ="data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;base64,".$document;
所以,试试这个代码块并享受 (: :
<?php
require_once ('vendor/autoload.php'); // if you use Composer
//require_once('ultramsg.class.php'); // if you download ultramsg.class.php
$token=""; // Ultramsg.com token
$instance_id=""; // Ultramsg.com instance id
$client = new UltraMsg\WhatsAppApi($token,$instance_id);
$to="";
$filename="test.xlsx";
$document = base64_encode(file_get_contents("test.xlsx"));
$document ="data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;base64,".$document;
$api=$client->sendDocumentMessage($to,$filename,$document);
print_r($api);