Bu şekilde dener misin?
function sendSms(array $data): \Illuminate\Http\JsonResponse
{
$mesaj = htmlspecialchars($data['message'], ENT_XML1, 'UTF-8');
$phoneNumber = htmlspecialchars($data['phone_number'], ENT_XML1, 'UTF-8');
$xml = sprintf('<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:impl="http://xxx">
<soapenv:Header/>
<soapenv:Body>
<impl:MesajGonder>
<MesajGonderKriter>
<mesajDetayList>
<mesaj>%s</mesaj>
<telefonNumarasi>%s</telefonNumarasi>
</mesajDetayList>
<smsKullaniciAdi>%s</smsKullaniciAdi>
</MesajGonderKriter>
</impl:MesajGonder>
</soapenv:Body>
</soapenv:Envelope>',
$mesaj,
$phoneNumber,
USERNAME
);
try {
$response = \Illuminate\Support\Facades\Http::withHeaders([
'Content-Type' => 'text/xml; charset=utf-8',
'SOAPAction' => USERNAME,
'Authorization' => 'Basic ' . base64_encode(USERNAME . ':' . PASSWORD),
])->post(URL, $xml);
if ($response->failed()) {
\Illuminate\Support\Facades\Log::error("SMS gönderim hatası: " . $response->body());
return response()->json([
'status' => false,
'alert' => "error",
'message' => "SMS gönderim hatası oluştu",
], 503);
}
$xmlContent = $response->body();
try {
$dom = new \DOMDocument();
$dom->loadXML($xmlContent);
$xpath = new \DOMXPath($dom);
$msgIdNodeList = $xpath->query('//msgId');
if ($msgIdNodeList->length > 0) {
$msgId = $msgIdNodeList->item(0)->nodeValue;
return response()->json([
'status' => true,
'alert' => 'success',
'message' => $msgId,
], 200);
}
return response()->json([
'status' => false,
'alert' => 'error',
'message' => NULL,
], 200);
} catch (\Exception $e) {
\Illuminate\Support\Facades\Log::error("XML parse hatası: " . $e->getMessage());
return response()->json([
'status' => false,
'alert' => 'error',
'message' => 'XML parse hatası oluştu',
], 500);
}
} catch (\Throwable $th) {
\Illuminate\Support\Facades\Log::error("Exception during SMS send: " . $th->getMessage());
return response()->json([
'alert' => "error",
'message' => $th->getMessage(),
], 503);
}
}