0

我在使用 Infobip 短信网关时遇到问题。当我执行此代码时,我不知道下面的代码有一个名为 no HttpRequest class found 的错误。任何人请帮助我。

<?php

$request = new HttpRequest();
$request->setUrl('https://api.infobip.com/sms/1/text/single');
$request->setMethod(HTTP_METH_POST);

$request->setHeaders(array(
  'accept' => 'application/json',
  'content-type' => 'application/json',
  'authorization' => 'Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ=='
));

$request->setBody('{  
   "from":"InfoSMS",
   "to":"41793026727",
   "text":"Test SMS."
}');

try {
  $response = $request->send();

  echo $response->getBody();
} catch (HttpException $ex) {
  echo $ex;
}
4

1 回答 1

0

你可以在下面使用..它对我有用。

    $curl = curl_init();

    curl_setopt_array($curl, array(
        CURLOPT_URL => 'https://lzz25w.api.infobip.com/sms/2/text/advanced',
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_ENCODING => '',
        CURLOPT_MAXREDIRS => 10,
        CURLOPT_TIMEOUT => 0,
        CURLOPT_FOLLOWLOCATION => true,
        CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
        CURLOPT_CUSTOMREQUEST => 'POST',
        CURLOPT_POSTFIELDS =>'{"messages":[{"from":"$from","destinations":[{"to":"'.$to.'"}],"text":"'.$message.'"}]}',
        CURLOPT_HTTPHEADER => array(
            'Authorization: {authorization}',
            'Content-Type: application/json',
            'Accept: application/json'
        ),
    ));

    $response = curl_exec($curl);

    curl_close($curl);
   // echo $response;
于 2021-01-15T08:19:17.283 回答