尝试安装 nexmo 语音 api 时出现错误,我无法独自解决(对服务器的了解有限等)
php /srv/www/...html/func/services/neo/voice_api_first_tts_call.php
Hi, using your key: xxxxxxxxxxxx and secret: xxxxxxxxxxx make a Call with Voice API.
0Using application ID App SMS n VoiceMail to call 0049xxxxx
Generate a JWT for App SMS n VoiceMail.
Fatal error: Uncaught exception 'InvalidArgumentException' with message 'It was not possible to parse your key, reason: ' in /root/vendor/lcobucci/jwt/src/Signer/Rsa.php:57
Stack trace:
/root/vendor/lcobucci/jwt/src/Signer/Rsa.php(26): Lcobucci\JWT\Signer\Rsa->validateKey(false)
1 /root/vendor/lcobucci/jwt/src/Signer/BaseSigner.php(34): Lcobucci\JWT\Signer\Rsa->createHash('eyJ0eXA...', Object(Lcobucci\JWT\Signer\Key))
2 /root/vendor/lcobucci/jwt/src/Builder.php(241): Lcobucci\JWT\Signer\BaseSigner->sign('eyJ0eXA...', Object(Lcobucci\JWT\Signer\Key))
3 /srv/www/nhv/html/func/services/nexmo/voice_api_first_tts_call.php(61): Lcobucci\JWT\Builder->sign(Object(Lcobucci\JWT\Signer\Rsa\Sha256), Object(Lcobucci\JWT\Signer\Key))
4 /srv/www/nhv/html/func/services/nexmo/voice_api_first_tts_call.php(124): generate_token('App SMS n Voice...', 'App SMS n Voice...')
5 {main}
thrown in /root/vendor/lcobucci/jwt/src/Signer/Rsa.php on line 57
(我不太确定是否相关,但服务器有一个 nginx/apache 设置)
我找到了发生错误的脚本,所以我与 openssl 有关……?
private function validateKey($key)
{
if ($key === false) {
throw new InvalidArgumentException(
'It was not possible to parse your key, reason: ' . openssl_error_string()
);
}
$details = openssl_pkey_get_details($key);
if (!isset($details['key']) || $details['type'] !== OPENSSL_KEYTYPE_RSA) {
throw new InvalidArgumentException('This key is not compatible with RSA signatures');
}
}
看来 $key = false, ... 所以脚本缺少 $key,....? 它在这里:
$key = openssl_get_privatekey($key->getContent(), $key->getPassphrase());
答案1
找到答案:
事实上,由于原始原型脚本没有考虑到文件可能位于不同的文件夹中,因此导致文件丢失。