在我的网站中,出于安全目的,我使用infobip 2-Factor Authentication 。我在他们的网站上有一些代码显示错误,例如
Fatal error: Class 'HttpRequest' not found in C:\xampp\htdocs\test\OTP\send.php on line 2
代码如下:
发送.php
<?php
$request = new HttpRequest();
$request->setUrl('https://oneapi.infobip.com/2fa/1/pin');
$request->setMethod(HTTP_METH_POST);
$request->setHeaders(array
('accept' => 'application/json'
,'content-type' => 'application/json'
,'authorization' => 'App SECRET_KEY'));
$request->setBody('{
"applicationId": "YOUR_APPLICATION_ID",
"messageId": "YOUR_MESSAGE_ID",
"to": "PHONE_NUMBER"
}');
try
{
$response = $request->send();
echo $response->getBody();
}
catch (HttpException $ex)
{
echo $ex;
}
?>
以下代码用于请求,这也显示
Fatal error: Class 'HttpRequest' not found in C:\xampp\htdocs\test\OTP\request.php on line 3
请求.php
<?php
$request = new HttpRequest();
$request->setUrl('https://oneapi.infobip.com/2fa/1/pin/{PIN_ID}/verify');
$request->setMethod(HTTP_METH_POST);
$request->setHeaders(array('accept' => 'application/json', 'content-type' => 'application/json','authorization' => 'App YOUR_API_KEY'
));
$request->setBody('{"pin": "PIN_CODE"}');
try
{
$response = $request->send();
echo $response->getBody();
}
catch (HttpException $ex)
{
echo $ex;
}
?>