当前位置:网站首页>Laravel Vonage SMS sending
Laravel Vonage SMS sending
2022-06-25 04:52:00 【Kiway.】
Import SMS package
Integrated SMS is the same , Find the right SMS interface provider , Then interface with them . My project is mainly for foreign customers , So use the vonage The SMS interface of .
First, reference the package to Laravel In the project , If it fails ,composer update See what's wrong , It's usually php.ini The configuration of limits the memory size .
quote :composer require vonage/client
After the package is introduced into the project, you can write interface calls .
Interface code :
<?php
namespace App\Lib\Sms;
class Vonage {
static private $_un = '****'; // account number
static private $_pw = '****'; // password
/* ========== Business module ========== */
public function send($phone,$code){
$basic = new \Vonage\Client\Credentials\Basic($this::$_un, $this::$_pw);
$client = new \Vonage\Client($basic);
// $client = new \Vonage\Client($basic, ['base_rest_url' => 'https://rest.nexmocn.com']);
$response = $client->sms()->send(
new \Vonage\SMS\Message\SMS($phone, 'JCZN', ' Your SMS verification code is :'.$code)
);
$message = $response->current();
return $message;
}
}
Other files call methods of interface code :
public function sendMobileCode()
{
$data = $this->request->input();
$code= rand(1000,9999);
// todo Send a text message
$sms = new \App\Lib\Sms\vonage();
$res = $sms->send($data['phone'],$code);
if ($res->getStatus()==0){
\App\Lib\AjaxApp\Result::OutPut(1, '100001',$res->getMessageId(),' Verification code sent successfully ');
}else{
\App\Lib\AjaxApp\Result::OutPut(0, '100002',$res->getMessageId(),' Verification code sending failed ');
}
}
This is simplified code , Other restrictions can be added slowly in the method , For example, this text message is used for registration or password retrieval , Collect the number of times this mobile number is sent ,IP Address sending restrictions , Short time multiple sending limit, etc .
边栏推荐
猜你喜欢

Penetration test - directory traversal vulnerability

jsz中的join()

The solution of wechat applet switchtab unable to take parameters

Teach you to write non maintainable PHP code step by step

SOC验证环境的启动方式

olap分析引擎——Kylin4.0

大话云原生数据库中的存算分离

Join() in JSZ

ASEMI大功率场效应管和三极管的区别

Record the problem of C # print size once
随机推荐
Excel exports data to SQL and pictures to folder through macro | VBA
魔法猪系统重装大师怎么使用
Difference between asemi high power FET and triode
Paper notes: multi label learning ESMC (I don't understand it, but I haven't written it yet, so I'll put it here for a place temporarily)
How PHP gets the user's City
Write shell script error summary
Part I Verilog quick start
基于Cortex-M3、M4的精准延时(系统定时器SysTick延时,可用于STM32、ADuCM4050等)
JS' sort() function
多睡觉,能减肥,芝加哥大学最新研究:每天多睡1小时,等于少吃一根炸鸡腿...
buuctf web
dotnet-exec 0.4.0 released
《QDebug 2022年6月》
XML (VIII)
[untitled]
计算学生成绩等级(虚函数和多态)
In Net 6 using dotnet format formatting code
[image fusion] image fusion based on MATLAB directional discrete cosine transform and principal component analysis [including Matlab source code 1907]
How to make colleagues under the same LAN connect to their own MySQL database
JS, BOM, DOM (VI)