0

我正在尝试执行名为 DoProduct 的 SOAP 请求。此方法正在更新特定产品。我查看了 WSDL ( http://api.istore.pl/#op.idp182160 ),发现我需要一个 Product 对象和会话密钥。

一切都与 PHP 完美配合:

    $product = $soap->__soapCall("getProduct", array("sessionId" => $key, "productId" => $id));
    $result = $soap->__soapCall("doProduct", array("sessionId" => $key, "product" => $product));

我用 Ruby 尝试了相同的方法(首先获取产品,然后将其发回):

    product = client.call(:get_product, message: {:session_id => session_key, :product_id => id})
    response = @@client.call(:do_product, message: {:session_id => session_key, :product =>  product.hash[:envelope][:body][:get_product_response][:return]})

Ruby 版本不工作。我收到一个参数未发送的错误(当然该参数在那里,我已经从第一个响应中检查了哈希):

    HTTPI POST request to api.istore.pl (net_http)
    SOAP response (status 500)
    <?xml version="1.0" encoding="UTF-8"?>
    <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><S
    OAP-ENV:Body><SOAP-ENV:Fault><faultcode>ERR_EMPTY_PRODUCT_TAX</faultcode><faults
    tring></faultstring></SOAP-ENV:Fault></SOAP-ENV:Body></SOAP-ENV:Envelope>

    Savon::SOAPFault: (ERR_EMPTY_PRODUCT_TAX)
    from F:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/savon-2.1.0/lib/savon/response.rb:70:in `raise_soap_and_http_errors!'
    from F:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/savon-2.1.0/lib/savon/response.rb:13:in `initialize'
    from F:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/savon-2.1.0/lib/savon/operation.rb:52:in `new'
    from F:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/savon-2.1.0/lib/savon/operation.rb:52:in `call'
    from F:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/savon-2.1.0/lib/savon/client.rb:38:in `call'
    from C:/Users/Arti/Documents/adgally/v1/app/models/istore.rb:45:in `update_product'
    from (irb):60
    from F:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.6/lib/rails/commands/console.rb:47:in `start'
    from F:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.6/lib/rails/commands/console.rb:8:in `start'
    from F:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.6/lib/rails/commands.rb:41:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'

@EDIT PHP 响应(vardump):

object(stdClass)[2]
  public 'Id' => int 18028717
  public 'PropertiesIds' => 
    array (size=0)
      empty
  public 'ImagesIds' => 
    array (size=1)
      0 => int 22573396
  public 'Currency' => 
    object(stdClass)[3]
      public 'Id' => int 1
      public 'Symbol' => string 'PLN' (length=3)
      public 'Round' => boolean false
      public 'Active' => boolean true
      public 'Rate' => float 1
  public 'Tax' => 
    object(stdClass)[4]
      public 'Id' => int 23
      public 'Name' => string '23%' (length=3)
      public 'Rate' => float 23
  public 'Symbol' => string ' ' (length=1)
  public 'Promotion' => boolean false
  public 'Wholesale' => boolean false
  public 'New' => boolean false
  public 'DeliveryTimeLength' => int 0
  public 'DeliveryTimeLengthPeriod' => string 'D' (length=1)
  public 'Producer' => null
  public 'PKWiU' => null
  public 'Active' => boolean true
  public 'Netto' => float 11.38
  public 'Brutto' => float 14
  public 'PromotionNetto' => float 0
  public 'PromotionBrutto' => float 0
  public 'WholesaleNetto' => float 0
  public 'WholesaleBrutto' => float 0
  public 'FirstPage' => int 0
  public 'Sequence' => int 18028717
  public 'Unit' => 
    object(stdClass)[5]
      public 'Id' => int 1
      public 'Symbol' => string 'szt.' (length=4)
  public 'PostSize' => string 'A' (length=1)
  public 'SortProperty' => string 'N' (length=1)
  public 'MainCategory' => 
    object(stdClass)[6]
      public 'Id' => int 34
      public 'Name' => string 'Odzież, Obuwie, Dodatki' (length=24)
  public 'Names' => 
    array (size=1)
      0 => 
        object(stdClass)[7]
          public 'Symbol' => string 'pl' (length=2)
          public 'Name' => string 'Bluzka testowa 2' (length=16)
  public 'Description' => 
    array (size=1)
      0 => 
        object(stdClass)[8]
          public 'Symbol' => string 'pl' (length=2)
          public 'Description' => string 'asdsad' (length=6)
  public 'HTMLDescription' => 
    array (size=1)
      0 => 
        object(stdClass)[9]
          public 'Symbol' => string 'pl' (length=2)
          public 'Description' => string 'asdasdas' (length=8)
  public 'MetaKeywords' => 
    array (size=1)
      0 => 
        object(stdClass)[10]
          public 'Symbol' => string 'pl' (length=2)
          public 'Description' => string 'bluzka, jesień, fajna' (length=22)
  public 'CategoriesIds' => 
    array (size=1)
      0 => int 1695922
  public 'BindingProducts' => 
    array (size=0)
      empty
  public 'Availability' => string 'A' (length=1)
  public 'Quality' => string 'N' (length=1)
  public 'Variants' => 
    array (size=1)
      0 => 
        object(stdClass)[11]
          public 'ShopProductPropertyValueIds' => 
            array (size=0)
              ...
          public 'Quantity' => float 1
          public 'WarehouseId' => int 20666112
          public 'Available' => boolean true
  public 'Weight' => float 0
  public 'Blocked' => boolean false
  public 'HideExternalOpinions' => boolean false
  public 'Width' => int 0
  public 'Height' => int 0
  public 'Deep' => int 0
  public 'InpostEnabled' => boolean false
  public 'Available' => boolean true
  public 'Ean' => null

Ruby Savon response.to_hash 对象(抱歉格式化,但我不知道如何从控制台正确格式化): http: //pastie.org/7065887

另外 ruby​​ response.to_json (格式更好):

{
   "get_product_response":{
      "return":{
         "id":"18028717",
         "properties_ids":{
            "@soap_enc:array_type":"xsd:int[0]",
            "@xsi:type":"ns1:ArrayOfint"
         },
         "images_ids":{
            "item":"22573396",
            "@soap_enc:array_type":"xsd:int[1]",
            "@xsi:type":"ns1:ArrayOfint"
         },
         "currency":{
            "id":"1",
            "symbol":"PLN",
            "round":false,
            "active":true,
            "rate":"1",
            "@xsi:type":"ns1:Currency"
         },
         "tax":{
            "id":"23",
            "name":"23%",
            "rate":"23",
            "@xsi:type":"ns1:Tax"
         },
         "symbol":{
            "@xsi:type":"xsd:string"
         },
         "promotion":false,
         "wholesale":false,
         "new":false,
         "delivery_time_length":"0",
         "delivery_time_length_period":"D",
         "producer":null,
         "pk_wi_u":null,
         "active":true,
         "netto":"11.38",
         "brutto":"14",
         "promotion_netto":"0",
         "promotion_brutto":"0",
         "wholesale_netto":"0",
         "wholesale_brutto":"0",
         "first_page":"0",
         "sequence":"18028717",
         "unit":{
            "id":"1",
            "symbol":"szt.",
            "@xsi:type":"ns1:Unit"
         },
         "post_size":"A",
         "sort_property":"N",
         "main_category":{
            "id":"34",
            "name":"Odzieu017c, Obuwie, Dodatki",
            "@xsi:type":"ns1:MainCategory"
         },
         "names":{
            "item":{
               "symbol":"pl",
               "name":"Bluzka testowa 2",
               "@xsi:type":"ns1:TranslationName"
            },
            "@soap_enc:array_type":"ns1:TranslationName[1]",
            "@xsi:type":"ns1:ArrayOfTranslationName"
         },
         "description":{
            "item":{
               "symbol":"pl",
               "description":"asdsad",
               "@xsi:type":"ns1:TranslationDescription"
            },
            "@soap_enc:array_type":"ns1:TranslationDescription[1]",
            "@xsi:type":"ns1:ArrayOfTranslationDescription"
         },
         "html_description":{
            "item":{
               "symbol":"pl",
               "description":"asdasdas",
               "@xsi:type":"ns1:TranslationDescription"
            },
            "@soap_enc:array_type":"ns1:TranslationDescription[1]",
            "@xsi:type":"ns1:ArrayOfTranslationDescription"
         },
         "meta_keywords":{
            "item":{
               "symbol":"pl",
               "description":"bluzka, jesieu0144, fajna",
               "@xsi:type":"ns1:TranslationDescription"
            },
            "@soap_enc:array_type":"ns1:TranslationDescription[1]",
            "@xsi:type":"ns1:ArrayOfTranslationDescription"
         },
         "categories_ids":{
            "item":"1695922",
            "@soap_enc:array_type":"xsd:int[1]",
            "@xsi:type":"ns1:ArrayOfint"
         },
         "binding_products":{
            "@soap_enc:array_type":"xsd:int[0]",
            "@xsi:type":"ns1:ArrayOfint"
         },
         "availability":"A",
         "quality":"N",
         "variants":{
            "item":{
               "shop_product_property_value_ids":{
                  "@soap_enc:array_type":"xsd:int[0]",
                  "@xsi:type":"ns1:ArrayOfint"
               },
               "quantity":"1",
               "warehouse_id":"20666112",
               "available":true,
               "@xsi:type":"ns1:ProductVariant"
            },
            "@soap_enc:array_type":"ns1:ProductVariant[1]",
            "@xsi:type":"ns1:ArrayOfProductVariant"
         },
         "weight":"0",
         "blocked":false,
         "hide_external_opinions":false,
         "width":"0",
         "height":"0",
         "deep":"0",
         "inpost_enabled":false,
         "available":true,
         "ean":null,
         "@xsi:type":"ns1:Product"
      }
   }
}

有人可以给我任何提示吗?

4

1 回答 1

0

根据 SOAP 响应,您实际上缺少 SOAP 服务所期望的参数。

我注意到在 PHP 版本中您只是发送了整个产品对象,但在 Ruby 版本中您正在挖掘响应哈希。

您可以检查两个版本中的“产品”并在此处发布回复吗?

于 2013-03-21T20:16:40.933 回答