当前位置:网站首页>Example of SMS interface verification code function implemented by ThinkPHP framework
Example of SMS interface verification code function implemented by ThinkPHP framework
2022-06-24 12:17:00 【PHP Development Engineer 】
This article gives an example of thinkPHP The SMS interface verification code function implemented by the framework . Share with you for your reference , As follows :
I use a model called SMS treasure Application , Newly registered users are free 3 Test SMS , Find a BUG, The same mobile phone can be registered indefinitely , It's OK to play by yourself .
There is no message in the SMS interface code , I don't feel very clear , I tested it myself , It can be used , Just call it directly , There are still a lot of details to deal with if it is used in the project , such as Set the lifetime of a verification code , And you can only press the button every other minute , There is also the ability to judge whether another user can use the SMS sent by this user , I will do it again when I have time , Now let's start with a simple version
View layer View
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Ajax No refresh upload </title> </head> <script type="text/javascript" src="__PUBLIC__/js/jquery-1.10.2.min.js"></script> <body> <div> Please enter your mobile number :<input type="text" name="phone" class="phone"> </div> <div> <a href="javascript:;" rel="external nofollow" class="butphone"> Click to get SMS verification code </a> </div> </body> <script type="text/javascript"> $('.butphone').click(function(){ var phone = $('.phone').val();// Phone number $.post( "{:U('smsbao')}",// The method of transmission {phone1:phone},// Parameters function (data){ if(data == '1'){ alert(' Input box cannot be empty '); }else if(data == '2'){ alert(' The value entered is non numeric '); }else{ alert(data); } }, 'json' ) }) </script> </html>
Controller layer Controller
<?php namespace Home\Controller; use Think\Controller; class IndexController extends Controller { // View public function index() { $this->display(); } // Short message interface public function smsbao() { $phonenum = trim( I('post.phone1') );// Parameters received // First, judge that the phone is not empty if(empty($phonenum) ){ $this->ajaxReturn('1'); } // Judge whether it is a number $boolphone = is_numeric($phonenum); if($boolphone){ $statusStr = array( "0" => " Message sent successfully ", "-1" => " Incomplete parameters ", "-2" => " Server space does not support , Please confirm support curl perhaps fsocket, Contact your space provider to solve or replace the space !", "30" => " Wrong password ", "40" => " Account does not exist ", "41" => " Lack of balance ", "42" => " The account has expired ", "43" => "IP Address restrictions ", "50" => " The content contains sensitive words " ); $num = rand(100000, 999999);// Set random numbers setcookie("numset", $num);// Put values in COOKIE in , Close the browser and clear cookie; $smsapi = "http://api.smsbao.com/"; $user = "asdf75054138"; // SMS platform account $pass = md5("asdf75054138"); // SMS platform password $content="[Bug], Verification from Four Musketeers , Verification Code :".$num;// The text message to send , Just set up $phone = $phonenum;// Mobile phone number to send SMS $sendurl = $smsapi."sms?u=".$user."&p=".$pass."&m=".$phone."&c=".urlencode($content);// Fixed format $result =file_get_contents($sendurl);// Fixed format $this->ajaxReturn( $statusStr[$result] );// Whether the SMS is sent successfully }else{ $this->ajaxReturn( '2' ); } } }
Various renderings :
Complete example :http://github.crmeb.net/u/defu
come from “ Open source world ” , link :https://ym.baisou.ltd/post/675.html, If you want to reprint , Please indicate the source , Otherwise, the legal liability will be investigated .
边栏推荐
- How to develop mRNA vaccine? 27+ pancreatic cancer antigen and immune subtype analysis to tell you the answer!
- Which commercial insurance endowment insurance is good? Ranking of commercial endowment insurance products in 2022
- Popular science of data annotation: ten common image annotation methods
- Why does the virtual machine Ping the host but not the virtual machine
- 夜晚读书 -- 关于微服务和容器
- [cloud based co creation] interpretation of harmonyos application and service ecology
- 哪个商业保险养老险好?2022年商业养老保险产品排名
- 怎样购买打新债 开户是安全的吗
- 如何优雅的写 Controller 层代码?
- 《opencv学习笔记》-- 感兴趣区域(ROI)、图像混合
猜你喜欢
Basic path test of software test on the function of the previous day
【Go语言刷题篇】Go从0到入门4:切片的高级用法、初级复习与Map入门学习
qt -- QTabWidget 中支持拖拽TabBar项
Group planning - General Review
程序员大部分时间不是写代码,而是。。。
电商红包雨是如何实现的?拿去面试用(典型高并发)
TP-LINK 1208 router tutorial (2)
【老卫搞机】090期:键盘?主机?全功能键盘主机!
美团基于 Flink 的实时数仓平台建设新进展
New progress in the construction of meituan's Flink based real-time data warehouse platform
随机推荐
How stupid of me to hire a bunch of programmers who can only "Google"!
保险APP适老化服务评测分析2022第06期
计组-总复习
电商红包雨是如何实现的?拿去面试用(典型高并发)
Embedded must learn! Detailed explanation of hardware resource interface - based on arm am335x development board (Part 2)
[Old Wei makes machines] issue 090: keyboard? host? Full function keyboard host!
Nacos source code - Interface read configuration
11+! Methylation modification patterns based on m6A regulatory factors in colon cancer are characterized by different tumor microenvironment immune spectra
The latest hot spot: the use of copper death related genes for tumor prognosis typing!
Jenkins remote publishing products
[go language questions] go from 0 to entry 4: advanced usage of slice, elementary review and introduction to map
Why choose b+ tree as storage engine index structure
Is it safe to open an account for how many new bonds you can apply for
C语言循环语句介绍(foe、while、do...while)
Opencv optical flow prediction and remap remapping function usage
【数字IC/FPGA】Booth乘法器
GLOG from getting started to getting started
Opencv learning notes - regions of interest (ROI) and image blending
Axi low power interface
How to develop mRNA vaccine? 27+ pancreatic cancer antigen and immune subtype analysis to tell you the answer!