2016-06-01 18 views
0

以下は私のコードでsoap要求を構成するコードです。私はクライアントを作成することができますが、クライアントを更新するには、クライアントタグの属性としてクライアント番号が必要です。要素属性と子要素を含むPHPソープ要求

 <urn:Client> <- Add attribute to this tag 
     <urn2:LogInfo> 
     </urn2:LogInfo> 
     <urn2:CommonName>Some Value</urn2:CommonName> 
     <urn2:CompanyName>Some Value</urn2:CompanyName> 
     <urn2:StartDate>2016-01-01</urn2:StartDate> 
     <urn2:MainPaymentMethod>0001</urn2:MainPaymentMethod> 
     <urn2:MainPaymentCondition>0003</urn2:MainPaymentCondition> 
     <urn2:ClientType>XXX</urn2:ClientType> 
     <urn2:Address> 
      <urn1:ZipCode>55555</urn1:ZipCode> 
      <urn1:City>City</urn1:City> 
      <urn2:GeneralFitness>MAIN</urn2:GeneralFitness> 
      <urn2:BillingFitness>MAIN</urn2:BillingFitness> 
      <urn2:Area1>NY</urn2:Area1> 
      <urn2:CountryCode>US</urn2:CountryCode> 
     </urn2:Address> 
     <urn2:AreImplicitMandatesOk>false</urn2:AreImplicitMandatesOk> 
     <urn2:ParentInfo urn1:dataOmitted="true"> 
     </urn2:ParentInfo> 
     <urn2:UserProperties urn1:dataOmitted="true"> 
     </urn2:UserProperties> 
     <urn2:MandateInfo urn1:dataOmitted="true"> 
     </urn2:MandateInfo> 
     <urn2:VATInfo> 
     </urn2:VATInfo> 
    </urn:Client> 

しかし、私に必要なのは上記のすべてのことをされ、すべての子要素を持つクライアントタグの属性::

$urn = '<SOME DEFINITION>'; 
$urn1 = '<SOME DEFINITION>'; 
$urn2 = '<SOME DEFINITION>'; 

// Main descriptive content of the client 
$clientType = $clientInfo['clt_type']; 
$companyName = $clientInfo['clt_name']; 
$mainPaymentMethod = '0001'; 
$mainPaymentCondition = '0003'; 

/* Build sales portion */ 
$sales_city = $clientInfo['clt_sales_city']; 
$sales_area1 = $clientInfo['clt_sales_state']; 
$sales_zipCode = $clientInfo['clt_sales_zipcode']; 
$sales_countryCode = $clientInfo['clt_sales_country']; 
$sales_address = $clientInfo['clt_sales_address']; 
$sales_address_two = $clientInfo['clt_sales_address2']; 

$salesGeneralFitness = 'MAIN'; 
$salesBillingFitness = 'MAIN'; 

$salesAddressParams[] = new SoapVar($sales_address, XSD_STRING, null, $urn1, 'Address', $urn1); 
$salesAddressParams[] = new SoapVar($sales_address_two, XSD_STRING, null, $urn1, 'AddressComplement', $urn1); 
$salesAddressParams[] = new SoapVar($sales_zipCode, XSD_STRING, null, $urn1, 'ZipCode', $urn1); 
$salesAddressParams[] = new SoapVar($sales_city, XSD_STRING, null, $urn1, 'City', $urn1); 
$salesAddressParams[] = new SoapVar($salesGeneralFitness, XSD_STRING, null, $urn2, 'GeneralFitness', $urn2); 
$salesAddressParams[] = new SoapVar($salesBillingFitness, XSD_STRING, null, $urn2, 'BillingFitness', $urn2); 
$salesAddressParams[] = new SoapVar($sales_area1, XSD_STRING, null, $urn2, 'Area1', $urn2); 
$salesAddressParams[] = new SoapVar($sales_countryCode, XSD_STRING, null, $urn2, 'CountryCode', $urn2); 

$SalesAddress = new SoapVar($salesAddressParams, SOAP_ENC_OBJECT, null, $urn2, 'Address', $urn2); 
/* End of sales portion */ 

/* Build financial portion */ 
$financial_city = $clientInfo['clt_financial_city']; 
$financial_area1 = $clientInfo['clt_financial_state']; 
$financial_zipCode = $clientInfo['clt_financial_zipcode']; 
$financial_countryCode = $clientInfo['clt_financial_country']; 
$financial_address = $clientInfo['clt_financial_address']; 
$financial_address_two = $clientInfo['clt_financial_address2']; 

$financialGeneralFitness = 'MAIN'; 
$financialBillingFitness = 'MAIN'; 

$financialAddressParams[] = new SoapVar($financial_address, XSD_STRING, null, $urn1, 'Address', $urn1); 
$financialAddressParams[] = new SoapVar($financial_address_two, XSD_STRING, null, $urn1, 'AddressComplement', $urn1); 
$financialAddressParams[] = new SoapVar($financial_zipCode, XSD_STRING, null, $urn1, 'ZipCode', $urn1); 
$financialAddressParams[] = new SoapVar($financial_city, XSD_STRING, null, $urn1, 'City', $urn1); 
$financialAddressParams[] = new SoapVar($financialGeneralFitness, XSD_STRING, null, $urn2, 'GeneralFitness', $urn2); 
$financialAddressParams[] = new SoapVar($financialBillingFitness, XSD_STRING, null, $urn2, 'BillingFitness', $urn2); 
$financialAddressParams[] = new SoapVar($financial_area1, XSD_STRING, null, $urn2, 'Area1', $urn2); 
$financialAddressParams[] = new SoapVar($financial_countryCode, XSD_STRING, null, $urn2, 'CountryCode', $urn2); 

$FinancialAddress = new SoapVar($financialAddressParams, SOAP_ENC_OBJECT, null, $urn2, 'Address', $urn2); 

/* Build The rest of the required (not used) soap request */ 

$LogInfo = new SoapVar('', XSD_STRING, null, $urn2, 'LogInfo', $urn2); 
$CommonName = $StartDate = new SoapVar($companyName, XSD_STRING, null, $urn2, 'CommonName', $urn2); 
$CompanyName = $StartDate = new SoapVar($companyName, XSD_STRING, null, $urn2, 'CompanyName', $urn2); 
$AreImplicitMandatesOk = new SoapVar('false', XSD_STRING, null, $urn2, 'AreImplicitMandatesOk', $urn2); 
$ParentInfo = new SoapVar('', XSD_STRING, null, $urn2, 'ParentInfo', $urn2); 
$UserProperties = new SoapVar('', XSD_STRING, null, $urn2, 'UserProperties', $urn2); 
$StartDate = new SoapVar(date('Y-m-d', time()), XSD_STRING, null, $urn2, 'StartDate', $urn2); 
$MainPaymentMethod = new SoapVar($mainPaymentMethod, XSD_STRING, null, $urn2, 'MainPaymentMethod', $urn2); 
$MainPaymentCondition = new SoapVar($mainPaymentCondition, XSD_STRING, null, $urn2, 'MainPaymentCondition', $urn2); 
$ClientType = new SoapVar($clientType, XSD_STRING, null, $urn2, 'ClientType', $urn2); 
$MandateInfo = new SoapVar('', XSD_STRING, null, $urn2, 'MandateInfo', $urn2); 
$VATInfo = new SoapVar('', XSD_STRING, null, $urn2, 'VATInfo', $urn2); 

/* Set the body content */ 
$Body[] = $LogInfo; 
$Body[] = $CommonName; 
$Body[] = $CompanyName; 
$Body[] = $StartDate; 
$Body[] = $MainPaymentMethod; 
$Body[] = $MainPaymentCondition; 
$Body[] = $ClientType; 
$Body[] = $SalesAddress; 
$Body[] = $FinancialAddress; 
$Body[] = $AreImplicitMandatesOk; 
$Body[] = $ParentInfo; 
$Body[] = $UserProperties; 
$Body[] = $MandateInfo; 
$Body[] = $VATInfo; 

    /* Build entire soap request here */ 
$data = new SoapVar($Body, SOAP_ENC_OBJECT, null, $urn, 'Client', $urn); 
$parameters['Client'] = $data; 

これは生産

<urn:Client Attr1='XXXX1121111'> 

は、私が行ってきました私が知っているすべての投稿を通じて。子要素を持つ要素に属性を生成することはできません。私はXSD_ANYXMLを使用しようとし、SoapVar()に挿入するためのビューを構築し、それは動作しませんでした。なぜなら、名前空間が必要だったからです。これはおそらく別の質問の繰り返しですが、回答が得られていません。以下は

はちょうど私がこの問題にしてきた投稿の一部です:

SOAP request with PHP

Create SOAP request with element attribute using Zend_Soap_Client and stdObject

Send other attributes with xsi:type attribute in Soap Request PHP

SOAP Request from PHP is not working

答えて

0

私は石鹸を構築しようとしていましたSoapVarを介してリクエスト。要素を要素にネストしようとしています。これを行う代わりに、私は単に要求されたのと同じ構造の連想配列を作成しました。

これは、私が得ようとしていた石鹸リクエストを生成しました。私はすべてのsoapvar要素を削除し、配列を関数のパラメータとして使用しました。

関連する問題