【发布时间】:2021-08-15 10:55:12
【问题描述】:
在我的项目中,我想在赢得指定游戏后向用户发送奖励短信。
所以我已经在GameController 中实现了代码,如下所示..
//some data
$this->send($mobile_number, $message);
//some data
发送函数定义为Trait,如下所示
public function send($mobile_number, $message)
{
$username = config('app.filee')['username'];
$password = config('app.file')['password'];
$sender_id = config('app.file')['sender_id'];
$url = "URL...username=" . $username . "&password=" . $password . "&from=" . $sender_id . "&to=" . $mobile_number . "&content=" . urlencode($message);
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
));
$response = curl_exec($curl);
curl_close($curl);
\Log::info(['SMS_RESPONSE' => $response, 'SENT_MESSAGE' => $message]);
return;
}
我怎样才能将此发送短信延迟到 5 分钟?
在功能上不做很多改动?
【问题讨论】:
-
使用 Laravel 队列并设置延迟。更多信息in the docs.
-
@Peppermintology 对不起,我是 laravel 的新手.. 我需要添加一个工作类吗?如果我需要,我应该在哪里写 send()?.. 你能告诉我工作流程吗..?
-
我不只是发布神奇的代码,我建议您看看一些在线教程,例如this one which is quite quick或this one which goes in to more depth
标签: laravel