如何將PHP SoapClient請求示例轉換為RoR? - How to translate PHP SoapClient request example to RoR? -开发者知识库

如何將PHP SoapClient請求示例轉換為RoR? - How to translate PHP SoapClient request example to RoR? -开发者知识库,第1张

I'd like to use some web service via its API. In documentation I found an example request written with PHP SoapClient. But I am using RoR and I have no PHP experience. Could someone tell me how should I write the same in RoR, or at least translate it to plain HTTP terminology?

我想通過其API使用一些Web服務。在文檔中,我發現了一個用PHP SoapClient編寫的示例請求。但我使用的是RoR而且我沒有PHP經驗。有人可以告訴我如何在RoR中編寫相同的內容,或者至少將其翻譯成純HTTP術語?

<?php
  $soap = new SoapClient(“https://secure.przelewy24.pl/external/wsdl/service.php?wsdl”);
  $test = $soap->TestAccess(“9999”, “anuniquekeyretrievedfromprzelewy24”);
  if ($test)
    echo ‘Access granted’;
  else
    echo ‘Access denied’;
?> 

Edit: particularly I'd like to know what should I do with TestAccess method, because there's no methods in plain HTTP. Should I join this name with URL?

編輯:特別是我想知道我應該怎么做TestAccess方法,因為普通HTTP中沒有方法。我應該用URL加入此名稱嗎?

2 个解决方案

#1


1  

To make your life easier, check out a gem that allows you to simplify SOAP access, like savon.

為了讓您的生活更輕松,請查看一個允許您簡化SOAP訪問的gem,例如savon。

Then the code could be translated as

然后代碼可以翻譯為

# create a client for the service
client = Savon.client(wsdl: 'https://secure.przelewy24.pl/external/wsdl/service.php?wsdl')

This will automatically parse the possible methods to client that are offered in the SOAP API (defined in the WSDL). To list the possible operations, type

這將自動解析SOAP API中提供的客戶端的可能方法(在WSDL中定義)。要列出可能的操作,請鍵入

client.operations

In your case this will list

在你的情況下,這將列出

[:test_access, :trn_refund, :trn_by_session_id, :trn_full_by_session_id, :trn_list_by_date, :trn_list_by_batch, :trn_full_by_batch, :payment_methods, :currency_exchange, :refund_by_id, :trn_register, :trn_internal_register, :check_nip, :company_register, :company_update, :batch_list, :trn_dispatch, :charge_back, :trn_check_funds, :check_merchant_funds, :transfer_merchant_funds, :verify_transaction, :register_transaction, :deny_transaction, :batch_details]

Then to call the method, do the following

然后調用該方法,執行以下操作

response = client.call(:test_access, message: { test_access_in: 9999 })
response = client.call(:test_access, message: { 
   test_access_in: 9999 }
   test_access_out: "anuniquekeyretrievedfromprzelewy24" 
)
response.body
 => {:test_access_response=>{:return=>false}}

this gets a result, but I have no idea what it means.

這得到了結果,但我不知道它意味着什么。

最佳答案:

本文经用户投稿或网站收集转载,如有侵权请联系本站。

发表评论

0条回复