Using Chat API send message from PHP to WhatsApp got socket_write(): unable to write to socket [10053]

1.5k views Asked by At

I want to send a message using from my PHP application to WhatsApp. So I used Chat API Interface to WhatsApp Messenger to send a message from PHP to WhatsApp.

STEP 1: Getting WhatsApp verify code Using PHP:

I used the below php script. I got my mobile WhatsApp code.

requestcode.php

<?php
require_once('src/Registration.php');
$debug = false;
$username = "9xxxxxxxxxxxx";
if(empty($username)){
    echo "Mobile Number can't be Empty";
    exit(0);
}
if (!preg_match('!^\d+$!', $username)){
    echo "Wrong number. Do NOT use '+' or '00' before your number\n";
    exit(0);
}
$w = new Registration($username, $debug);
try {
    $w->codeRequest("sms");
    echo "Verification Code Sent via SMS";
} catch(Exception $e) {
    echo $e->getMessage();
    exit(0);
}

STEP:2: Getting WhatsApp Password

Using the below script I got my WhatsApp password

Getpassword.php

<?php
error_reporting(0);
require_once('src/Registration.php');
$debug = false;
$username = "9+++++++++++";
$code = "7+++++";
if(empty($username)){
    echo "Mobile Number can't be Empty";
    exit(0);
}
if (!preg_match('!^\d+$!', $username)){
    echo "Wrong number. Do NOT use '+' or '00' before your number\n";
    exit(0);
}
$identityExists = file_exists("src/wadata/id.$username.dat");
$w = new Registration($username, $debug);
if (!$identityExists){
    echo "Identity Doesn't Exists";
} else { 
    try {
        $result = $w->codeRegister($code);
        echo "Your username is: ".$result->login."<BR>";
        echo "Your password is: ".$result->pw."<BR>";
    } catch(Exception $e) {
        echo $e->getMessage();
        exit(0);
    }
}

STEP 3: Send message using PHP to WhatsApp

Using the below PHP script. I tried to send SMS to another WhatsApp number.

SendSMStoWhatsapp.php

<?php
set_time_limit(0);
require_once("src/whatsprot.class.php");
$username = "9xxxxxxxx"; //Mobile Phone prefixed with country code
$password = "xxxxxxxxxxxxxxxxxxx=";

$w = new WhatsProt($username, 0, 'Test Blog', true); //Name your application by replacing “WhatsApp Messaging”
$w->connect();
$w->loginWithPassword($password);
$target = "9XXXXXXXXXXX"; //Target Phone,reciever phone
$message = "Hello User";
$w->SendPresenceSubscription($target); //Let us first send presence to user
$w->sendMessage($target,$message ); // Send Message
echo "Message Sent Successfully";
?>

OUTPUT:

But I got the below Issues.

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

tx  <auth user="9xxxxxxxxxxxxxxx" mechanism="WAUTH-2"></auth>

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

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

rx  <challenge>04fd4424021a18981379c634f2d69b94eab3d116</challenge>

tx  <response>3ef1c0a24d1cd70645b75577ddf841f53d7f937b7f011a3ca1da884f32b48543f02f9f09685ebba6185407bf887c50e104aa30d06bc75c542cb21a9545de7a7faeb8c228926d42941947f04cb6b3</response>

tx  <iq id="1" xmlns="w:p" type="get" to="s.whatsapp.net">
tx    <ping></ping>
tx  </iq>

tx  <iq id="2" xmlns="w:p" type="get" to="s.whatsapp.net">
tx    <ping></ping>
tx  </iq>


Warning: socket_write(): unable to write to socket [10053]: An established connection was aborted by the software in your host machine. in C:\xampp\htdocs\ChatAPI\src\whatsprot.class.php on line 2748
tx  <presence type="unavailable"></presence>


Warning: socket_write(): unable to write to socket [10053]: An established connection was aborted by the software in your host machine. in C:\xampp\htdocs\ChatAPI\src\whatsprot.class.php on line 2748
tx  <stream:features></stream:features>

tx  <auth user="9xxxxxxxxxxxxxxx" mechanism="WAUTH-2">d58842f739313938343135313231303504fd4424021a18981379c634f2d69b94eab3d11631343832383338313034</auth>

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

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

rx  <challenge>abf87d2abd096c559b677d16c85f0ab33e240139</challenge>

tx  <response>2de422a4193a1acf4d137da58c21f00e1004db354d2cae2fdcf5066d5be1a97dd2dbc7b1d769dd8e15cf66dba124c539da4f8de94b3769a9b8a3800d36cadd3ebf0c19f83cb46cf8ecc85a8d6dca</response>

tx  <presence type="unavailable"></presence>

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

tx  <auth user="9xxxxxxxxxxxxxxx" mechanism="WAUTH-2">e8b92808393139383431353132313035abf87d2abd096c559b677d16c85f0ab33e24013931343832383338313635</auth>

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

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

rx  <challenge>a3910a5d18ef72d80b056029ad900e0f78d01253</challenge>

tx  <response>92bdfbc4f132968a98defe1fec362cb82319ff665cbcfb29e7a31b43149b782ab371d3ff36c0f2690e29f43cf008373dcbbbda276c491d2c3e717a8c26efcec149abb147d5666876377eac2107fa</response>

tx  <presence type="unavailable"></presence>

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

tx  <auth user="9xxxxxxxxxxxxxxx" mechanism="WAUTH-2">d903be5e393139383431353132313035a3910a5d18ef72d80b056029ad900e0f78d0125331343832383338323236</auth>

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

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

rx  <challenge>54bc71bd3e61d48af9934b5f0f07986f792e28c4</challenge>

tx  <response>4be3f642718e8f55e6a5524fe909a2939696a4719786e04c171c9aaa974cfa050d2e740ada56a6b897be61c31ac55f06b80f0e7f044dce19310b24d477ad19b3295247e34bdf4b2bbef5d2c232ba</response>

tx  <presence type="unavailable"></presence>

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

tx  <auth user="9xxxxxxxxxxxxxxx" mechanism="WAUTH-2">1e898d2239313938343135313231303554bc71bd3e61d48af9934b5f0f07986f792e28c431343832383338323838</auth>

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

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

rx  <challenge>9518acc805334cfa5dd02ce0f833f1c4a28cdd4c</challenge>

tx  <response>bcf939dc38d61183f9c3ccdde8c800b54a0643b238ae9a5f17bd6fc6565f51698c2e50d3344a73d2660b6334710d5e423099f830ec8ca962bc7882231306c77b7d6d8539dcfb288ac63ca5626b30</response>

tx  <presence type="unavailable"></presence>

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

tx  <auth user="9xxxxxxxxxxxxxxx" mechanism="WAUTH-2">14a3045c3931393834313531323130359518acc805334cfa5dd02ce0f833f1c4a28cdd4c31343832383338333439</auth>

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

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

rx  <challenge>27209d5eebb7763fbd47f65f9df37b7d5fc14b5d</challenge>

tx  <response>160235a7bfa5e72dc31a9e16a00731fceff3e9f695e505dd387afda2538531fcc9a93b257ed7d031e307fa6d5e16b9b071131fa2e0b3eb24957b2e831776a924de7cbb79e61c379061eef497af5e</response>

tx  <presence type="unavailable"></presence>

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

tx  <auth user="9xxxxxxxxxxxxxxx" mechanism="WAUTH-2">a52f25c539313938343135313231303527209d5eebb7763fbd47f65f9df37b7d5fc14b5d31343832383338343130</auth>

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

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

rx  <challenge>c8caa3ebd98297eba7783466430e25d453d9b86f</challenge>

tx  <response>b0a3d8f1df8345b14643c935fe25a7df2498a23d772b5e374de778c20e629f263a8432baa79754814780205f837bae07a54cdebab3405e9d065324f88fe414ea37b4c12c336b0abf5b4de53d4e4c</response>

tx  <presence type="unavailable"></presence>

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

tx  <auth user="9xxxxxxxxxxxxxxx" mechanism="WAUTH-2">5296cb42393139383431353132313035c8caa3ebd98297eba7783466430e25d453d9b86f31343832383338343731</auth>

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

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

rx  <challenge>8990c2165fe79f2374031166b2938f00aece83af</challenge>

tx  <response>a136bb8e3803d8f5b5dff2b3bbf5263134015c575acc4af0a728186d30851fd032bbc8fc3c2b052734a86aef30cbbd13a730eff68f7d39374582cb459f52e0c3404b403e12175f09d6192f9b2a41</response>

tx  <presence type="unavailable"></presence>

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

tx  <auth user="9xxxxxxxxxxxxxxx" mechanism="WAUTH-2">f98740523931393834313531323130358990c2165fe79f2374031166b2938f00aece83af31343832383338353332</auth>

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

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

rx  <challenge>c9d4f73826a60a8c83756c8df4da706bf37a4098</challenge>

tx  <response>18552bb34e4b1c927080e31d22b017e7d7fa5b71b9ea5242904a5d622c473c06bf2e1ff48a0cae0d8a6a4d48138725fa0e229021a57c4dabaa0fde26003e3dc24cb13761a6b29cb70cbe88c16dca</response>

tx  <presence type="unavailable"></presence>

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

tx  <auth user="9xxxxxxxxxxxxxxx" mechanism="WAUTH-2">7fee1fc4393139383431353132313035c9d4f73826a60a8c83756c8df4da706bf37a409831343832383338353933</auth>

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

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

As per this socket [10053] error in whatsAPI PHP sending message. I turn off my system firewalls.

Again I got this issue only.

Is there any paid/open source API available to send a message from PHP to WhatsApp.

0

There are 0 answers