Saturday 4 September 2021

Send Whatsapp Message via PHP Code

 

How to Send and Receive Messages in WhatsApp using PHP


In this tutorial you will see How to Send and Receive Messages in WhatsApp using PHP.

Prerequisite :-

# Chat-API Token , Refer : https://www.phphive.info/255/get-whatsapp-password/



Code:

<?php
 
$chatApiToken = ""; // Get it from https://www.phphive.info/255/get-whatsapp-password/
 
$number = "919999999999"; // Number
$message = "Hello :)"; // Message
 
$curl = curl_init();
curl_setopt_array($curl, array(
  CURLOPT_URL => 'http://chat-api.phphive.info/message/send/text',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_POSTFIELDS =>json_encode(array("jid"=> $number."@s.whatsapp.net", "message" => $message)),
  CURLOPT_HTTPHEADER => array(
    'Authorization: Bearer '.$chatApiToken,
    'Content-Type: application/json'
  ),
));
 
$response = curl_exec($curl);
curl_close($curl);
echo $response;



Sample Output :

For Receiving Messages

Refer : http://chat-api.phphive.info/docs#/device/messagesRequest

Q : Is There any Daily Limit for Using this API ?

Ans : No! There’s No Daily Limit. But Spamming is Obviously not allowed. We are keeping records of IP’s, if we find someone Spamming our Service then that IP will be Banned.

Chat-API Full Documentation available at http://chat-api.phphive.info/docs


Thanks You

No comments:

Post a Comment

Send Whatsapp Message via PHP Code

  How to Send and Receive Messages in WhatsApp using PHP In this tutorial you will see How to Send and Receive Messages in WhatsApp using PH...