php - SOAP 请求中的 ns1 和 tem 不匹配会影响请求吗?

标签 php xml soap soap-client

我不知道怎么写,但我应该发送一个格式如下的 SOAP 请求:

<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' => '60123456789',
        '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”吗?请帮忙。

最佳答案

不应该。命名空间前缀仅引用实际命名空间(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/"/>

但是,我看到了比我想要的更多的错误实现。他们通常依赖特定的命名空间前缀而忽略实际的命名空间。

关于php - SOAP 请求中的 ns1 和 tem 不匹配会影响请求吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42248233/

相关文章:

android - 以编程方式将多个自定义 View 添加到布局

python - python从xml文件中读取数据的方法

java - Liferay SOAP 服务 Java 客户端验证错误

java - 由于 SOAP 信封/ header 混淆,Tomcat 中的任意 HTTP 501 未实现错误

java - 在自定义拦截器 (Soap12FaultOutInterceptor) 中捕获 SOAP Fault 错误

php - Elasticsearch php : aggregations of documents with date interval

php - 使用 AJAX 在 Javascript 中调用 PHP 函数

php - 在复杂查询中使用 GROUP_CONCAT 的 Mysql JOIN

PHP 为除最后一项以外的每一项添加逗号

xml - 如何更改 XSLT 模板在 Visual Studio 2010 中使用的文件?