我正在使用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);
}
我想从<StatusCode>00</StatusCode>
对象中获得body
。
我怎么能得到这个?
谢谢
答案 0 :(得分:0)
最后,我知道了。响应不是常规的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
}