1

我是 SOAP 新手。我正在尝试将我的应用程序集成到 SmartTurn webservice API(它是一家库存管理公司)。它们是用于 API 操作的 SOAP 和 wsdl。我是肥皂新手,所以我不知道如何在 php 中做到这一点。这是我想使用的 xml。

<?xml version="1.0" encoding="UTF-8" ?><soapenv:Envelope      xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
  <soapenv:Body><saveSalesOrder 
xmlns="http://www.smartturn.com/services/OccamService/sales-order"> 
<inCredential> 
   <ns1:UserId 
xmlns:ns1="http://www.smartturn.com/services/occamtypes">webservice@fithoop.com.au</ns1:UserId>  
  <ns2:Password 
xmlns:ns2="http://www.smartturn.com/services/occamtypes">secret</ns2:Password>  
</inCredential> 
<inSalesOrders> 
  <ns3:externalNumber xmlns:ns3="http://www.smartturn.com/services/sales-order-types">Ext-id-00502</ns3:externalNumber>  
  <ns4:type xmlns:ns4="http://www.smartturn.com/services/sales-order-types">EXTERNAL</ns4:type>  
  <ns5:date xmlns:ns5="http://www.smartturn.com/services/sales-order-types">2012-10-20T00:04:34.479Z</ns5:date>  
 <ns6:dateDue xmlns:ns6="http://www.smartturn.com/services/sales-order-types">2012-10-20T00:04:34.479Z</ns6:dateDue>  
  <ns7:customerName xmlns:ns7="http://www.smartturn.com/services/sales-order-types">customer name</ns7:customerName>  
  <ns8:customerContact 
xmlns:ns8="http://www.smartturn.com/services/sales-order-types">customer contact</ns8:customerContact>  
  <ns9:customerContactPhone 
xmlns:ns9="http://www.smartturn.com/services/sales-order-types">customer phone</ns9:customerContactPhone>  
  <ns10:customerAddress 
xmlns:ns10="http://www.smartturn.com/services/sales-order-types"> 
    <ns11:addressLine1 
xmlns:ns11="http://www.smartturn.com/services/occamtypes">the main street</ns11:addressLine1>  
    <ns12:addressLine2 
xmlns:ns12="http://www.smartturn.com/services/occamtypes">broadway</ns12:addressLine2>  
    <ns13:city 
xmlns:ns13="http://www.smartturn.com/services/occamtypes">Oakland</ns13:city>  
    <ns14:state 
xmlns:ns14="http://www.smartturn.com/services/occamtypes">California</ns14:state>  
    <ns15:country 
xmlns:ns15="http://www.smartturn.com/services/occamtypes">USA</ns15:country>  
    <ns16:postalCode 
xmlns:ns16="http://www.smartturn.com/services/occamtypes">94607</ns16:postalCode>  
  </ns10:customerAddress> 
  <ns17:salesRep xmlns:ns17="http://www.smartturn.com/services/sales-order-types">sales rep</ns17:salesRep>  
  <ns18:useShipToAsBillAddress 
xmlns:ns18="http://www.smartturn.com/services/sales-order-types">false</ns18:useShipToAsBillAddress>  
  <ns19:shipToName xmlns:ns19="http://www.smartturn.com/services/sales-order-types">ship to name</ns19:shipToName>  
  <ns20:shipToContact 
xmlns:ns20="http://www.smartturn.com/services/sales-order-types">ship to contact</ns20:shipToContact>  
  <ns21:shipToContactPhone 
xmlns:ns21="http://www.smartturn.com/services/sales-order-types">ship to contact phone</ns21:shipToContactPhone>  
  <ns22:status xmlns:ns22="http://www.smartturn.com/services/sales-order-types">NEW</ns22:status>  
  <ns23:item xmlns:ns23="http://www.smartturn.com/services/sales-order-types"> 
    <ns23:itemMasterId>BB-10</ns23:itemMasterId>  
    <ns23:description>this is a desc</ns23:description>  
    <ns23:details>these are details</ns23:details>  
    <ns23:orderedQuantity> 
<ns26:value 
xmlns:ns26="http://www.smartturn.com/services/occamtypes">10.0</ns26:value>  
<ns27:unitAbbreviation 
xmlns:ns27="http://www.smartturn.com/services/occamtypes">ea</ns27:unitAbbreviation>  
    </ns23:orderedQuantity> 
  <ns23:customerRequestDate>2007-03-
20T00:04:34.479Z</ns23:customerRequestDate>  
  <ns23:price> 
<ns28:value 
xmlns:ns28="http://www.smartturn.com/services/occamtypes">100.0</ns28:value>  
<ns29:type 
xmlns:ns29="http://www.smartturn.com/services/occamtypes">$10</ns29:type>  
  </ns23:price> 
  <ns23:vendorItemId>vendor item id</ns23:vendorItemId>  
  <ns23:manufacturerItemId>manf item id</ns23:manufacturerItemId>  
  <ns23:upcCode>UPC Code</ns23:upcCode>  
  <ns23:manufacturerId>manf id</ns23:manufacturerId>  
</ns23:item> 
<ns30:comments xmlns:ns30="http://www.smartturn.com/services/sales-order-types">This is a comment</ns30:comments>  
</inSalesOrders> 
</saveSalesOrder> 
</soapenv:Body> 
</soapenv:Envelope>

`

并且 url $url = "https://services.smartturn.com/occam/services/OccamService?wsdl"; 和我想要执行的操作是'saveSalesOrder' 我怎么能在 php 中做到这一点。

提前致谢 。

4

2 回答 2

2

首先,您需要安装并启用 PHP 的 SOAP 扩展。然后:

$url = "https://services.smartturn.com/occam/services/OccamService?wsdl";

$data = array(
    "UserId"               => "secret",
    "Password"             => "secret",
    "type"                 => "EXTERNAL",
    "date"                 => "2012-10-20T00:04:34.479Z",
    "dateDue"              => "2012-10-20T00:04:34.479Z",
    "externalNumber"       => "Ext-id-00502",
    "customerName"         => "test ",
    "customerContact"      => "customer Contact",
    "customerContactPhone" => "123456789",
    "salesRep"             => "w salesRep",
);

try {
    $soapClient = new SoapClient($url, array(
        'trace' => true, // for debugging, disable in production
        //"connection_timeout" => 1
    ));

    // List types to get an idea how to call methods, since it looks like
    // there are no help pages as in .asmx services
    // var_dump($soapClient->__getTypes());

    $soapClient->saveSalesOrder($data);
} catch (Exception $e) {
    trigger_error("SOAP error: ".$e->getMessage(), E_USER_WARNING);
}

链接:

整体 SmartTurn 服务列表

PHP SoapClient 文档

编辑:根据评论更新示例。

于 2012-10-08T07:25:40.303 回答
0

这是 Halil 的一个很好的回答,真的帮助我弄清楚该怎么做。您需要添加更多数组来创建请求,因为 XML 请求的嵌套值需要放入数组中。此外,还需要填写最少数量的字段,因此您最好查看 API 文档并查看示例请求,然后格式化您的数组以匹配嵌套值。例如:

$url = "https://stdemo.smartturn.com/occam/services/OccamService?wsdl"; //DEMO URL
// $url = "https://app.smartturn.com/occam/services/OccamService?wsdl"; //LIVE URL

$data = array(
"inCredential" => array("UserId" => "secret", "Password" => "secret"),
"inSalesOrders" => array("type" => "EXTERNAL",
                         "date" => "2012-10-20T00:04:34.479Z",
                         "dateDue" => "2012-10-20T00:04:34.479Z",
                         "externalNumber" => "Ext-id-00502",
                         "customerName" => "test ",
                         "customerContact" => "customer Contact",
                         "customerContactPhone" => "123456789",
                         "salesRep" => "w salesRep",
                          ...
                    )
);

try {
$soapClient = new SoapClient($url, array(
    'trace' => true, // for debugging, disable in production
    //"connection_timeout" => 1
));

// List types to get an idea how to call methods, since it looks like
// there are no help pages as in .asmx services
// var_dump($soapClient->__getTypes());

$soapClient->saveSalesOrder($data);
} catch (Exception $e) {
    trigger_error("SOAP error: ".$e->getMessage(), E_USER_WARNING);
}

使用此方法生成 SOAP 信封的唯一问题是,当您使用关联数组时,您只能在每个销售订单请求中发送 1 个项目对象。一旦您的订单中有多个商品,这将不起作用。您可以调查 SoapVar,我最终形成了完整的 XML 文档,然后使用 CURL 发送它。

于 2014-06-24T09:23:08.260 回答