4

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

PhilipB
  • 329
  • 2
  • 16
ardi
  • 41
  • 1
  • 1
  • 2
  • 3
    hide password, if its correct – devpro Sep 27 '16 at 10:00
  • Well you have exceeded the default maximum runtime of a PHP script allowed by your config. That can be fixed, but I cannot see from the code you actually show why 30 seconds is not enough time to run that script. So is this ALL the code in your script? – RiggsFolly Sep 27 '16 at 10:03
  • Why the [tag:android] tag? – RiggsFolly Sep 27 '16 at 10:05
  • ok. i will check my code again. thanks. maybe you have other code for send the whatsapp message using php ? – ardi Sep 27 '16 at 11:47

3 Answers3

0

Add

set_time_limit(120);

Your script takes too long to execute

Marcin
  • 1,488
  • 1
  • 13
  • 27
0

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/

DavidTaubmann
  • 3,223
  • 2
  • 34
  • 43
0

The official documentation says to use their wa.me URL, so let's just check it out: http://wa.me/?text=mytest. What do you see? Do you see an error page? This is what I see:

We couldn't find the page you were looking for

Looks like you're looking for a page that doesn't exist. Or a page we might have just deleted. Either way, go back or be sure to check the url, your spelling and try again.

So, in short, DO NOT use the wa.me URL. Use the api.whatsapp.com URL, like one of these:

https://api.whatsapp.com/send?text=YourShareTextHere

https://api.whatsapp.com/send?text=YourShareTextHere&phone=123

These both work perfectly for me!

If you are interested in watching a project that keeps track of these URLs, then check us out!: https://github.com/bradvin/social-share-urls#whatsapp

Social Share URLs

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
HoldOffHunger
  • 18,769
  • 10
  • 104
  • 133