


The IMEI restricted SMS verification code sending class implemented by php
?
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 43 44 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 84 85 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 119
|
class Api_Sms{ const EXPIRE_SEC = 1800; // Expiration interval const RESEND_SEC = 60; // Resend interval const ONE_DAY_FREQ = 5; // Number of times a day to send text messages to the same mobile phone number const ONE_DAY_IMEI_COUNT = 3; // Number of IMEIs sent to the same mobile phone number every day
public $error = array();
/** * Send verification code to the specified mobile phone number * @param $mobile * @param $imei * @return bool */ public function sendVerifyCode($mobile, $imei) { if(!$this->isMobile($mobile)) { $this->error = array('code' => -1, 'msg' => 'This mobile phone number is very strange, please enter it correctly and try again'); return false; }
$redis = Api_Common::redis(); $vcKey = 'VC_'.$mobile; $limitKey = 'VC_LIMIT_'.$mobile;
//Verification code resend limit $data = json_decode($redis->get($vcKey), true); if($data && time() $this->error = array('code' => -1, 'msg' => 'The message has been sent within 1 minute, please wait patiently'); return false; }
//Mobile phone number and IMEI restrictions $sendCnt = $redis->zScore($limitKey, $imei); if($sendCnt && $sendCnt >= self::ONE_DAY_FREQ) { $this->error = array('code' => -1, 'msg' => 'Didn't receive the text message? Please wait or check whether the text message has been blocked'); return false; } $imeiCnt = $redis->zCard($limitKey); if($imeiCnt >= self::ONE_DAY_IMEI_COUNT && !$sendCnt) { $this->error = array('code' => -1, 'msg' => 'Verification code sending device limit exceeded'); return false; }
//Get verification 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 the verification code expiration time } $vc = $data['vc'];
$content = 'Security verification code:'.$vc; $result = $this->send($mobile, $content); if($result) { //Reset resend time limit $data['resend_expire'] = time() self::RESEND_SEC; $ttl = $redis->ttl($vcKey); $redis->set($vcKey, json_encode($data)); $redis->expire($vcKey, $ttl);
//Set mobile phone number and IMEI restrictions $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 call specific service provider API return true; }
/** * Determine whether it is a 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) { $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 additional SMS verification code implemented by other netizens
?
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 43 44 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 84 85 86 87 88 89 90 91 92 |
/*-------------------------------- Function: China SMS Network PHP HTTP interface to send SMS Modification date: 2009-04-08 Instructions: http://http.c123.com/tx/?uid=user account&pwd=MD5-digit 32-digit password&mobile=number&content=content Status: 100 sent successfully 101 Verification failed 102 Insufficient SMS 103 Operation failed 104 illegal characters 105 Too much content 106 Too Many Numbers 107 frequency is too fast 108 number content is empty 109 Account Freeze 110 Frequent sending of single messages is prohibited 111 system tentatively sends 112 number is incorrect 120 System Upgrade --------------------------------*/ $uid = '9999'; //User account $pwd = '9999'; //Password $mobile = '13912341234,13312341234,13512341234,02122334444'; //Number $content = 'China SMS Network PHP HTTP interface'; //Content //Send immediately $res = sendSMS($uid,$pwd,$mobile,$content); echo $res;
//Send regularly /* $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 digit 32 password 'mobile'=>$mobile, //Number 'content'=>$content, //Content 'time'=>$time, //Send regularly 'mid'=>$mid //Sub extension number ); $re= postSMS($http,$data); //Submit via POST if( trim($re) == '100' ) { return "Sent successfully!"; } else { return "Sending 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)."&"; //转URL标准码 } $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.1rn"; $out .= "Host: $hostrn"; $out .= "Content-type: application/x-www-form-urlencodedrn"; $out .= "Connection: Closern"; $out .= "Content-Length: $lenrnrn"; $out .= $post; fwrite($fp, $out); while (!feof($fp)) { $receive .= fgets($fp, 128); } fclose($fp); $receive = explode("rnrn",$receive); unset($receive[0]); return implode("",$receive); } } ?> |
以上所述就是本文的全部内容了,希望大家能够喜欢。

php把负数转为正整数的方法:1、使用abs()函数将负数转为正数,使用intval()函数对正数取整,转为正整数,语法“intval(abs($number))”;2、利用“~”位运算符将负数取反加一,语法“~$number + 1”。

实现方法:1、使用“sleep(延迟秒数)”语句,可延迟执行函数若干秒;2、使用“time_nanosleep(延迟秒数,延迟纳秒数)”语句,可延迟执行函数若干秒和纳秒;3、使用“time_sleep_until(time()+7)”语句。

php字符串有下标。在PHP中,下标不仅可以应用于数组和对象,还可应用于字符串,利用字符串的下标和中括号“[]”可以访问指定索引位置的字符,并对该字符进行读写,语法“字符串名[下标值]”;字符串的下标值(索引值)只能是整数类型,起始值为0。

php除以100保留两位小数的方法:1、利用“/”运算符进行除法运算,语法“数值 / 100”;2、使用“number_format(除法结果, 2)”或“sprintf("%.2f",除法结果)”语句进行四舍五入的处理值,并保留两位小数。

判断方法:1、使用“strtotime("年-月-日")”语句将给定的年月日转换为时间戳格式;2、用“date("z",时间戳)+1”语句计算指定时间戳是一年的第几天。date()返回的天数是从0开始计算的,因此真实天数需要在此基础上加1。

在php中,可以使用substr()函数来读取字符串后几个字符,只需要将该函数的第二个参数设置为负值,第三个参数省略即可;语法为“substr(字符串,-n)”,表示读取从字符串结尾处向前数第n个字符开始,直到字符串结尾的全部字符。

方法:1、用“str_replace(" ","其他字符",$str)”语句,可将nbsp符替换为其他字符;2、用“preg_replace("/(\s|\ \;||\xc2\xa0)/","其他字符",$str)”语句。

查找方法:1、用strpos(),语法“strpos("字符串值","查找子串")+1”;2、用stripos(),语法“strpos("字符串值","查找子串")+1”。因为字符串是从0开始计数的,因此两个函数获取的位置需要进行加1处理。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 Chinese version
Chinese version, very easy to use

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 Linux new version
SublimeText3 Linux latest version