laravel アプリケーションで SMS を送信しようとしています。私はinfobipテストアカウントを持っていて、その詳細をSMSに使用していますが、このエラーが発生しています:
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;
サイトからダイレクトテキストメッセージを送信しようとしたので、ユーザー名とパスワードは正しいです。
誰かが私が間違っていることを手伝ってくれますか?
ありがとう!