我在使用Infobip短信网关时有问题。我不知道下面的代码,当我执行这段代码有一个错误称为没有HttpRequest类发现。谁来帮帮我。
<?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;
}
您可以使用下面的…这对我很有用。
$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;