2017-02-15 135 views
3

我不知道如何把這個,但我本來是要發送帶有以下格式的SOAP請求:是否在SOAP請求NS1和TEM的不匹配影響的要求?

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
xmlns:tem="http://tempuri.org/"> 
    <soapenv:Header/> 
    <soapenv:Body> 
     <tem:RequestTopup> 
      <tem:sClientUserName>?</tem:sClientUserName> 
      <tem:sClientPassword>?</tem:sClientPassword> 
      <tem:sClientTxID>?</tem:sClientTxID> 
      <tem:sProductID>?</tem:sProductID> 
      <tem:dProductPrice>?</tem:dProductPrice> 
      <tem:sCustomerAccountNumber>?</tem:sCustomerAccountNumber> 
      <tem:sCustomerMobileNumber>?</tem:sCustomerMobileNumber> 
      <tem:sEncKey>?</tem:sEncKey> 
     </tem:RequestTopup> 
    </soapenv:Body> 
</soapenv:Envelope> 

我的PHP代碼是象下面這樣:

$opts = array(
    'ssl' => array('ciphers' => 'RC4-SHA', 'verify_peer' => false, 'verify_peer_name' => false) 
); 

$params = array(
    'encoding' => 'UTF-8', 
    'verifypeer' => false, 
    'verifyhost' => false, 
    'trace' => 1, 'exceptions' => 1, 
    "connection_timeout" => 180, 
    'stream_context' => stream_context_create($opts) 
); 



$client = new SoapClient("http://xmpl/connect.asmx?WSDL", $params);  

    $txn_id = "2017021234567"; 

$result = $client->RequestTopup(
    array(
     'sClientUserName' => '6', 
     'sClientPassword' => '123456789', 
     'sProductID' => '1', 
     'dProductPrice' => '10', 
     'sClientTxID' => $txn_id, 
     'sCustomerAccountNumber' => '60166527234', 
     'sCustomerMobileNumber' => '60166527234', 
     'sEncKey' => 'sample_enc', 
    ) 
); 

echo $client->__getLastRequest(); 

現在的問題這是否會生成正確格式的xml,但會將「tem」替換爲「ns1」。我很抱歉地說,但我甚至不知道這兩者之間的區別和谷歌搜索沒有多大幫助。

這會不會使任何區別,如果我要求與「NS1」的XML?或者我應該改變它爲「tem」,因爲客戶端期望它?請幫忙。

回答

1

它不應該。名稱空間前綴僅引用實際名稱空間(xmlns:*名稱空間定義節點中的值)。前綴對元素節點是可選的,並且可以在每個元素節點上更改。所以tem:RequestTopup實際應被理解爲{http://tempuri.org/}RequestTopup。這裏有3個例子,所有的解析爲一個節點命名空間中的http://tempuri.org/與當地名RequestTopup

  • <tem:RequestTopup xmlns:tem="http://tempuri.org/"/>
  • <ns1:RequestTopup xmlns:ns1="http://tempuri.org/"/>
  • <RequestTopup xmlns="http://tempuri.org/"/>

不過,我已經看到了很多錯誤的實現那麼我想。它們經常依賴特定的命名空間前綴並忽略實際的命名空間。

+0

非常感謝..你讓一切變得清晰..然而,有沒有什麼辦法,用tem替換那些ns1? –

+0

你將不得不重新創建XML節點。我在FluentDOM中實現了一個可用於執行此操作的優化器:https://github.com/FluentDOM/FluentDOM/blob/master/examples/Transformer/Namespaces/optimize.php – ThW