From 615629e0afd998fd6b5db0e7884c2cef52aeb0f9 Mon Sep 17 00:00:00 2001 From: Stife Date: Fri, 17 Jan 2025 15:32:01 +0100 Subject: [PATCH] Update WhatsApp API instructions and code Related to #403 --- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/venomous0x/WhatsAPI/issues/403?shareId=XXXX-XXXX-XXXX-XXXX). --- README.md | 44 +++++++++++++++++++++- exampleRegister.php | 43 +++++++++++++++++++++ whatsprot.class.php | 91 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 177 insertions(+), 1 deletion(-) create mode 100644 exampleRegister.php create mode 100644 whatsprot.class.php diff --git a/README.md b/README.md index 378bbca7..1cf02558 100644 --- a/README.md +++ b/README.md @@ -10,4 +10,46 @@ Among people who were involved: legal firms and counselors, sending all sorts of So besides having no time or interest for the core project anymore, and not benefiting at all, not from this or from the work derived from it, comes more aggressive letters citing lengthy Computer Fraud and Abuse Act (CFAA) clauses and requiring compensation among other ridiculous demands and/or threats. -*I'm wiping this repository away.* \ No newline at end of file +*I'm wiping this repository away.* + +## Instructions for Obtaining a WhatsApp Password Using the API + +### Phase 1: Request Code + +```php +$username = "phone number with international prefix but without + and 00"; +$identity = strtolower(urlencode(sha1($username, true))); +$w = new WhatsProt($username, $identity, "Your Name", true); +$w->codeRequest(); +``` + +### Phase 2: Retrieve Password + +```php +$username = "phone number with international prefix but without + and 00"; +$identity = strtolower(urlencode(sha1($username, true))); +$w = new WhatsProt($username, $identity, "Your Name", true); +$result = $w->codeRegister("your 6 digit SMS code"); +$password = $result->pw; +echo "Password is $password"; +``` + +### Phase 3: Send Message + +```php +$username = "phone number with international prefix but without + and 00"; +$identity = strtolower(urlencode(sha1($username, true))); +$w = new WhatsProt($username, $identity, "Your Name", true); +$password = 'YourPassword'; +$w->Connect(); +$w->LoginWithPassword($password); + +$dst = 'destination number with international prefix but without + and 00'; +$msg = 'Your message text'; +$w->sendMessage($dst, $msg); +$w->disconnect(); +``` + +### Note + +You need to enable the `php_curl` extension in your PHP configuration. diff --git a/exampleRegister.php b/exampleRegister.php new file mode 100644 index 00000000..c0faf3b7 --- /dev/null +++ b/exampleRegister.php @@ -0,0 +1,43 @@ +codeRequest(); + +// Register the code +$result = $w->codeRegister("your 6 digit SMS code"); + +// Retrieve the password +$password = $result->pw; +echo "Password is $password"; + +// Connect to WhatsApp +$w->Connect(); + +// Login with the password +$w->LoginWithPassword($password); + +// Define the destination number with international prefix but without + and 00 +$dst = 'destination number with international prefix but without + and 00'; + +// Define the message text +$msg = 'Your message text'; + +// Send the message +$w->sendMessage($dst, $msg); + +// Disconnect from WhatsApp +$w->disconnect(); +?> diff --git a/whatsprot.class.php b/whatsprot.class.php new file mode 100644 index 00000000..09ba99c0 --- /dev/null +++ b/whatsprot.class.php @@ -0,0 +1,91 @@ + $this->countryCode, + "in" => $this->phoneNumber, + "to" => $this->phoneNumber, + "lg" => $languageCode ? $languageCode : $this->languageCode, + "lc" => $countryCode ? $countryCode : $this->countryCode, + "method" => $method, + "mcc" => $this->mcc, + "mnc" => $this->mnc, + "token" => $this->generateToken(), + "id" => $this->identity + ); + + // Send the request + $response = $this->sendRequest("code", $params); + + // Handle the response + return $this->handleResponse($response); + } + + public function codeRegister($code) + { + // Generate the request parameters + $params = array( + "cc" => $this->countryCode, + "in" => $this->phoneNumber, + "to" => $this->phoneNumber, + "lg" => $this->languageCode, + "lc" => $this->countryCode, + "code" => $code, + "id" => $this->identity + ); + + // Send the request + $response = $this->sendRequest("register", $params); + + // Handle the response + return $this->handleResponse($response); + } + + private function sendRequest($endpoint, $params) + { + // Initialize cURL + $ch = curl_init(); + + // Set cURL options + curl_setopt($ch, CURLOPT_URL, $this->apiUrl . $endpoint); + curl_setopt($ch, CURLOPT_POST, true); + curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params)); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + + // Execute the request + $response = curl_exec($ch); + + // Close cURL + curl_close($ch); + + // Return the response + return $response; + } + + private function handleResponse($response) + { + // Decode the response + $result = json_decode($response); + + // Check for errors + if (isset($result->status) && $result->status == "fail") { + throw new Exception("Error: " . $result->reason); + } + + // Return the result + return $result; + } + + private function generateToken() + { + // Generate a token based on the phone number and identity + return md5($this->phoneNumber . $this->identity); + } +} +?>