本示例使用了阿里大鱼作为api
- 安装依赖
composer require flc/dysms
- 注册阿里大鱼帐号并且添加签名、短信模板、找到accessKeys
- 发短信
use Flc\Dysms\Client;
use Flc\Dysms\Request\SendSms;
class SMSController extends Controller
{
// 发短信
$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);
}
}
网友评论