使用whatsapp php api接收来自多个号码的消息

时间:2016-03-25 06:57:55

标签: php api whatsapp

我能够使用whatsapp api为PHP发送和接收消息,但是API有一个简单的演示只能从一个号码接收消息,你能不能帮助我让它能够从多个号码接收它在数组列表或其他内容中指定?

我正在使用Whatsapp PHP api,即 https://github.com/mgp25/Chat-API

和单个号码发送和接收的代码是。

<?php
session_start();
$_SESSION['running'] = time();
$_SESSION['inbound'] = [];
$_SESSION['outbound'] = [];

$target = '**********'; //conversation target number/JID
?>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
    var target = "<?php echo $target; ?>";
    $(document).ready(function()
    {
        $("#message").keypress(function(e) {
            if (e.which == 13)
            {
                sendMessage();
            }
        });
        Listen(true);
        getMessages();
    });

    function Listen(initial)
    {
        $.ajax({
            url: "socket.php",
            cache: false,
            dataType: "html",
            timeout: 70000,
            method: "POST",
            data: {
                initial: initial,
                target: target
            }
        }).done(function(data) { // on success, you can get the parameter as "data".
            console.log(data) ;
        }).always(function() { //if DONE is used, the service is stopped in case of failure of connection.
            setTimeout(function() {
                Listen(false)
            }, 10000);
        });

    }

    function getMessages()
    {
        $.ajax({
            url: "ajax.php",
            cache: false,
            dataType: "json",
            method: "POST",
            data: {
                method: "pollMessages",
            }
        }).done(function(data) {
            if (data)
            {
                if (data.profilepic != "")
                {
                    $("#profilepic").attr("src", data.profilepic);
                }
                for (var i in data.messages)
                {
                    addMessage(data.messages[i], "toMe");
                }
            }
        }).always(function() { //if DONE is used, the service is stopped in case of failure of connection.
            setTimeout(function() {
                getMessages()
            }, 5000);
        });
    }

    function addMessage(message, cssclass)
    {
        $("#conversation").append($("<div></div>").addClass("message").addClass(cssclass).html(message));
    }

    function sendMessage()
    {
        var message = $("#message").val();
        if (message != '')
        {
            addMessage(message, "fromMe");
            $("#message").val("");
            $.ajax({
                url: "ajax.php",
                cache: false,
                dataType: "html",
                method: "POST",
                data: {
                    method: "sendMessage",
                    target: target,
                    message: message
                }});
        }
    }
</script>

可在https://github.com/mgp25/Chat-API/blob/master/examples/ajaxDemo/index.php

获取

0 个答案:

没有答案