Laravel 的 Twilio API
Twilio API for Laravel
我正在使用 twilio 向我测试过的应用程序发送消息,它正在运行。如果产品数据库 table 的产品状态为 0,我需要帮助每 1 小时发送一次消息。
例如,如果有状态为 0 的产品,则发送一条消息,如果在发送消息 1 小时后它们仍然是状态 0 的产品,直到它们不是产品。
谢谢
//Controller
public function pendingNotification() {
$products = Product::where('status', 0)->get();
if ($products->any()) {
$sid = env('SID');
$token = env('AUTH_TOKEN');
$twilio = new Client($sid, $token);
$message = $twilio->messages
->create("whatsapp:+55 555 555", // to
array(
"from" => "whatsapp:+1 555 5555",
"body" => "Hello, you have pending products"
)
);
print($message->sid);
}
}
我建议您查看 laravel 文档中的调度程序:
https://laravel.com/docs/5.7/scheduling
您的代码将类似于以下内容:
$schedule->command('analytics:report')
->hourly()
->runInBackground();
我正在使用 twilio 向我测试过的应用程序发送消息,它正在运行。如果产品数据库 table 的产品状态为 0,我需要帮助每 1 小时发送一次消息。
例如,如果有状态为 0 的产品,则发送一条消息,如果在发送消息 1 小时后它们仍然是状态 0 的产品,直到它们不是产品。
谢谢
//Controller
public function pendingNotification() {
$products = Product::where('status', 0)->get();
if ($products->any()) {
$sid = env('SID');
$token = env('AUTH_TOKEN');
$twilio = new Client($sid, $token);
$message = $twilio->messages
->create("whatsapp:+55 555 555", // to
array(
"from" => "whatsapp:+1 555 5555",
"body" => "Hello, you have pending products"
)
);
print($message->sid);
}
}
我建议您查看 laravel 文档中的调度程序: https://laravel.com/docs/5.7/scheduling
您的代码将类似于以下内容:
$schedule->command('analytics:report')
->hourly()
->runInBackground();