当前位置:网站首页>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 .
边栏推荐
- The solution of distributed system: directory, message queue, transaction system and others
- Use go to process millions of requests per minute
- Deep parsing and implementation of redis pub/sub publish subscribe mode message queue
- [Architect (Part 41)] installation of server development and connection to redis database
- Jenkins performance test
- Embedded must learn! Detailed explanation of hardware resource interface - based on arm am335x development board (Part 1)
- Why does the virtual machine Ping the host but not the virtual machine
- 打新债的条件 开户是安全的吗
- ArrayList#subList这四个坑,一不小心就中招
- 数据标注科普:十种常见的图像标注方法
猜你喜欢

如何优雅的写 Controller 层代码?
![[live review] battle code pioneer phase 7: how third-party application developers contribute to open source](/img/fa/e52bd8a1a404a759ef6ba88e8da0f0.png)
[live review] battle code pioneer phase 7: how third-party application developers contribute to open source

工具及方法 - 在Source Insight中使用代码格式化工具

Qt: judge whether the string is in numeric format
Cloud native database: the outlet of the database, you can also take off

FreeRTOS overview and experience

u盘安装kali并且持久化

PHP SMS notification + voice broadcast automatic double call

How to write controller layer code gracefully?

Tools and methods - use code formatting tools in source insight
随机推荐
基于AM335X开发板 ARM Cortex-A8——Acontis EtherCAT主站开发案例
Turn 2D photos into 3D models to see NVIDIA's new AI "magic"!
Variable parameter template implements max (accepts multiple parameters, two implementation methods)
Opencv learning notes - matrix normalization normalize() function
How to develop hospital information system (his) with SMS notification and voice function
About the unsupported instruction set SSE 4.2 of CPU in virtualization
软件测试 对前一日函数的基本路径测试
Is it safe to apply for new bonds to open an account
程序员大部分时间不是写代码,而是。。。
Example of PHP observer mode [useful in the laravel framework]
Is it safe to open an account under the conditions of new bonds
数据标注科普:十种常见的图像标注方法
Fizz gateway secondary development integration tutorial
怎样购买打新债 开户是安全的吗
Is it safe to open an account for how many new bonds you can apply for
11+的基于甲基化组和转录组综合分析识别葡萄膜黑色素瘤中新的预后 DNA 甲基化特征~
Oxylabs live online: website capture demo
美团基于 Flink 的实时数仓平台建设新进展
I'm in Shenzhen. Where can I open an account? Is it safe to open an account online now?
How to calculate the bandwidth of video transmission? How much bandwidth is required to transmit 4K video?