示例#1
0
 /**
  * Request a registration code from WhatsApp.
  *
  * @param string $method
  *   Accepts only 'sms' or 'voice' as a value.
  * @param string $countryCode
  *   ISO Country Code, 2 Digit.
  * @param string $langCode
  *   ISO 639-1 Language Code: two-letter codes.
  *
  * @return object
  *   An object with server response.
  *   - status: Status of the request (sent/fail).
  *   - length: Registration code lenght.
  *   - method: Used method.
  *   - reason: Reason of the status (e.g. too_recent/missing_param/bad_param).
  *   - param: The missing_param/bad_param.
  *   - retry_after: Waiting time before requesting a new code.
  *
  * @throws Exception
  */
 public function codeRequest($method = 'sms', $countryCode = null, $langCode = null)
 {
     if (!($phone = $this->dissectPhone())) {
         throw new Exception('The provided phone number is not valid.');
     }
     if ($countryCode == null && $phone['ISO3166'] != '') {
         $countryCode = $phone['ISO3166'];
     }
     if ($countryCode == null) {
         $countryCode = 'US';
     }
     if ($langCode == null && $phone['ISO639'] != '') {
         $langCode = $phone['ISO639'];
     }
     if ($langCode == null) {
         $langCode = 'en';
     }
     // Build the token.
     $token = generateRequestToken($phone['country'], $phone['phone']);
     // Build the url.
     $host = 'https://' . static::WHATSAPP_REQUEST_HOST;
     $query = array('method' => $method, 'in' => $phone['phone'], 'cc' => $phone['cc'], 'id' => $this->identity, 'lg' => $langCode, 'lc' => $countryCode, 'token' => urlencode($token), 'sim_mcc' => '000', 'sim_mnc' => '000');
     if ($this->debug) {
         print_r($query);
     }
     $response = $this->getResponse($host, $query);
     if ($this->debug) {
         print_r($response);
     }
     if ($response->status == 'ok') {
         $this->eventManager()->fireCodeRegister($this->phoneNumber, $response->login, $response->pw, $response->type, $response->expiration, $response->kind, $response->price, $response->cost, $response->currency, $response->price_expiration);
     } else {
         if ($response->status != 'sent') {
             if (isset($response->reason) && $response->reason == "too_recent") {
                 $this->eventManager()->fireCodeRequestFailedTooRecent($this->phoneNumber, $method, $response->reason, $response->retry_after);
                 $minutes = round($response->retry_after / 60);
                 throw new Exception("Code already sent. Retry after {$minutes} minutes.");
             } else {
                 $this->eventManager()->fireCodeRequestFailed($this->phoneNumber, $method, $response->reason, $response->param);
                 throw new Exception('There was a problem trying to request the code.');
             }
         } else {
             $this->eventManager()->fireCodeRequest($this->phoneNumber, $method, $response->length);
         }
     }
     return $response;
 }
示例#2
0
 /**
  * Request a registration code from WhatsApp.
  *
  * @param string $method Accepts only 'sms' or 'voice' as a value.
  * @param string $carrier
  *
  * @return object
  *   An object with server response.
  *   - status: Status of the request (sent/fail).
  *   - length: Registration code lenght.
  *   - method: Used method.
  *   - reason: Reason of the status (e.g. too_recent/missing_param/bad_param).
  *   - param: The missing_param/bad_param.
  *   - retry_after: Waiting time before requesting a new code.
  *
  * @throws Exception
  */
 public function codeRequest($method = 'sms', $carrier = "T-Mobile5")
 {
     if (!($phone = $this->dissectPhone())) {
         throw new Exception('The provided phone number is not valid.');
     }
     $countryCode = $phone['ISO3166'] != '' ? $phone['ISO3166'] : 'US';
     $langCode = $phone['ISO639'] != '' ? $phone['ISO639'] : 'en';
     if ($carrier != null) {
         $mnc = $this->detectMnc(strtolower($countryCode), $carrier);
     } else {
         $mnc = $phone['mnc'];
     }
     // Build the token.
     $token = generateRequestToken($phone['country'], $phone['phone']);
     // Build the url.
     $host = 'https://' . Constants::WHATSAPP_REQUEST_HOST;
     $query = array('in' => $phone['phone'], 'cc' => $phone['cc'], 'id' => $this->identity, 'lg' => $langCode, 'lc' => $countryCode, 'sim_mcc' => $phone['mcc'], 'sim_mnc' => $mnc, 'method' => $method, 'token' => $token);
     $this->debugPrint($query);
     $response = $this->getResponse($host, $query);
     $this->debugPrint($response);
     if ($response->status == 'ok') {
         $this->eventManager()->fire("onCodeRegister", array($this->phoneNumber, $response->login, $response->pw, $response->type, $response->expiration, $response->kind, $response->price, $response->cost, $response->currency, $response->price_expiration));
     } else {
         if ($response->status != 'sent') {
             if (isset($response->reason) && $response->reason == "too_recent") {
                 $this->eventManager()->fire("onCodeRequestFailedTooRecent", array($this->phoneNumber, $method, $response->reason, $response->retry_after));
                 $minutes = round($response->retry_after / 60);
                 throw new Exception("Code already sent. Retry after {$minutes} minutes.");
             } else {
                 if (isset($response->reason) && $response->reason == "too_many_guesses") {
                     $this->eventManager()->fire("onCodeRequestFailedTooManyGuesses", array($this->phoneNumber, $method, $response->reason, $response->retry_after));
                     $minutes = round($response->retry_after / 60);
                     throw new Exception("Too many guesses. Retry after {$minutes} minutes.");
                 } else {
                     $this->eventManager()->fire("onCodeRequestFailed", array($this->phoneNumber, $method, $response->reason, isset($response->param) ? $response->param : NULL));
                     throw new Exception('There was a problem trying to request the code.');
                 }
             }
         } else {
             $this->eventManager()->fire("onCodeRequest", array($this->phoneNumber, $method, $response->length));
         }
     }
     return $response;
 }
 /**
  * Request a registration code from WhatsApp without firing events.
  *
  * @param string $method Accepts only 'sms' or 'voice' as a value.
  * @param string $carrier
  *
  * @return object
  *   An object with server response.
  *   - status: Status of the request (sent/fail).
  *   - length: Registration code lenght.
  *   - method: Used method.
  *   - reason: Reason of the status (e.g. too_recent/missing_param/bad_param).
  *   - param: The missing_param/bad_param.
  *   - retry_after: Waiting time before requesting a new code.
  *
  * @throws Exception
  */
 public function codeRequestSync($method = 'sms', $carrier = "T-Mobile5", $platform = 'Android')
 {
     if (!($phone = $this->dissectPhone())) {
         throw new Exception('The provided phone number is not valid.');
     }
     $countryCode = $phone['ISO3166'] != '' ? $phone['ISO3166'] : 'US';
     $langCode = $phone['ISO639'] != '' ? $phone['ISO639'] : 'en';
     if ($carrier != null) {
         $mnc = $this->detectMnc(strtolower($countryCode), $carrier);
     } else {
         $mnc = $phone['mnc'];
     }
     // Build the token.
     $token = generateRequestToken($phone['country'], $phone['phone'], $platform);
     // Build the url.
     $host = 'https://' . Constants::WHATSAPP_REQUEST_HOST;
     $query = array('cc' => $phone['cc'], 'in' => $phone['phone'], 'lg' => $langCode, 'lc' => $countryCode, 'id' => $this->identity, 'token' => $token, 'mistyped' => '6', 'network_radio_type' => '1', 'simnum' => '1', 's' => '', 'copiedrc' => '1', 'hasinrc' => '1', 'rcmatch' => '1', 'pid' => mt_rand(100, 9999), 'rchash' => hash('sha256', openssl_random_pseudo_bytes(20)), 'anhash' => md5(openssl_random_pseudo_bytes(20)), 'extexist' => '1', 'extstate' => '1', 'mcc' => $phone['mcc'], 'mnc' => $mnc, 'sim_mcc' => $phone['mcc'], 'sim_mnc' => $mnc, 'method' => $method);
     $this->debugPrint($query);
     return $this->getResponse($host, $query);
 }
 /**
  * Request a registration code from WhatsApp.
  *
  * @param string $method Accepts only 'sms' or 'voice' as a value.
  * @param string $carrier
  *
  * @throws Exception
  *
  * @return object
  *   An object with server response.
  *   - status: Status of the request (sent/fail).
  *   - length: Registration code lenght.
  *   - method: Used method.
  *   - reason: Reason of the status (e.g. too_recent/missing_param/bad_param).
  *   - param: The missing_param/bad_param.
  *   - retry_after: Waiting time before requesting a new code.
  */
 public function codeRequest($method = 'sms', $carrier = 'T-Mobile5', $platform = 'Android')
 {
     if (!($phone = $this->dissectPhone())) {
         throw new Exception('The provided phone number is not valid.');
     }
     $countryCode = $phone['ISO3166'] != '' ? $phone['ISO3166'] : 'US';
     $langCode = $phone['ISO639'] != '' ? $phone['ISO639'] : 'en';
     if ($carrier != null) {
         $mnc = $this->detectMnc(strtolower($countryCode), $carrier);
     } else {
         $mnc = $phone['mnc'];
     }
     // Build the token.
     $token = generateRequestToken($phone['country'], $phone['phone'], $platform);
     // Build the url.
     $host = 'https://' . Constants::WHATSAPP_REQUEST_HOST;
     $query = ['cc' => $phone['cc'], 'in' => $phone['phone'], 'lg' => $langCode, 'lc' => $countryCode, 'id' => $this->identity, 'token' => $token, 'mistyped' => '6', 'network_radio_type' => '1', 'simnum' => '1', 's' => '', 'copiedrc' => '1', 'hasinrc' => '1', 'rcmatch' => '1', 'pid' => mt_rand(100, 9999), 'rchash' => hash('sha256', openssl_random_pseudo_bytes(20)), 'anhash' => md5(openssl_random_pseudo_bytes(20)), 'extexist' => '1', 'extstate' => '1', 'mcc' => $phone['mcc'], 'mnc' => $mnc, 'sim_mcc' => $phone['mcc'], 'sim_mnc' => $mnc, 'method' => $method];
     $this->debugPrint($query);
     $response = $this->getResponse($host, $query);
     $this->debugPrint($response);
     if ($response->status == 'ok') {
         $this->eventManager()->fire('onCodeRegister', [$this->phoneNumber, $response->login, $response->pw, $response->type, $response->expiration, $response->kind, $response->price, $response->cost, $response->currency, $response->price_expiration]);
     } elseif ($response->status != 'sent') {
         if (isset($response->reason) && $response->reason == 'too_recent') {
             $this->eventManager()->fire('onCodeRequestFailedTooRecent', [$this->phoneNumber, $method, $response->reason, $response->retry_after]);
             $minutes = round($response->retry_after / 60);
             throw new Exception("Code already sent. Retry after {$minutes} minutes.");
         } elseif (isset($response->reason) && $response->reason == 'too_many_guesses') {
             $this->eventManager()->fire('onCodeRequestFailedTooManyGuesses', [$this->phoneNumber, $method, $response->reason, $response->retry_after]);
             $minutes = round($response->retry_after / 60);
             throw new Exception("Too many guesses. Retry after {$minutes} minutes.");
         } else {
             $this->eventManager()->fire('onCodeRequestFailed', [$this->phoneNumber, $method, $response->reason, isset($response->param) ? $response->param : null]);
             throw new Exception('There was a problem trying to request the code.');
         }
     } else {
         $this->eventManager()->fire('onCodeRequest', [$this->phoneNumber, $method, $response->length]);
     }
     return $response;
 }
示例#5
0
文件: index.php 项目: amagdas/rawkets
                    $_SESSION["oauth_access_token_secret"] = $access_token_info["oauth_token_secret"];
                    $expire = time() + 60 * 60 * 24 * 30;
                    // One month
                    setcookie("oauth_access_token", $access_token_info["oauth_token"], $expire);
                    setcookie("oauth_access_token_secret", $access_token_info["oauth_token_secret"], $expire);
                    $_SESSION["oauth_request_token"] = "";
                    $_SESSION["oauth_request_token_secret"] = "";
                    checkAuth($oauth);
                } catch (OAuthException $e) {
                    // Generate a new request token
                    generateRequestToken($oauth);
                }
            }
            if (!isset($_SESSION["oauth_access_token"]) || $_SESSION["oauth_access_token"] == "") {
                // Generate a new request token
                generateRequestToken($oauth);
            }
            // Cookies detected
        } else {
            checkAuth($oauth, true);
        }
    } else {
        checkAuth($oauth);
    }
} catch (OAuthException $e) {
    //print_r($e);
}
?>
<!DOCTYPE html>

<html lang="en">
示例#6
0
 /**
  * Request a registration code from WhatsApp.
  *
  * @param string $method Accepts only 'sms' or 'voice' as a value.
  * @param string $carrier
  *
  * @throws Exception
  *
  * @return object
  *   An object with server response.
  *   - status: Status of the request (sent/fail).
  *   - length: Registration code lenght.
  *   - method: Used method.
  *   - reason: Reason of the status (e.g. too_recent/missing_param/bad_param).
  *   - param: The missing_param/bad_param.
  *   - retry_after: Waiting time before requesting a new code.
  */
 public function codeRequest($method = 'sms', $carrier = 'T-Mobile5', $platform = 'Android')
 {
     if (!($phone = $this->dissectPhone())) {
         throw new Exception(Language::getMessageByKey("MESSAGE_REGISTRATION_ERROR_INVALID_NUMBER", self::FILE_PACK_LANGUAGE, Constants::LANGUAGE));
     }
     $countryCode = $phone['ISO3166'] != '' ? $phone['ISO3166'] : 'US';
     $langCode = $phone['ISO639'] != '' ? $phone['ISO639'] : 'en';
     if ($carrier != null) {
         $mnc = $this->detectMnc(strtolower($countryCode), $carrier);
     } else {
         $mnc = $phone['mnc'];
     }
     // Build the token.
     $token = generateRequestToken($phone['country'], $phone['phone'], $platform);
     // Build the url.
     $host = 'https://' . Constants::WHATSAPP_REQUEST_HOST;
     $query = ['cc' => $phone['cc'], 'in' => $phone['phone'], 'lg' => $langCode, 'lc' => $countryCode, 'id' => $this->identity, 'token' => $token, 'mistyped' => '6', 'network_radio_type' => '1', 'simnum' => '1', 's' => '', 'copiedrc' => '1', 'hasinrc' => '1', 'rcmatch' => '1', 'pid' => mt_rand(100, 9999), 'rchash' => hash('sha256', openssl_random_pseudo_bytes(20)), 'anhash' => md5(openssl_random_pseudo_bytes(20)), 'extexist' => '1', 'extstate' => '1', 'mcc' => $phone['mcc'], 'mnc' => $mnc, 'sim_mcc' => $phone['mcc'], 'sim_mnc' => $mnc, 'method' => $method];
     $this->debugPrint($query);
     $response = $this->getResponse($host, $query);
     $this->debugPrint($response);
     if ($response->status == 'ok') {
         $this->eventManager()->fire('onCodeRegister', [$this->phoneNumber, $response->login, $response->pw, $response->type, $response->expiration, $response->kind, $response->price, $response->cost, $response->currency, $response->price_expiration]);
     } elseif ($response->status != 'sent') {
         if (isset($response->reason) && $response->reason == 'too_recent') {
             $this->eventManager()->fire('onCodeRequestFailedTooRecent', [$this->phoneNumber, $method, $response->reason, $response->retry_after]);
             $minutes = round($response->retry_after / 60);
             throw new Exception(Language::getMessageByKey("MESSAGE_REGISTRATION_ERROR_CODE_ALREADY_SENT", self::FILE_PACK_LANGUAGE, Constants::LANGUAGE, array("MINUTES" => $minutes)));
         } elseif (isset($response->reason) && $response->reason == 'too_many_guesses') {
             $this->eventManager()->fire('onCodeRequestFailedTooManyGuesses', [$this->phoneNumber, $method, $response->reason, $response->retry_after]);
             $minutes = round($response->retry_after / 60);
             throw new Exception(Language::getMessageByKey("MESSAGE_REGISTRATION_ERROR_MANY_GUESSES", self::FILE_PACK_LANGUAGE, Constants::LANGUAGE, array("MINUTES" => $minutes)));
         } else {
             $this->eventManager()->fire('onCodeRequestFailed', [$this->phoneNumber, $method, $response->reason, isset($response->param) ? $response->param : null]);
             throw new Exception(Language::getMessageByKey("MESSAGE_REGISTRATION_ERROR_FAILED_REQUEST_CODE", self::FILE_PACK_LANGUAGE, Constants::LANGUAGE));
         }
     } else {
         $this->eventManager()->fire('onCodeRequest', [$this->phoneNumber, $method, $response->length]);
     }
     return $response;
 }