2012-10-08 2 views
1

SOAP를 처음 사용합니다. 내 응용 프로그램을 SmartTurn webservice API (자사의 발명 관리 회사)에 통합하려고합니다. 그것들은 API 작업을위한 SOAP와 wsdl입니다. 나는 내가 PHP에서 이것을 할 수있는 방법을 모른다는 것을 비누에 익숙하지 않다. 여기에 내가 사용하고자하는 XML이있다.통합 SmartTurn webservice API with SOAP, XML in PHP

<?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">[email protected]</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에 있다고 할 수있다.

미리 감사드립니다.

답변

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); 
} 

링크 :

Overall SmartTurn service listing

PHP SoapClient documentation

편집 : 코멘트에 따라 업데이트 예.

+0

덕분에 ... 그래서 난 당신의 코드 $ 데이터에이를 추가해야 = 배열 ​​("사용자 아이디"= > "[email protected]", "비밀 번호"=> "비밀", "유형"=> "외부", "날짜"=> "2012-10-20T00 : 04 : 34.479Z" "dateDue"=> "2012-10-20T00 : 04 : 34.479Z", "externalNumber"=> "Ext-id-00502", "customerName"=> "test", "customerContact"=> 고객 연락처 ", "customerContactPhone "=>"145874562 ", "salesRep "=>"w salesRep ", \t \t \t \t \t \t); –

+0

@SheikhJames에서'$ soapClient-> saveSalesOrder ($ data);를 시도해 보셨습니까? + 귀하의 의견을 바탕으로 업데이트 된 예제 코드. –

0

이것은 할릴의 훌륭한 답이며 무엇을해야 할지를 결정하는 데 정말로 도움이되었습니다. 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로 보낼 수있었습니다. SOAP 확장은 이미 내가 위의 XML에서 언급으로 saveSalesOrder 작업을 수행 할 .so를 설치 당신이 PHP는 응답을

+0

원래 게시물 : http://stackoverflow.com/a/12777080/1121121 – hutchbat