我正在尝试使用我的 laravel 应用程序发送短信。我有 infobip 测试帐户并使用该详细信息发送短信但收到此错误:
ClientException in RequestException.php line 111:
Client error: `POST https://api.infobip.com/sms/1/text/single` resulted in a `401 Unauthorized` response:
{"requestError":{"serviceException": {"messageId":"UNAUTHORIZED","text":"Invalid login details"}}}
代码:
$data= '{
"from":"InfoSMS",
"to":"923227124444",
"text":"Test SMS."
}';
$userstring = 'myuserame:password';
$id =base64_encode ( 'myuserame:password' );
echo 'Basic '.$id;
$client = new \GuzzleHttp\Client();
$request = $client->post('https://api.infobip.com/sms/1/text/single',array(
'content-type' => 'application/json'
),['auth' => ['myusername', 'password']]);
$request->setHeaders(array(
'accept' => 'application/json',
'authorization' => 'Basic '.$id,
'content-type' => 'application/json'
));
$request->setBody($data); #set body!
$response = $request->send();
echo $res->getStatusCode(); // 200
echo $res->getBody();
return $response;
用户名和密码是正确的,因为我试图从该站点发送直接短信并在那里工作。
谁能帮我解决我做错了什么?
谢谢!