1.短信宝官网:https://www.smsbao.com/
2.在extend创建smsbao文件夹,然后创建SmsBao.php文件
3.SmsBao.php文件内容:
<?php
namespace smsbao;/*** 短信模块《短信宝》* https://www.smsbao.com/* Class SmsBao* @package smsbao*/
class SmsBao{public static $errCode = ['30'=>'错误密码','40'=>'账号不存在','41'=>'余额不足','43'=>'IP地址限制','50'=>'内容含有敏感词','51'=>'手机号码不正确',];/*** 发送短信* @param $phone* @param $code* @return bool*/public static function sendSms($phone,$code){$param = ['u'=>config('app.smsBao.u'),'p'=>md5(config('app.smsBao.p')),'c'=>UrlEncode('【短信宝】您的验证码是'.$code)];$url = "http://api.smsbao.com/sms?u={$param['u']}&p={$param['p']}&g=GOODSID&m={$phone}&c={$param['c']}";return file_get_contents($url);}
}
4:调用
use smsbao\SmsBao;$phone = 您的手机号;
$code = 验证码;
$data = SmsBao::sendSms($phone,$code);
if ($data!=0) {dd('短信发失败:'.SmsBao::$errCode[$data]);
}
cache('sms_' . $phone,$code);
dd('成功');
5:验证 验证码是否正确
$phone = input('phone');
$code = input('code');
if ($code != cache('sms_' . $phone)) {dd('验证码错误');
}
dd('验证码正确');