无法从 soap api 响应 json 访问数据

unable to access data from soap api response json

我正在使用 soap api 请求并返回我 this response.

那是我的 laravel 控制器代码。

    public function testResponseSRI($phone, $code)
{
    $url = 'https://tamimahsms.com/user/bulkpush.asmx?wsdl';
    $body = '
    <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Body>
    <SendSMS xmlns="https://www.tamimahsms.com/">
    <UserName>username</UserName>
    <Password>password</Password>
    <Message>test message with code '.$code.'</Message>
    <Priority>1</Priority>
    <Schdate>07/18/2018</Schdate>
    <Sender>AsifSource</Sender>
    <AppID>123456</AppID>
    <SourceRef>7654321</SourceRef>
    <MSISDNs>'.$phone.'</MSISDNs>
    </SendSMS>
    </soap:Body>
    </soap:Envelope>';

    $headers = ['Content-Type: text/xml; charset=utf-8', 'Content-Length: '.strlen($body)];
    $result = SoapClientRequest::send($url, $headers, $body);
    return response()->json($result);
}

我想从 body 对象中获取 <StatusCode>00</StatusCode>。 我怎样才能得到这个?

谢谢

终于想通了。响应不是常规的JSON,首先转换它:

            $data = $jsonResponse->getData();

然后将其视为常规json。现在我可以通过使用 php preg_match

轻松获得 <StatusCode>00</StatusCode>

这样的方法:

if(preg_match("!<StatusCode>(.+)</StatusCode>!i",$data->body,$matches)) 
{
    return $matches[1]      // return 00
}