PHP implementation of IMEI limit SMS verification code send class

Source: Internet
Author: User
PHP implementation of IMEI limit SMS verification code send class

 IsMobile ($mobile)) {$this->error = array (' code ' = = 1, ' msg ' = ' = ' "This is a wonderful mobile phone number, please enter it correctly and try again");    return false;    } $redis = Api_common::redis ();    $vcKey = ' vc_ '. $mobile;     $limitKey = ' vc_limit_ '. $mobile;    Verification code re-send Limit $data = Json_decode ($redis->get ($vcKey), true); if ($data && time () < $data [' Resend_expire ']) {$this->error = array (' code ' = = 1, ' msg ' = =)      "SMS has been sent within 1 minutes, please wait patiently");    return false;    }//Mobile number and IMEI limit $sendCnt = $redis->zscore ($limitKey, $imei); if ($sendCnt && $sendCnt >= self::one_day_freq) {$this->error = array (' code ' = = 1, ' msg ' = =      "Do you want to wait or check if the text message is blocked?"    return false;    } $imeiCnt = $redis->zcard ($limitKey);  if ($imeiCnt >= self::one_day_imei_count &&! $sendCnt) {$this->error = array (' code ' = = 1, ' msg ')      + "has exceeded the verification code sending device limit");    return false; }//Get the CAPTCHA if (! $data) {$VC = Strval (rand (100000, 999999));      $data = Array (' VC ' = + $VC, ' Resend_expire ' + 0);      $redis->set ($vcKey, Json_encode ($data)); $redis->expire ($vcKey, self::expire_sec);     Set verification code Expiration Time} $VC = $data [' VC '];    $content = ' Security code: '. $VC;    $result = $this->send ($mobile, $content);      if ($result) {//Reset the re-send time limit $data [' resend_expire '] = Duration () + self::resend_sec;      $ttl = $redis->ttl ($vcKey);      $redis->set ($vcKey, Json_encode ($data));       $redis->expire ($vcKey, $ttl);      Set the phone number with the IMEI limit $redis->zincrby ($limitKey, 1, $imei);    $redis->expireat ($limitKey, Strtotime (date (' y-m-d ', Strtotime (' +1 Day ')));  } return $result; /** * Send SMS to designated mobile phone number * @param $mobile * @param $content * @return BOOL */Public function Send ($mobile, $conten  T) {//TODO invoke specific service provider API return true; }/** * Determines whether it is a legitimate mobile number * @param $mobile * @return BOOL */Private Function IsMobile ($mobile) {if (Preg_match ("/     ^1\d{10}$/", $mobile)) return true;  return false;  /** * Verify SMS Verification code * @param $mobile * @param $VC * @return BOOL */Public Function Checkverifycode ($mobile, $VC)    {$vcKey = ' vc_ '. $mobile;    $vcData = Json_decode (Api_common::redis ()->get ($vcKey), true);    if ($vcData && $vcData [' vc '] = = = $VC) {return true;  } return false;    /** * Clear Verification code * @param $mobile */Public Function Cleanverifycode ($mobile) {$redis = Api_common::redis ();    $vcKey = ' vc_ '. $mobile;    $limitKey = ' vc_limit_ '. $mobile;    $redis->del ($vcKey);  $redis->del ($limitKey); }}

Other users to pay for the implementation of the SMS Verification Code code

 $uid,//user account ' pwd ' =>strtolower (MD5 ($PWD)),//MD5 bit 32 password ' mobile ' and ' + $mobile,//number ' content  ' = + $content,//content ' ' time ' and ' = ' $time,//timed to send ' mid ' ' + $mid//Sub-extension number];     $re = Postsms ($http, $data);  Post Way to submit if (trim ($re) = = "+") {return "sent successfully!"; } else {return ' send failed!  Status: ". $re;  }} function Postsms ($url, $data = "") {$row = Parse_url ($url);  $host = $row [' Host ']; $port = $row [' Port ']?  $row [' Port ']:80;  $file = $row [' path ']; while (list ($k, $v) = each ($data)) {$post. = Rawurlencode ($k). " = ". Rawurlencode ($v)." & ";  Go to URL Standard code} $post = substr ($post, 0,-1);  $len = strlen ($post);  $fp = @fsockopen ($host, $port, $errno, $ERRSTR, 10);  if (! $fp) {return "$errstr ($errno) \ n";    } else {$receive = "";    $out = "POST $file http/1.1\r\n";    $out. = "Host: $host \ r \ n";    $out. = "content-type:application/x-www-form-urlencoded\r\n";    $out. = "connection:close\r\n"; $out. = "ConteNt-length: $len \r\n\r\n ";       $out. = $post;    Fwrite ($fp, $out);    while (!feof ($fp)) {$receive. = fgets ($fp, 128);    } fclose ($FP);    $receive = Explode ("\r\n\r\n", $receive);    unset ($receive [0]);  Return implode ("", $receive); }}?>
Reprinted from: http://www.aspnetjia.com
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.