本示例使用了阿里大魚作為api
- 安裝依賴
composer require flc/dysms
- 注冊阿里大魚帳號并且添加簽名醒叁、短信模板糯景、找到accessKeys
- 發(fā)短信
use Flc\Dysms\Client;
use Flc\Dysms\Request\SendSms;
class SMSController extends Controller
{
// 發(fā)短信
$config = [
'accessKeyId' => '你的key',
'accessKeySecret' => '你的secret',
];
$client = new Client($config);
$sendSms = new SendSms();
$sendSms->setPhoneNumbers(手機號);
$sendSms->setSignName('簽名');
$sendSms->setTemplateCode('短信模板');
$msg = $psy['realname'] . ($status == 2 ? '通過' : '未通過');
$sendSms->setTemplateParam(['relname' => $msg]);
$smsRes = $client->execute($sendSms);
if (strtoupper($smsRes->Code) != 'OK') {
return response()->json($smsRes->Message, 501);
}
}