我正在使用soap-api请求,它将返回此响应。
这是我的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
}