18

I'm trying to use the WhatsApi Official library to send a message via WhatsApp from a php file. I've moved in my Apache web server the library, in a folder call test, like this:

enter image description here

The file whatsapp.php is this one:

    <?php
    require_once './src/whatsprot.class.php';
    $username = "1XXXXXXXXX";
    $password = "password";
    $w = new WhatsProt($username, "0", "My Nickname", true); //Name your application by replacing “WhatsApp Messaging”
    $w->connect();
    $w->loginWithPassword($password);
    $target = '1xxxxxxxxx'; //Target Phone,reciever phone
    $message = 'This is my messagge';
    $w->SendPresenceSubscription($target); //Let us first send presence to user
    $w->sendMessage($target,$message ); // Send Message
    echo "Message Sent Successfully";
?>

I'm facing some problem with the library new WhatsProt(), which blocks all the code (may be sockets ?).

So my question is, how can I fix this problem ? If no, are there any other solution to send message from a pho script ?

I love coding
  • 1,183
  • 3
  • 18
  • 47
  • Which response do you get from the API server? – Ofir Baruch Apr 16 '15 at 10:55
  • The script stops to work before the $w ->connect(); so I can't get the response ! – I love coding Apr 16 '15 at 10:57
  • And you get no errors on your side? Maybe something is wrong with your credentials or the `WhatsProt Class` – Ofir Baruch Apr 16 '15 at 10:59
  • I don't think my credential are wrong. I put as number, "my contry code, without +" and the mobile phone number. I sue Wart in Windows to obtain the password. – I love coding Apr 16 '15 at 11:44
  • 1
    Is there a simple tool to check if the credentials are correct ? – I love coding Apr 16 '15 at 13:11
  • 2
    There is no ***official*** API – candlejack Dec 20 '16 at 21:16
  • I don't like hacks. WhatsApp don't want us to use their system programmatically, so be it . I will not messaging my users with WhatsApp . instead I will use [line messaging API](https://developers.line.me/messaging-api/overview) – Accountant م Apr 05 '17 at 12:19
  • Hey hi, I am going to implement this but first i want to clear my doubt so if you dont mind can you clear it ? 1) Is it possible to send bulk of msg in one day like i need to send message in arround 5/6 lacs numbers daily, so is it possible ? – David Coder Aug 26 '17 at 07:25
  • @candlejack Yes, there is an official API... [Whatsapp Business API](https://www.whatsapp.com/business/api) –  Aug 26 '18 at 18:04

2 Answers2

5

You can use below script to send message from whatsapp in PHP.

https://github.com/venomous0x/WhatsAPI/tree/master/examples

Configure the source code in Apache and run examples/whatsapp.php file.

You have change below configurations.

//simple password to view this script
$config['webpassword'] = 'MakeUpPassword';

and

$config['YOURNAME'] = array(
'id' => 'e807f1fcf82d132f9bb018ca6738a19f',
'fromNumber' => '441234567890',
'nick' => "YOURNICKNAME",
'waPassword' => "EsdfsawS+/ffdskjsdhwebdgxbs=",
'email' => 'testemail@gmail.com',
'emailPassword' => 'gmailpassword'
);

It's working for me..

Jayson
  • 1,105
  • 7
  • 25
  • Thank you. Can you be more precise, about the action/modification should I do ? – I love coding Apr 16 '15 at 11:41
  • you have to do only above configuration and it will work. if you face any problem then let me know. – Jayson Apr 16 '15 at 12:39
  • is it normale that id contains multiple % repeated every 2 char ? Why in my script, it is not required the id ? – I love coding Apr 16 '15 at 13:10
  • yes its normal thing. id is required for unique identity in whatsapp. – Jayson Apr 16 '15 at 13:27
  • well know it seems to work ! Also my script works ! is it possible, that, once I execute the php script, I got a lot of lines back from the page ? is possible to send emoction and message to group ? – I love coding Apr 16 '15 at 14:32
  • got a lot of lines back from the page means? and yes you can send emotions and message in group there is lots of functions are available in `whatsprot.class.php` – Jayson Apr 17 '15 at 04:55
  • From the page I got soma lines back, such as some status of the message. can you make me the example of set the nickname, with: MyNickname+soccer emoction ? – I love coding Apr 17 '15 at 17:12
  • The link is finally dead as its owner has taken it down. – rahulserver Jun 18 '15 at 10:43
  • @jayson can i run it on localhost? (with internet connection) or i must run it on real server ? – IIM NUR DIANSYAH May 24 '16 at 01:33
  • 6
    @Jayson : https://github.com/venomous0x/WhatsAPI/tree/master/examples url is not working. Showing 404 – Lakhan Dec 29 '16 at 12:49
  • @Lakhan if you go to https://github.com/venomous0x/WhatsAPI/ you'll see why. If you look around on github there are plenty of forks prior to the original being taken down though. – Leith Feb 28 '17 at 23:41
  • NOt working I have Downloaded https://github.com/mgp25/Chat-API and past in local host hiting http://localhost/w/examples/whatsup.php But not working what to do ? – SURENDER SINGH Jun 19 '18 at 13:04
0

afaik you are probably better off currently writing an interface to a python project. E.g. have a microservice that does sending of messages for you in python, and you call them via some json request or similar

see this project, looks promising: https://github.com/tgalal/yowsup

it seems like the only viable option so far, as everything else was shut down or has a high probability to get your account banned

see discussion here:

https://stackoverflow.com/a/46635985/533426

Toskan
  • 13,911
  • 14
  • 95
  • 185