PHP kullanarak kolayca WhatsApp API ile Mesaj Gönderme

Tanıtım

Bu dersimizde PHP kullanarak WhatsApp API üzerinden mesaj göndermek için bir sayfa oluşturacağız.

Kurulum

Sadece ultramsg.class.php dosyasını indirin veya Composer’ı kullanın:

composer require ultramsg/whatsapp-php-sdk

kimlik doğrulama

Kaydolun ve örnek kontrol panelinize gidin ve kimlik doğrulaması için kullanılacak Örnek Kimliğinizi ve Simgenizi kopyalayın.

PHP kullanarak WhatsApp API için örnek kullanım:

İlk WhatsApp mesajınızı gönderin

require_once ('vendor/autoload.php'); // if you use Composer
//require_once('ultramsg.class.php'); // if you download ultramsg.class.php
	
$token="tof7lsdJasdloaa57e"; // Ultramsg.com token
$instance_id="instance1150"; // Ultramsg.com instance id
$client = new UltraMsg\WhatsAppApi($token,$instance_id);
	
$to="put_your_mobile_number_here"; 
$body="Hello world"; 
$api=$client->sendChatMessage($to,$body);
print_r($api);
  • $to: Alıcının uluslararası biçimli WhatsApp numarası, örneğin +14155552671 veya kişi veya grup için sohbet kimliği, örneğin [email protected] veya [email protected]
  • $body : Mesaj metni.

Not: Bir gruba WhatsApp mesajlarının nasıl gönderileceğini burada görebilirsiniz.

Resim Gönder

$to="put_your_mobile_number_here"; 
$caption="image Caption"; 
$image="https://file-example.s3-accelerate.amazonaws.com/images/test.jpg"; 
$api=$client->sendImageMessage($to,$image,$caption);
print_r($api);

Belge Gönder

$to="put_your_mobile_number_here"; 
$filename="image Caption"; 
$document="https://file-example.s3-accelerate.amazonaws.com/documents/cv.pdf"; 
$api=$client->sendDocumentMessage($to,$filename,$document);
print_r($api);

Ses Gönder

$to="put_your_mobile_number_here"; 
$audio="https://file-example.s3-accelerate.amazonaws.com/audio/2.mp3"; 
$api=$client->sendAudioMessage($to,$audio);
print_r($api);

Ses Gönder

Telefon numarasına veya gruba bir ppt ses kaydı gönderebilirsiniz, Ancak WhatsApp bu uzantıya duyarlıdır, OGG formatında olması gerekir ve codec bileşenleri opus olmalıdır, Daha fazla bilgi için bu makaleye göz atabilirsiniz.

$to="put_your_mobile_number_here"; 
$audio="https://file-example.s3-accelerate.amazonaws.com/voice/oog_example.ogg"; 
$api=$client->sendVoiceMessage($to,$audio);
print_r($api);

Video Gönder

$to="put_your_mobile_number_here"; 
$video="https://file-example.s3-accelerate.amazonaws.com/video/test.mp4"; 
$api=$client->sendVideoMessage($to,$video);
print_r($api);
$to="put_your_mobile_number_here"; 
$link="https://ultramsg.com"; $api=$client->sendLinkMessage($to,$link);
print_r($api);

Kişi Gönder

$to="put_your_mobile_number_here"; 
$contact="[email protected]"; 
$api=$client->sendContactMessage($to,$contact);
print_r($api);

Konum göndermek

$to="put_your_mobile_number_here"; 
$address="ABC company \n Sixth floor , office 38"; 
$lat="25.197197"; 
$lng="55.2721877"; 
$api=$client->sendLocationMessage($to,$address,$lat,$lng);
print_r($api);

Vcard gönder

$to="put_your_mobile_number_here"; 
$vcard="BEGIN:VCARD
VERSION:3.0
N:lastname;firstname
FN:firstname lastname
TEL;TYPE=CELL;waid=14000000001:14000000002
NICKNAME:nickname
BDAY:01.01.1987
X-GENDER:M
NOTE:note
ADR;TYPE=home
ADR;TYPE=work
END:VCARD";
$vcard = preg_replace("/[\n\r]/", "\n", $vcard);
$api=$client->sendVcardMessage($to,$vcard);
print_r($api)

Bu videoda önceki adımları görebilir ve Tam WhatsApp API Belgelerini görebilirsiniz.

Ultramsg WhatsApp API PHP SDK kullanıyor musunuz ?