【问题标题】:Laravel Nexmo invalid signatureLaravel Nexmo 无效签名
【发布时间】: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 发送通知,谁能解释为什么会出错?

【问题讨论】:

    标签: php laravel cron vonage


    【解决方案1】:

    如果相同的代码在控制器中工作,听起来配置设置没有正确传递到作业中。我会确保 $nexmoKey$signatureSecret 在工作中看起来正确。

    顺便说一句,我们还通过nexmo/laravel (https://github.com/Nexmo/nexmo-laravel/) 提供了一个 Laravel 插件,它通过服务容器和外观层提供对 Nexmo 对象的访问。这可能有助于减少制作 Nexmo 对象的样板。

    【讨论】:

    • 一开始我也有同样的想法,但后来我尝试回应他们,他们是正确的。之后我尝试对它们进行硬编码,但得到了同样的错误。
    猜你喜欢
    • 2019-05-22
    • 2017-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-03
    • 2022-06-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多