dongwu4834 2018-05-15 11:17
浏览 77
已采纳

如何将PHP SoapClient请求示例转换为RoR?

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?

<?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?

  • 写回答

2条回答 默认 最新

  • dongsu4345 2018-05-15 13:31
    关注

    To make your life easier, check out a gem that allows you to simplify SOAP access, like 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

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 有两个非常“自以为是”烦人的问题急期待大家解决!
  • ¥30 STM32 INMP441无法读取数据
  • ¥100 求汇川机器人IRCB300控制器和示教器同版本升级固件文件升级包
  • ¥15 用visualstudio2022创建vue项目后无法启动
  • ¥15 x趋于0时tanx-sinx极限可以拆开算吗
  • ¥15 任意一个散点图自己下载其js脚本文件并做成独立的案例页面,不要作在线的,要离线状态。
  • ¥15 各位 帮我看看如何写代码,打出来的图形要和如下图呈现的一样,急
  • ¥30 c#打开word开启修订并实时显示批注
  • ¥15 如何解决ldsc的这条报错/index error
  • ¥15 VS2022+WDK驱动开发环境