send whatsapp message using php

北城余情 提交于 2019-12-02 04:56:04

问题


hi. i want to send whatsapp message using php. i run this code

<?php
require_once 'Chat-API-master/src/whatsprot.class.php';
$username = "6285648145xxx";
$nickname = "ardi";
$password = "password"; // The one we got registering the number
$debug = true;

// Create a instance of WhastPort.
$w = new WhatsProt($username, $nickname, $debug);

$w->connect(); // Connect to WhatsApp network
$w->loginWithPassword($password); // logging in with the password we got!

$target = '62811304xxxx'; // The number of the person you are sending the message
$message = 'Hi! :) this is a test message';

$w->sendMessage($target , $message);
?>

But i have result this code at my browser

tx  <stream:features></stream:features>

tx  <auth user="6285648145xxx" mechanism="WAUTH-2"></auth>

rx  <from s.whatsapp.net=""></from>

rx  <stream:features></stream:features>

rx  <challenge>376a507c7e915642d85255fe96cb1d101fa23819</challenge>

tx  <response>200e09fa50b7c6a3fa3416878f1e165e8d7670f054ddeaa1c77278a5f8e5b881f4f9f75dce809f42cbdcf17931db8c15641399488b90e9cb74e87de94560802f98bb028af9b5967403fb278c28e06c</response>


Fatal error: Maximum execution time of 30 seconds exceeded in D:\XAMPP\htdocs\waonline\Chat-API-master\src\whatsprot.class.php on line 2609

what's wrong?? please give me sollution. thanks


回答1:


Add

set_time_limit(120);

Your script takes too long to execute




回答2:


Use the official "Click to Chat" API

The first possible way was thorugh a URL procedure sending the user to:

https://api.whatsapp.com/send?phone=XXYYYYYYYY

(where XX is the country code and YYYYYYYY is the number)

Nowadays the API comes in a shorter format and allows including the text message.

https://wa.me/whatsappphonenumber/?text=urlencodedtext

(where whatsappphonenumber is a full phone number in international format and URL-encodedtext is the URL-encoded pre-filled message)

It's also possible to just assign a message to be sent but with no user specified, letting the user to later choose whom to send it to, being able to send it to many people at once, with this method:

https://wa.me/?text=urlencodedtext

You can see all the official current information in here https://faq.whatsapp.com/en/android/26000030/



来源:https://stackoverflow.com/questions/39721694/send-whatsapp-message-using-php

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