Yowsup: Send message with PHP

Created on 9 Jul 2017  路  5Comments  路  Source: tgalal/yowsup

Hey, guys! I tried to develop a code in PHP to send the messages with PHP, it's a simple code. It sends the command to my VPS to try to send the message but it did not work, both the yowsup and the php code are in my VPS. Here is the code.

<?php $output = shell_exec('yowsup-cli demos -d -s 557788759298 "Menssage" -c /home/workspace/config.conf'); echo "<pre>$output</pre>"; ?>

Here is the code return.

yowsup-cli v2.0.15
yowsup v2.5.2

Copyright (c) 2012-2016 Tarek Galal
http://www.openwhatsapp.org

This software is provided free of charge. Copying and redistribution is
encouraged.

If you appreciate this software and you would like to support future
development please consider donating:
http://openwhatsapp.org/yowsup/donate


If i try the same code in the terminal, its works.

yowsup-cli demos -d -s 557788759298 "Menssage" -c /home/workspace/config.conf

yowsup-cli v2.0.15
yowsup v2.5.2

Copyright (c) 2012-2016 Tarek Galal
http://www.openwhatsapp.org

This software is provided free of charge. Copying and redistribution is
encouraged.

If you appreciate this software and you would like to support future
development please consider donating:
http://openwhatsapp.org/yowsup/donate

DEBUG:yowsup.env.env:Env not set, setting it to s40
DEBUG:yowsup.env.env:Current env changed to s40
DEBUG:yowsup.stacks.yowstack:Initializing stack
DEBUG:yowsup.stacks.yowstack:Constructed Network Layer
DEBUG:yowsup.stacks.yowstack:Constructed Stanza Regulator Layer
DEBUG:yowsup.stacks.yowstack:Constructed Crypt Layer
DEBUG:yowsup.stacks.yowstack:Constructed Coder Layer
DEBUG:yowsup.stacks.yowstack:Constructed Logger Layer
DEBUG:yowsup.stacks.yowstack:Constructed
DEBUG:yowsup.stacks.yowstack:Constructed Axolotl Layer -
DEBUG:yowsup.stacks.yowstack:Constructed Authentication Layer - Messages Layer - Receipt Layer - Ack Layer - Presence Layer - Ib Layer - Iq Layer - n
otification Ib Layer - Iq Layer - Chatstate Layer - call Layer - Groups Iq Layer - Media Layer - Privacy Layer - Profiles Layer
DEBUG:yowsup.stacks.yowstack:Constructed Interface Layer
DEBUG:yowsup.layers.network.layer:Connecting to e2.whatsapp.net:443
DEBUG:yowsup.layers.logger.layer:tx:

DEBUG:yowsup.layers.logger.layer:tx:

O\x94B#p\xb9\xbb\xef\x90+M
j\xc8{e@\xdc\xd7G\xe8\xd4\xd8\xc7\xf1\xcdsv\xf1,EDBAV\xf2T\x94\xd7\xc5\xb4\xbcA\xffUkq#S\xea\xb7Z\xb2\xa2:0K\xe4l_

HEX3:b'4f1294422370b9bbef902b4d080b6a1f0ec87b6540dcd74715e8d4d8c7f1cd7376f12c16164544424156f25494d7c5b4bc1e41ff01556b712353eab75ab2a23a304be46c5f0b'

DEBUG:yowsup.layers.logger.layer:rx:

DEBUG:yowsup.layers.logger.layer:rx:

y\x86\x91n'xz\xe5\x8eM\xe6\xec\xbb \xe9%
HEX3:b'79861a916e271d787ae58e4de6ecbb09e9062513'

DEBUG:yowsup.layers.protocol_iq.layer:starting ping thread.
DEBUG:yowsup.layers.logger.layer:tx:


b'3\x08\xde\x9d\xa5\x04\x12!\x05\xc8\xe4\xc5\xfe\xed\xeb1t\xd3o|=\xd8\xc5\xc8\xbfn4\xbeP\x97\xbd\xc4\xf6K\xb8\x14\xbf\x95loo\x1a!\x05k\x87B\xf0D\xcck
\x8a\x1e\xe8\xb4J\x8f\x0e\xd9\x91\x07\xe1\xb0\xa6\x0b\x19odf\x80\xf7\x1dy\xac\xfcO"\xb3\x013\n!\x05!\xf5\x0b\xb9\x00\xa5\r\x80\xad\xdd\xc2?B\xd8;+\xf
e=`9\xde\xfb\x84\xb0S\x89\xb2\xd0\xb32f\x00\x10\t\x18\x00"\x80\x01~3y\xbc\xec\x16\xc2\xe9\xe2*\xe7\x8cFN\x82\x045\xad\x80\xcf\x94\t\x9ev\x05\xac\x08\
x0b\xc0C\xdb\x01\x1cW\xff\xc9@+\x17,J\xed\x1d\xa3\xcc|\xb9\xa1\xb9t\xc4\x8fG\xbcs\xff\xfbc%\xa2\xd0}\x0c\xc0\x13\x16,\xb4,J\xabK4\xa0\x89e\xa1\xa94=\
xd9\xb6\xe5\xc3\xab\xdfR\xa5\xbe\x7fN\xef\xf4BfS\x0b\x03\x1f\x8eX@\x01G\xf4\r\x8a\xa7RD\x994\xe6e\xca\x12\xc2\x04\x96\x11\xe9\xa9\x10 B\xf9[\x99\x08\
xc7N\x08{\xdb\x07\x9c(\xef\xfa\xac\xf4\r0\x04'
HEX:b'3308de9da504122105c8e4c5feedeb3174d36f7c3dd8c5c8bf6e34be5097bdc4f64bb814bf956c6f6f1a21056b8742f044cc6b8a1ee8b44a8f0ed99107e1b0a60b196f646680f71
d79acfc4f22b301330a210521f50bb900a50d80adddc23f42d83b2bfe3d6039defb84b05389b2d0b3326600100918002280017e3379bcec16c2e9e22ae78c464e820435ad80cf94099e76
05ac080bc043db011c57ffc9402b172c4aed1da3cc7cb9a1b974c48f47bc73fffb6325a2d07d0cc013162cb42c4aab4b34a08965a1a9343dd9b6e5c3abdf52a5be7f4eeff44266530b031
f8e58400147f40d8aa752449934e665ca12c2049611e9a9102042f95b9908c74e087bdb079c28effaacf40d3004'

DEBUG:yowsup.layers.logger.layer:rx:



DEBUG:yowsup.layers.logger.layer:rx:

INFO:yowsup.demos.sendclient.layer:Message sent

Yowsdown

Most helpful comment

Please I want send/received message with PHP help me please

All 5 comments

  • Does $output provide any information?

  • Does shell_exec have the correct permissions?

this is a information provided by $output

yowsup-cli v2.0.15
yowsup v2.5.2

Copyrig

Copyright (c) 2012-2016 Tarek Galal
http://www.openwhatsapp.org

This software is provided free of charge. Copying and redistribution is
encouraged.

If you appreciate this software and you would like to support future
development please consider donating:
http://openwhatsapp.org/yowsup/donate

As for the shell_exec permissions, I think everything is ok because I have tested some commands and it worked.

  1. Add debug logs to your question (-d flag to enable it)
  2. I suppose that you are running php from apache so you are using www-data user to execute yowsup-cli. So, It is using its home to get the encryption database.

First of all validate which user is running PHP and save in the home of the user used by PHP the .yowsup folder.
I at least use these two functions for sending:

function runCommand($bin, $command = '', $force = true){
$stream = null;
$bin .= $force ? ' 2>&1' : '';

    $descriptorSpec = array
    (
        0 => array('pipe', 'r'),
        1 => array('pipe', 'w')
    );

    $process = proc_open($bin, $descriptorSpec, $pipes);

    if (is_resource($process))
    {
        fwrite($pipes[0], $command);
        fclose($pipes[0]);

        $stream = stream_get_contents($pipes[1]);
        fclose($pipes[1]);

        proc_close($process);
    }

    return trim($stream);
}
function sendWhatsapp($phone,$msj){
    $send = $this->runCommand('yowsup-cli demos --login phonesend:keysend -s '.$phone.' "'.$msj."');
    if(explode(':',$send)[2] == 'Message sent'){
        return true;
    }else{
        return false;
    }
}

Please I want send/received message with PHP help me please

Was this page helpful?
0 / 5 - 0 ratings

Related issues

EliasinnKamachoo picture EliasinnKamachoo  路  3Comments

abhiroock picture abhiroock  路  5Comments

mathslimin picture mathslimin  路  4Comments

alexvong1995 picture alexvong1995  路  4Comments

MauricioAHM picture MauricioAHM  路  5Comments