【发布时间】:2020-03-13 22:22:44
【问题描述】:
我有通过 Nexmo 客户端发送短信通知的方法:
try {
$client = new Client(new SignatureSecret($nexmoKey, $signatureSecret, 'md5hash'));
$message = $client->message()->send(
[
'to' => $this->userNumber,
'from' => $from,
'text' => $this->notificationMessage,
'callback' => $webhookReceiveURL,
]
);
$response = $message->getResponseData();
$this->notificationId = $response['messages'][0]['message-id'];
return true;
} catch (\Exception $e) {
$this->exceptions[] = $e->getMessage();
return false;
}
如果我将这段代码放在服务类中,在 Laravel 的命令中通过 crontab 调用 handle() 方法,我会得到:无效签名错误,但如果我从任何控制器方法调用此方法,通知发送成功。如果我尝试通过 crontab 发送通知,谁能解释为什么会出错?
【问题讨论】: