2017-02-15 44 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