当前位置: 首页>>代码示例>>PHP>>正文


PHP generateRequestToken函数代码示例

本文整理汇总了PHP中generateRequestToken函数的典型用法代码示例。如果您正苦于以下问题:PHP generateRequestToken函数的具体用法?PHP generateRequestToken怎么用?PHP generateRequestToken使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了generateRequestToken函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: codeRequest

 /**
  * 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;
 }
开发者ID:micschk,项目名称:WhatsAPI,代码行数:68,代码来源:whatsprot.class.php

示例2: codeRequest

 /**
  * 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;
 }
开发者ID:rezanadimi72,项目名称:Chat-API,代码行数:61,代码来源:whatsprot.class.php

示例3: codeRequestSync

 /**
  * 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);
 }
开发者ID:PretzelMakersInc,项目名称:Chat-API,代码行数:37,代码来源:Registration.php

示例4: codeRequest

 /**
  * 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;
 }
开发者ID:sadiqhirani,项目名称:WhatsApp-PHP-API,代码行数:57,代码来源:Registration.php

示例5: time

                    $_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">
开发者ID:amagdas,项目名称:rawkets,代码行数:31,代码来源:index.php

示例6: codeRequest

 /**
  * 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;
 }
开发者ID:margaretkho,项目名称:Chat-API,代码行数:57,代码来源:Registration.php


注:本文中的generateRequestToken函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。