2

我正在尝试使用 php 5.3.x 从 webservice 响应构建一个表。

这是我的 WSDL 的一部分:

     <s:element name="CardStatementResponse">
    <s:complexType>
        <s:sequence>
            <s:element minOccurs="0" maxOccurs="1" name="CardStatementResult" type="tns:CardStatementResult"/>
        </s:sequence>
    </s:complexType>
</s:element>
<s:complexType name="CardStatementResult">
    <s:sequence>
        <s:element minOccurs="0" maxOccurs="1" name="CardHolder" type="s:string"/>
        <s:element minOccurs="0" maxOccurs="1" name="AccountNo" type="s:string"/>
        <s:element minOccurs="0" maxOccurs="1" name="Currency" type="s:string"/>
        <s:element minOccurs="0" maxOccurs="1" name="MoreTrans" type="s:string"/>
        <s:element minOccurs="1" maxOccurs="1" name="StartBalance" nillable="true" type="s:decimal"/>
        <s:element minOccurs="1" maxOccurs="1" name="EndBalance" nillable="true" type="s:decimal"/>
        <s:element minOccurs="0" maxOccurs="1" name="Transactions" type="tns:ArrayOfTransactionRecord"/>
        <s:element minOccurs="0" maxOccurs="1" name="Delay" type="s:string"/>
    </s:sequence>
</s:complexType>
<s:complexType name="ArrayOfTransactionRecord">
    <s:sequence>
        <s:element minOccurs="0" maxOccurs="unbounded" name="TransactionRecord" nillable="true" type="tns:TransactionRecord"/>
    </s:sequence>
</s:complexType>
<s:complexType name="TransactionRecord">
    <s:sequence>
        <s:element minOccurs="0" maxOccurs="1" name="STAN" type="s:string"/>
        <s:element minOccurs="1" maxOccurs="1" name="TransactionDate" nillable="true" type="s:dateTime"/>
        <s:element minOccurs="0" maxOccurs="1" name="TranType" type="s:string"/>
        <s:element minOccurs="0" maxOccurs="1" name="TranTypeDesc" type="s:string"/>
        <s:element minOccurs="0" maxOccurs="1" name="ReferenceNumber" type="s:string"/>
        <s:element minOccurs="0" maxOccurs="1" name="ApprovalNumber" type="s:string"/>
        <s:element minOccurs="0" maxOccurs="1" name="DebitCredit" type="s:string"/>
        <s:element minOccurs="0" maxOccurs="1" name="TranCurr" type="s:string"/>
        <s:element minOccurs="1" maxOccurs="1" name="TranAmount" nillable="true" type="s:decimal"/>
        <s:element minOccurs="1" maxOccurs="1" name="TranActualAmount" nillable="true" type="s:decimal"/>
        <s:element minOccurs="1" maxOccurs="1" name="TranActivityFee" nillable="true" type="s:decimal"/>
        <s:element minOccurs="0" maxOccurs="1" name="AcctCurr" type="s:string"/>
        <s:element minOccurs="1" maxOccurs="1" name="AcctCurrAmount" nillable="true" type="s:decimal"/>
        <s:element minOccurs="1" maxOccurs="1" name="AcctActivityFee" nillable="true" type="s:decimal"/>
        <s:element minOccurs="1" maxOccurs="1" name="AcctProcessFee" nillable="true" type="s:decimal"/>
        <s:element minOccurs="1" maxOccurs="1" name="AcctServiceFee" nillable="true" type="s:decimal"/>
        <s:element minOccurs="0" maxOccurs="1" name="AcqPart" type="s:string"/>
        <s:element minOccurs="0" maxOccurs="1" name="DataStorRet" type="s:string"/>
        <s:element minOccurs="0" maxOccurs="1" name="CAID" type="s:string"/>
        <s:element minOccurs="0" maxOccurs="1" name="CATI" type="s:string"/>
        <s:element minOccurs="0" maxOccurs="1" name="CATA" type="s:string"/>
        <s:element minOccurs="0" maxOccurs="1" name="MCC" type="s:string"/>
        <s:element minOccurs="0" maxOccurs="1" name="ReversalFlag" type="s:string"/>
        <s:element minOccurs="0" maxOccurs="1" name="AuthorizationFlag" type="s:string"/>
    </s:sequence>
</s:complexType>

这就是我正在尝试的

   $result = $client->CardStatement(array('req' => $parameters));
       $row = $result->Transactions;
        print "
            <div id='demo'>
            <table cellpadding='0' cellspacing='0' border='0' class='display' id='example' width='100%'>
            <thead>
                <tr>
                    <th>Row</th>
                    <th>TransactionDate</th>
                    <th>DebitCredit</th>
                    <th>TranAmount</th>
                    <th>TranActualAmount</th>
                </tr>
            </thead>
            <tbody>";
        foreach ($row as $k => $v) {
            if (($k + 1) % 2 == 0) {
                $grade = 'odd_gradeX';
            } else {
                $grade = 'even_gradeX';
            }
            print "
                <td align='right' class= $grade>" . ($k + 1) . "</td>              
                <td>". $v->TransactionDate. "</td>
                <td align='right'>" . $v->DebitCredit . "</td>
                <td align='right'>" . $v->TranAmount . "</td>
                <td align='right'>" . $v->TranActualAmount . "</td> ";
        }
        print "
            </tbody>
            <tfoot>
                <tr>
                    <th>Row</th>
                    <th>TransactionDate</th>
                    <th>DebitCredit</th>
                    <th>TranAmount</th>
                    <th>TranActualAmount</th>
                </tr>
            </tfoot>
            </table>
         </div>";?>

当 om 尝试访问 Transactions 时出现此错误 Undefined property: stdClass::$Transactions ,所以我的问题是如何访问 Transactions 以及如何从中创建表?假设我正在使用 php SoapClient?

4

1 回答 1

1

在玩了这个 wsdl 之后,我发现我必须将一个复杂类型称为数组,即使它只有一个元素,所以这就是我所做的:

   $result = $client->CardStatement(array('req' => $parameters));
    print "
        <div id='demo'>
        <table cellpadding='0' cellspacing='0' border='0' class='display' id='example' width='100%'>
        <thead>
            <tr>
                <th>Row</th>
                <th>TransactionDate</th>
                <th>DebitCredit</th>
                <th>TranAmount</th>
                <th>TranActualAmount</th>
            </tr>
        </thead>
        <tbody>";
    foreach ($result as $k => $v) {
      $obj = $v->Transactions->TransactionRecord;

      foreach ($obj as $k => $v) {
        if (($k + 1) % 2 == 0) {
            $grade = 'odd_gradeX';
        } else {
            $grade = 'even_gradeX';
        }
        print "
            <td align='right' class= $grade>" . ($k + 1) . "</td>              
            <td>". $v->TransactionDate. "</td>
            <td align='right'>" . $v->DebitCredit . "</td>
            <td align='right'>" . $v->TranAmount . "</td>
            <td align='right'>" . $v->TranActualAmount . "</td> ";
    }
 }
    print "
        </tbody>
        <tfoot>
            <tr>
                <th>Row</th>
                <th>TransactionDate</th>
                <th>DebitCredit</th>
                <th>TranAmount</th>
                <th>TranActualAmount</th>
            </tr>
        </tfoot>
        </table>
     </div>";?>
于 2012-07-18T13:25:10.033 回答