PHP implementation of the IMEI limit SMS authentication code send class

Source: Internet
Author: User
Tags bool php class redis time interval

PHP implementation of the IMEI limit SMS authentication code send class

?

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26-27--28 29---30 31--32 33 34 35 36 37 38-39 40 41 42 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 5, 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 11 9 <?php class api_sms{Const EXPIRE_SEC = 1800;//expiration interval Const RESEND_SEC = 60;//Repeat time interval const ONE_DAY_FREQ = 5;//Daily Number of messages to the same cell phone number const ONE_DAY_IMEI_COUNT = 3; Number of IMEI messages sent to the same mobile phone number   Public $error = Array ();    /** * Send a verification code to the designated mobile number * @param $mobile * @param $imei * @return bool/Public Function Sendverifycode ($mobile, $imei) {if (! $this->ismobile ($mobile)) {$this->error = array (' Code ' =>-1, ' msg ' => ' This cell phone number is wonderful, please input and try again "); re Turn false; }   $redis = Api_common::redis (); $vcKey = ' vc_ '. $mobile; $limitKey = ' vc_limit_ '. $mobile;  //Authenticode $data = Json_decode ($redis->get ($vcKey), true); if ($data && time () < $data [' Resend_expire ']) {$this->error = array (' Code ' =>-1, ' msg ' => ' SMS has been sent in 1 minutes , please wait patiently '); return false;  /Mobile phone number and IMEI limit $sendCnt = $redis->zscore ($limitKey, $imei); if ($sendCnt && $sendCnt >= self::one_day_freq) {$this->error = array (' Code ' =>-1, ' msg ' => ') seized SMS? And so on or check whether the message is blocked '); RetUrn false; $imeiCnt = $redis->zcard ($limitKey); if ($imeiCnt >= self::one_day_imei_count &&! $sendCnt) {$this->error = array (' Code ' =>-1, ' msg ' => ' has been Exceeding the authentication code sending device limit '); return false;  //Get Authentication code 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 Authenticode Expiration Time} $VC = $data [' VC '];   $content = ' Security Verification Code: '. $VC; $result = $this->send ($mobile, $content); if ($result) {//Reset the self::resend_sec $data [' resend_expire '] = time () + $ttl = $redis->ttl ($vcKey); $redis->set ( $vcKey, Json_encode ($data)); $redis->expire ($vcKey, $ttl);  //Set mobile number and 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, $content) {// TODO TuneReturn true with the specific provider API;  /** * To determine whether the legal mobile phone number * @param $mobile * @return bool/Private Function IsMobile ($mobile) {if Preg_match ('/^1d{10}$ /', $mobile)) return true; return false; }  /** * Verify SMS Verification code * @param $mobile * @param $VC * @return bool/Public Function Checkverifycode ($mobile, $VC) {$VC Key = ' 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); } }

To pay other users to implement the text message verification code

?

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26-27--28 29---30 31--32 33 34 35 36 37 38-39 40 41 42 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 5 86 87 88 89 90 91 92

The above is the entire contents of this article, I hope you can enjoy.

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.