Laravel框架接入短信平台进行用户注册短信验证
今天刚接触了一个短信接口平台,云通讯第三方短信提供服务商。http://www.yuntongxun.com/
然后介绍一下怎么使用该短信平台来接入到自己的项目中。
首先你的去注册一个账号,然后根据提供的一些信息,作为接口进行接入。
将account sid、auth token、Rest url、等信息写入代码中。稍后会由示例代码上传的。
然后就是实例化SMS类,调用里面的方法就好了,很多方法都已经封装好了,直接用就好了。
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 | public function sendSMS(Request $request ){ $m3_result = new M3Result(); $phone = $request ->input( 'phone' , '' ); if ( $phone == '' ){ $m3_result ->status = 1; $m3_result ->message = '手机号不能为空' ; return $m3_result ->toJson(); } $sendTemplateSMS = new SendTemplateSMS(); $code = '' ; $charset = '1234567890' ; $_len = strlen ( $charset )-1; for ( $i =0; $i <6;++ $i ){ $code .= $charset [mt_rand(0, $_len )]; } $sendTemplateSMS ->sendTemplateSMS( $phone , array ( $code ,60),1); $deadline = date ( "Y-m-d H:i:s" ,time()+60*60); if (TempPhone::where( 'phone' , $phone )->first()){ TempPhone::where( 'phone' , $phone )->update([ 'code' => $code , 'deadline' => $deadline ]); } else { $tempPhone = new TempPhone(); $tempPhone ->phone= $phone ; $tempPhone ->code= $code ; $tempPhone ->deadline= $deadline ; $tempPhone ->save(); } $m3_result ->status=0; $m3_result ->message= '发送成功' ; return $m3_result ->toJson(); } |
这个是前台进行异步验证的
这个是临时存储验证码的表。
短信接口平台工具类的下载:http://download.csdn.net/detail/yxhbk/9662824
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!