How to send message from WhatsApp in PHP with WhatsAPI Official?

非 Y 不嫁゛ 提交于 2019-12-31 08:53:07

问题


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:

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 ?


回答1:


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..




回答2:


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



来源:https://stackoverflow.com/questions/29672255/how-to-send-message-from-whatsapp-in-php-with-whatsapi-official

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!