当前位置:网站首页>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 .
边栏推荐
- 5W1H talk about open source - what is open source?
- C语言循环语句介绍(foe、while、do...while)
- 工具及方法 - 在Source Insight中使用代码格式化工具
- Variable parameter template implements max (accepts multiple parameters, two implementation methods)
- What are the low threshold financial products in 2022? Not much money
- Audio knowledge (III) -- MFCCs code implementation
- 我在深圳,到哪里开户比较好?现在网上开户安全么?
- 《opencv学习笔记》-- 分离颜色通道、多通道混合
- Deep learning ~11+ a new perspective on disease-related miRNA research
- Opencv learning notes - cv:: mat class
猜你喜欢
[Old Wei makes machines] issue 090: keyboard? host? Full function keyboard host!
![[go language questions] go from 0 to entry 4: advanced usage of slice, elementary review and introduction to map](/img/7a/16b481753d7d57f50dc8787eec8a1a.png)
[go language questions] go from 0 to entry 4: advanced usage of slice, elementary review and introduction to map

GTEST from getting started to getting started

How can a shell script (.Sh file) not automatically close or flash back after execution?

链接器 --- Linker

Install Kali on the U disk and persist it

GLOG from getting started to getting started

如何优雅的写 Controller 层代码?
【老卫搞机】090期:键盘?主机?全功能键盘主机!
[mysql_16] variables, process control and cursors
随机推荐
How is the e-commerce red envelope realized? For interview (typical high concurrency)
Variable parameter template implements max (accepts multiple parameters, two implementation methods)
Opencv learning notes - Discrete Fourier transform
Oxylabs live online: website capture demo
【直播回顾】战码先锋第七期:三方应用开发者如何为开源做贡献
Single gene pan cancer + simple experiment can be published 7 points+
不用做实验的6分+基因家族纯生信思路~
Cloud native database: the outlet of the database, you can also take off
【云驻共创】解读HarmonyOS 应用与服务生态
Reading at night -- about microservices and containers
2022年有什么低门槛的理财产品?钱不多
如何优雅的写 Controller 层代码?
The latest hot spot: the use of copper death related genes for tumor prognosis typing!
"Meng Hua Lu" is about to have a grand finale. It's better to learn it first than to look ahead!
Fizz gateway secondary development integration tutorial
5分+的单基因泛癌纯生信思路!
OpenGL es shared context for multi-threaded rendering
《opencv学习笔记》-- 分离颜色通道、多通道混合
Clickhouse deployment and basic usage 1
可变参数模板实现max(接受多个参数,两种实现方式)