Categories
Bookmarked PHP Programming

WhatsAPP moving to new authentication.

Though the new authentication (WUTH-2) is not really new, but few days back they disable the old authentication mechanism. So, just a bookmark to latest version of API: https://github.com/mgp25/WhatsAPI-Official . This is rather refined library and you can feel it when you use it.

Categories
PHP Programming

WhatsApp Messaging from Web

If you need to send WhatsApp message to your friend from Web, you need to find unofficial API as WhatsApp till date do not provide them, and do not allow bulk messaging as well. But in one of my project, I need to send message on whatsapp, for those who subscribe on website to recieve those about our service updates. So, I use WhatsApi (https://github.com/venomous0x/WhatsAPI New URL is https://github.com/WHAnonymous/Chat-API ), simply because it was most recommended API I found. I didn’t even try any other API code, as it works like charm for me. It has AjaxDemo folder in there, with 3 files. Anyone can easily learn the coding from it. So, I don’t go in much of coding part in this article. But here is basic steps with some code. To start with,

  • You will need a Mobile number that will be used to send messages. Make sure that you can recieve SMS on this mobile phone to verify the Whatsapp account.
  • Once you have your phone ready, download WART (https://github.com/shirioko/WART) which provide a simple EXE, to enter your phone and get a Password for API. Remember Whatsapp send password once every 30 minute, so if you want to get new password you have to wait 30 minutes. This step is no longer required as API has registration function available. Please refer API documentation for it.
  • Now, that you have WhatsAPP mobile phone and password, simply try this code.

 

require_once 'whatsprot.class.php';
$username = "11111111111"; //Mobile Phone prefixed with country code so for india it will be 91xxxxxxxx
$password = "somepasswordstring";

$w = new WhatsProt($username, 0, "WhatsApp Messaging", true); //Name your application by replacing "WhatsApp Messaging"
$w->connect();
$w->loginWithPassword($password);

$target = '912222222222'; //Target Phone,reciever phone
$message = 'Your message comes here';

$w->SendPresenceSubscription($target); //Let us first send presence to user
$w->sendMessage($target,$message ); // Send Message

Yes, it was that simple. You can send Image and Video as well, but I am not going to explain them here, though to send Media you need to call ‘$w->pollMessages()’ otherwise your message won’t be sent. Note: all Phone must prefix the country code or it won’t send messages. To send media, you can either give Physical path or a URL to media resource.   EDIT: The API is now moved to new location: https://github.com/mgp25/Chat-API