【发布时间】:2017-11-09 14:30:54
【问题描述】:
好的,我在砖墙...所以我成功地向 php 中的 web 服务发出请求,我可以捕获响应并使用 php.net 能够以可读形式输出结果/响应
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<GetLoanDetailResponse xmlns="http://vendorsite.com/">
<GetLoanDetailResult><WEB><LOANDETAIL><acctrefno>31415</acctrefno><master_acctrefno>0</master_acctrefno><loan_number>TEST100001</loan_number><name>HILL ALAN</name><shortname>ALAN HILL</shortname><current_payoff_balance>14,358.83</current_payoff_balance><curr_date>07/14/2015</curr_date><curr_maturity_date>07/14/2021</curr_maturity_date><interest_accrued_thru_date>06/06/2017</interest_accrued_thru_date><current_note_amount>10,000.00</current_note_amount><current_principal_balance>10,000.00</current_principal_balance><current_interest_balance>4,358.83</current_interest_balance><current_fees_balance>0.00</current_fees_balance><current_late_charge_balance>0.00</current_late_charge_balance><current_perdiem>6.30</current_perdiem><current_interest_rate>23.00000</current_interest_rate><total_past_due_balance>5,651.05</total_past_due_balance><total_current_due_balance>5,651.05</total_current_due_balance><next_billing_date>06/18/2017</next_billing_date><days_past_due>662</days_past_due><current_pending>0</current_pending><current_impound_balance>0</current_impound_balance><last_payment_date>05/18/2017</last_payment_date><last_payment_amount>5</last_payment_amount><status_code>ACTIVE</status_code><loan_type>Term</loan_type><open_date>07/14/2015</open_date><last_activity_date>05/18/2017</last_activity_date><current_udf1_balance>0.00</current_udf1_balance><current_udf2_balance>0.00</current_udf2_balance><current_udf3_balance>0.00</current_udf3_balance><current_udf4_balance>0.00</current_udf4_balance><current_udf5_balance>0.00</current_udf5_balance><current_udf6_balance>0.00</current_udf6_balance><current_udf7_balance>0.00</current_udf7_balance><current_udf8_balance>0.00</current_udf8_balance><current_udf9_balance>0.00</current_udf9_balance><current_udf10_balance>0.00</current_udf10_balance><current_suspense_balance>0.00</current_suspense_balance><interest_method>SI</interest_method><term_char>Payments</term_char><term>72</term><term_due>72</term_due></LOANDETAIL></WEB></GetLoanDetailResult>
</GetLoanDetailResponse>
</soap:Body>
</soap:Envelope>
使用: echo "RESPONSE:\n" 完成。 htmlentities(str_ireplace('>\n__getLastResponse())) 。 "\n";
我试过simplexml_load_string() will not read soap response with "soap:" in the tags
和
How to drill into SOAP Namespaces with SimpleXML & PHP
尝试How to convert SOAP response to PHP Array?再次
我可以在堆栈溢出和 php.net / google 上找到所有内容。我不断看到对错误https://bugs.php.net/bug.php?id=48966 的引用,我现在正试图用它来解决这个问题......我真的不想使用 dom 似乎应该有一个 php 唯一的方法来读取这个响应......奇怪的是当我调用 $soapClient->__getLastResponse()) 我得到 p>
<WEB><LOANDETAIL><acctrefno>31415</acctrefno><master_acctrefno>0</master_acctrefno><loan_number>TEST100001</loan_number><name>Last Name F Name</name><shortname>Name</shortname><current_payoff_balance>14,358.83</current_payoff_balance><curr_date>07/14/2015</curr_date><curr_maturity_date>07/14/2021</curr_maturity_date><interest_accrued_thru_date>06/06/2017</interest_accrued_thru_date><current_note_amount>10,000.00</current_note_amount><current_principal_balance>10,000.00</current_principal_balance><current_interest_balance>4,358.83</current_interest_balance><current_fees_balance>0.00</current_fees_balance><current_late_charge_balance>0.00</current_late_charge_balance><current_perdiem>6.30</current_perdiem><current_interest_rate>23.00000</current_interest_rate><total_past_due_balance>5,651.05</total_past_due_balance><total_current_due_balance>5,651.05</total_current_due_balance><next_billing_date>06/18/2017</next_billing_date><days_past_due>662</days_past_due><current_pending>0</current_pending><current_impound_balance>0</current_impound_balance><last_payment_date>05/18/2017</last_payment_date><last_payment_amount>5</last_payment_amount><status_code>ACTIVE</status_code><loan_type>Term</loan_type><open_date>07/14/2015</open_date><last_activity_date>05/18/2017</last_activity_date><current_udf1_balance>0.00</current_udf1_balance><current_udf2_balance>0.00</current_udf2_balance><current_udf3_balance>0.00</current_udf3_balance><current_udf4_balance>0.00</current_udf4_balance><current_udf5_balance>0.00</current_udf5_balance><current_udf6_balance>0.00</current_udf6_balance><current_udf7_balance>0.00</current_udf7_balance><current_udf8_balance>0.00</current_udf8_balance><current_udf9_balance>0.00</current_udf9_balance><current_udf10_balance>0.00</current_udf10_balance><current_suspense_balance>0.00</current_suspense_balance><interest_method>SI</interest_method><term_char>Payments</term_char><term>72</term><term_due>72</term_due></LOANDETAIL></WEB>
我还没有能够爆炸成一个数组......
当我尝试使用 jsonencode/decode 进行任何操作时,请注意 GetLoanDetailResult,我会得到一个具有此值的键,并在非定界字符串中包含其余数据...
GOAL 的结尾是将其放入一个数组中,这样我就可以提取这些值并使用它们来填充新变量的参数。
在ubuntu服务器上使用php7.0
How to convert SOAP response to PHP Array?之后与响应交互的代码
$loanDetail = var_dump($loanUpdate);
$response = preg_replace("/(<\/?)(\w+):([^>]*>)/", "$1$2$3", $soapClient->__getLastResponse());
$xml = new SimpleXMLElement($response);
$body = $xml->xpath('//SBody');
var_export($xml);
echo "======================<br />";
var_export($body);
echo "======================<br />";
$array = json_decode(json_encode((array)$body), TRUE);
print_r($array);
返回
object(stdClass)#3 (1) {
["NLSGetLoanDetailResult"]=>
string(24) "7"
}
SimpleXMLElement::__set_state(array(
'soapBody' =>
SimpleXMLElement::__set_state(array(
'NLSGetLoanDetailResponse' =>
SimpleXMLElement::__set_state(array(
'NLSGetLoanDetailResult' => '7',
)),
)),
))======================
array (
)======================
Array
(
)
【问题讨论】:
-
你的代码在哪里显示你在肥皂请求后做了什么?
-
目前一直在变化(上传到底部?)
-
没有运气让其中一项工作@mkaatman,但尝试
-
我不知道你有什么,但通常看起来你得到了一个空数组。故障排除 101:转储上一个变量。 $xml,然后是 $response。继续跟踪它,直到你找到它在哪里坏了。
标签: php xml web-services soap response