PHP implementation of the IMEI limit SMS authentication code send class _php instance

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

PHP Implementation of the IMEI limit SMS authentication code send class

<?php class api_sms{Const EXPIRE_SEC = 1800;     Expiration interval Const RESEND_SEC = 60;    Repeat time interval const ONE_DAY_FREQ = 5; Daily SMS to the same cell phone number const ONE_DAY_IMEI_COUNT = 3;
 
 
  The number of IMEI messages sent to the same mobile phone number public $error = Array (); /** * @param $mobile * @param $imei * @return bool/Public function Sendverifycode to the designated mobile number ($mobil E, $imei) {if (! $this->ismobile ($mobile)) {$this->error = array (' Code ' =>-1, ' msg ' => ') This is a wonderful mobile phone number, please
      Correct input and retry ');
    return false;
    } $redis = Api_common::redis ();
    $vcKey = ' vc_ '. $mobile;
 
    $limitKey = ' vc_limit_ '. $mobile;
    Verification code Postback Limit $data = Json_decode ($redis->get ($vcKey), true); if ($data && time () < $data [' Resend_expire ']) {$this->error = array (' Code ' =>-1, ' msg ' => ' SMS is already in
      1 minutes, please be patient ');
    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 ' => ' confiscated to SMS? Please wait or check if the message is blocked);
    return false;
    $imeiCnt = $redis->zcard ($limitKey); if ($imeiCnt >= self::one_day_imei_count &&! $sendCnt) {$this->error = array (' Code ' =>-1, ' msg ' =& Gt
      ' has exceeded the authentication code to send 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 Authentication code: '. $VC;
    $result = $this->send ($mobile, $content);
      if ($result) {//Reset the time limit $data [' resend_expire '] = period () + self::resend_sec;
      $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 (' 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 invokes the specific provider API return true; /** * To determine whether the legal mobile phone number * @param $mobile * @return bool/Private Function IsMobile ($mobile) {if preg_m
    Atch ('/^1\d{10}$/', $mobile)) return true;
  return false; /** * Verify SMS Verification code * @param $mobile * @param $VC * @return bool/Public function Checkverifycode ($mobi
    Le, $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);
 }
}

Pay other users to implement the SMS Authentication Code codes

? /*--------------------------------function: China SMS Web PHP HTTP interface to send SMS Modified date: 2009-04-08 Note: http://http.c123.com/tx/?uid= user account &am P;PWD=MD5 bit 32 password &mobile= number &content= content status: 100 Send Success 101 authentication failed 102 SMS less 103 operation failed 104 illegal character 105 content too much 106th code 
Too much 107 frequency too fast 108th number content empty 109 account Freeze 110 prohibit frequent single send 111 system tentatively send 112th code incorrect 120 system upgrade--------------------------------* *   $uid = ' 9999 ';   User account $pwd = ' 9999 ';  Password $mobile = ' 13912341234,13312341234,13512341234,02122334444 ';    Number $content = ' China SMS Web php http interface ';
Content//Instant Send $res = Sendsms ($uid, $pwd, $mobile, $content);
 
Echo $res;
Timed Send/* $time = ' 2010-05-27 12:11 ';
$res = Sendsms ($uid, $pwd, $mobile, $content, $time);
Echo $res;
  * * Function sendsms ($uid, $pwd, $mobile, $content, $time = ', $mid = ') {$http = ' http://http.c123.com/tx/'; $data = Array (' UID ' => $uid,//user account ' pwd ' =>strtolower (MD5 ($PWD)),//MD5 bit 32 password ' mobile ' =>$ Mobile,//number ' content ' => $content,//content ' time ' => $time,//scheduled to send ' mid ' => $mid/Sub extension);     $re = Postsms ($http, $data);
  Post method to submit if (trim ($re) = = ' {return "sent successfully!"; ' Else {return ' failed to send!
  Status: ". $re;
  } function Postsms ($url, $data = ' ") {$row = Parse_url ($url);
  $host = $row [' Host ']; $port = $row [' Port ']?
  $row [' Port ']:80;
  $file = $row [' path ']; while (the list ($k, $v) = each ($data)) {$post. = Rawurlencode ($k). = ". Rawurlencode ($v)." & ";
  Forwarding 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); }}?>

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

Related Article

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.