当前位置:网站首页>laravel 调用第三方 发送邮件 (php)
laravel 调用第三方 发送邮件 (php)
2022-07-25 09:20:00 【yu-yuan】
composer一个集成腾讯云、短信宝短信发送的工具类:
composer require mrwanghongda/sms-sdk控制器类文件引入该类文件:
use Mrwanghongda\SmsSdk\Sms\SmsFactory;控制器类文件常量:
/**
* 短信宝
*/
const SMS_BAO = 'bao';
/**
* 腾讯云
*/
const SMS_TENCENT = 'tencent'; 控制器类文件方法:
/**
* 发送验证码
* @param Request $request
* @return \think\response\Json
*/
function send2(Request $request){
$code=rand(0000,9999);
$tel=$request->post('tel');
//工厂模式
$smsObj = (new SmsFactory(SmsFactory::SMS_BAO))->getSmsService();
$config = [
/* 填写平台对应的CAM密匙secretId,短信宝填写平台账号*/
'secretId' => '',
/* 填写平台对应的CAM密匙secretKey,短信宝填写平台密码*/
'secretKey' => '',
/* 短信应用ID: 短信SdkAppId在 [短信控制台] 添加应用后生成的实际SdkAppId,示例如1400006666 ,短信宝默认为空*/
'smsSdkAppId' => '',
/* 验证码,示例如5039 */
'code' => $code,
/* 填写腾讯、阿里平台对应的签名内容,短信宝则默认为空 */
'signName' => '',
/* 发送的手机号,示例如17899873465 */
'tel' => $tel,
/* 模板 ID: 必须填写已审核通过的模板 ID。模板ID可登录 [短信控制台] 查看 */
'templateId' => "",
/* 模板发送的短信内容,短信宝则需要填写 如:"【短信宝】您的验证码是"5390",3分钟有效。", 腾讯、阿里默认为空 */
'content' => '【短信宝】您的验证码是'.$code.',3分钟有效。',//
];
$result = $smsObj->send($config);
return json([
'code'=>200,
'msg'=>'成功',
'data'=>$config['content']
]);
}边栏推荐
猜你喜欢

idea 热部署

idea实用tips---如今将pom.xml(红色)改为pom.xml(蓝色)

~3 ccf 2022-03-2 出行计划

Week summary

学习 Redis linux 安装Redis

Idea practical tips --- now change pom.xml (red) to pom.xml (blue)

【代码源】每日一题 - 排队

Detailed explanation of the use of nanny scanner class

Analysis of five data structure principles of redis
![[GKCTF 2021]easynode](/img/f0/1daf6f83fea66fdefd55608cbddac6.png)
[GKCTF 2021]easynode
随机推荐
How can technologists start their personal brand? Exclusive teaching of top five KOLs
[WSN communication] optimize HWSN energy-saving clustering protocol based on MATLAB biogeography [including Matlab source code, 1989]
*7-2 CCF 2015-09-2 日期计算
C language and SQL Server database technology
uni-app如何获取位置信息(经纬度)
[GKCTF 2021]easynode
SSM框架整合,简单案例
Machine learning -- detailed introduction of standardscaler (), transform (), fit () in sklearn package
Redis安装(Ubuntu)
CentOS changes MySQL database directory
多态和接口
Idea hot deployment
深入解读C语言随机数函数和如何实现随机数
Go foundation 2
*6-3 节约小能手
Detailed explanation of the use of nanny scanner class
The difference between abstract classes and interfaces (the most detailed)
Idea practical tips --- now change pom.xml (red) to pom.xml (blue)
学习 Redis linux 安装Redis
什么是贫血模型和充血模型?