需要帮助构建一个名为 Nusoap 的网络服务

发布于 2024-10-25 15:17:08 字数 1862 浏览 6 评论 0原文

在尝试解决此问题时遇到了重大问题,我很乐意向可以帮助我完成这项工作的人提供 +500 赏金。

基本上,我尝试使用 Nusoap 调用此 Web 服务:

https ://www.eway.com.au/gateway/ManagedPaymentService/managementCreditCardPayment.asmx?op=QueryCustomer

这是我到目前为止所得到的:

class Eway
{
    var $username = '[email protected]';
    var $pw = 'test123';
    var $customerId = '87654321';
    private function setHeaders($client)
    {
        $headers = <<<EOT
<eWAYHeader xmlns="http://www.eway.com.au/gateway/managedPayment">
      <eWAYCustomerID>$this->customerId</eWAYCustomerID>
      <Username>$this->username</Username>
      <Password>$this->pw</Password>
    </eWAYHeader> 
EOT;
       $client->setHeaders($headers);
       return $client;
    }

     function getCustomer($ewayId = 9876543211000)
     {
        $url = 'https://www.eway.com.au/gateway/ManagedPaymentService/managedCreditCardPayment.asmx?WSDL';  
        $client = new Nusoap_client($url, true);
        $this->setHeaders($client);

        $args['QueryCustomer'] = array('managedCustomerID'=>$ewayId);

        $result = $client->call('QueryCustomer', $args);
        print_r($result);
    }
}

当我运行此代码并执行 $eway-> 时;getCustomer() 我收到以下错误:

Array
(
    [faultcode] => soap:Client
    [faultstring] => eWayCustomerID, Username and Password needs to be specified in the soap header.
)

我做错了什么?

如果您可以修复我的类并为我提供工作代码,该代码能够使用测试客户 ID 执行 QueryCustomer 方法并返回其信息,我将很高兴为您提供 +500 代表和我永远的感激之情。显然,我需要 48 小时才能开始赏金,但我保证我会这么做。

Been having major issues trying to solve this issue, I'll be happy to give a +500 bounty to someone who can help me get this work.

Basically, I'm trying to call this web service using Nusoap:

https://www.eway.com.au/gateway/ManagedPaymentService/managedCreditCardPayment.asmx?op=QueryCustomer

This is what I've got so far:

class Eway
{
    var $username = '[email protected]';
    var $pw = 'test123';
    var $customerId = '87654321';
    private function setHeaders($client)
    {
        $headers = <<<EOT
<eWAYHeader xmlns="http://www.eway.com.au/gateway/managedPayment">
      <eWAYCustomerID>$this->customerId</eWAYCustomerID>
      <Username>$this->username</Username>
      <Password>$this->pw</Password>
    </eWAYHeader> 
EOT;
       $client->setHeaders($headers);
       return $client;
    }

     function getCustomer($ewayId = 9876543211000)
     {
        $url = 'https://www.eway.com.au/gateway/ManagedPaymentService/managedCreditCardPayment.asmx?WSDL';  
        $client = new Nusoap_client($url, true);
        $this->setHeaders($client);

        $args['QueryCustomer'] = array('managedCustomerID'=>$ewayId);

        $result = $client->call('QueryCustomer', $args);
        print_r($result);
    }
}

When I run this code and do $eway->getCustomer() I get the following error:

Array
(
    [faultcode] => soap:Client
    [faultstring] => eWayCustomerID, Username and Password needs to be specified in the soap header.
)

What am I doing wrong?

If you could fix my class and give me working code which is able to do the QueryCustomer method using the test customer id and return its info, I'll be glad to give you +500 rep and my eternal gratitude. Obviously it'll be 48 hours before I can start the bounty, but I promise that I will do it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

分開簡單 2024-11-01 15:17:09

我可能没有抓住要点,但您实际上从未将返回的对象分配给 $client

function getCustomer($ewayId = 9876543211000)
 {
    $url = 'https://www.eway.com.au/gateway/ManagedPaymentService/managedCreditCardPayment.asmx?WSDL';  
    $client = new Nusoap_client($url, true);
    $client = $this->setHeaders($client);

    $args['QueryCustomer'] = array('managedCustomerID'=>$ewayId);

    $result = $client->call('QueryCustomer', $args);
    print_r($result);
}

如果需要,您也可以将 $client 设置为类变量或通过发送参数作为参考。


查看数据,我不知道这是否重要,但是您使用 var 作为类变量声明,然后使用 private 作为函数。如果您使用 php5,我会远离 var

private $username = '[email protected]';
private $pw = 'test123';
private $customerId = '87654321';

使用 privatepublicprotected (以你的班级需要)而不是保持一致性。我怀疑这能解决你的问题,只是需要注意一下。


可能的解决方案

好吧,我自己做了一些挖掘,发现了这一点,您需要将添加的实际标头封装在 SOAP:Header 交易中。我测试了下面的内容,它对我有用,所以尝试一下:

private function setHeaders($client)
{
    $headers = <<<EOT
<SOAP:Envelope xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/" >
<SOAP:Header>
<eWAYHeader xmlns="http://www.eway.com.au/gateway/managedPayment">
  <eWAYCustomerID>$this->customerId</eWAYCustomerID>
  <Username>$this->username</Username>
  <Password>$this->pw</Password>
</eWAYHeader>
</SOAP:Header>
EOT;
   $client->setHeaders($headers);
   return $client;
}

它没有返回任何错误。是的,这似乎是罪魁祸首。 (请注意,我还实现了上面提到的 $client = $this->setHeaders($client);


我的最终答案是:

好吧,做了一点挖掘并发现了一些有用的东西。并不是说它是正确的,但它

private function setHeaders($client)
{
    $headers = <<<EOT
<eWAYHeader xmlns="https://www.eway.com.au/gateway/managedpayment">
  <eWAYCustomerID>$this->customerId</eWAYCustomerID>
  <Username>$this->username</Username>
  <Password>$this->pw</Password>
</eWAYHeader>
EOT;
   $client->setHeaders($headers);
   return $client;
}

 function getCustomer($ewayId = 123456789012)
 {
    $url = 'https://www.eway.com.au/gateway/ManagedPaymentService/managedCreditCardPayment.asmx?WSDL';
    $client = new nusoap_client($url);
    $client = $this->setHeaders($client);

    $args['QueryCustomer'] = array('managedCustomerID'=>$ewayId);

    $result = $client->call('QueryCustomer', $args, $namespace='https://www.eway.com.au/gateway/managedpayment', $soapAction='https://www.eway.com.au/gateway/managedpayment/QueryCustomer');

    print_r($result);

    //echo "\n{$client->request}\n"; // This echos out the response you are sending for debugging.
}

似乎是我使用链接找到的关键成分。您最初发布的内容: https://www.eway.com.au /gateway/ManagedPaymentService/managedCreditCardPayment.asmx?op=QueryCustomer

基本上,我只是查看该响应,然后进行一些搜索以找出soapAction,然后只是对其进行修改,直到发送的请求与页面匹配为止它返回失败的登录,但是,这通常意味着某些东西正在工作,并且可能是由于测试数据,但这为您提供了一个基线

。 是未来方便的调试工具。

I could be missing the point, but you never actually assign the returned object to $client:

function getCustomer($ewayId = 9876543211000)
 {
    $url = 'https://www.eway.com.au/gateway/ManagedPaymentService/managedCreditCardPayment.asmx?WSDL';  
    $client = new Nusoap_client($url, true);
    $client = $this->setHeaders($client);

    $args['QueryCustomer'] = array('managedCustomerID'=>$ewayId);

    $result = $client->call('QueryCustomer', $args);
    print_r($result);
}

You could also set $client as a class variable if desired or by sending the parameter as a reference.


Looking at the data, I do not know if this matters, but you are using var for your class variable declarations and then using private for the function. If you are using php5 I would stay away from the var:

private $username = '[email protected]';
private $pw = 'test123';
private $customerId = '87654321';

Use the private or public or protected (whichever your class requires) instead to keep consistency. I doubt this will solve your problem, just something to be conscious about.


Possible Solution

Ok, doing some digging of my own, figured this out, you need to encase the actual header you add in a SOAP:Header deal. I tested the below and it was working for me, so give it a try:

private function setHeaders($client)
{
    $headers = <<<EOT
<SOAP:Envelope xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/" >
<SOAP:Header>
<eWAYHeader xmlns="http://www.eway.com.au/gateway/managedPayment">
  <eWAYCustomerID>$this->customerId</eWAYCustomerID>
  <Username>$this->username</Username>
  <Password>$this->pw</Password>
</eWAYHeader>
</SOAP:Header>
EOT;
   $client->setHeaders($headers);
   return $client;
}

It did not return any errors. So yea, it seems that is the likely culprit. (Note I also implemented the $client = $this->setHeaders($client); I mentioned above as well.


And my Final Answer is:

Alright did a bit of digging and found something that works. Not saying it is right, but yea it works.

private function setHeaders($client)
{
    $headers = <<<EOT
<eWAYHeader xmlns="https://www.eway.com.au/gateway/managedpayment">
  <eWAYCustomerID>$this->customerId</eWAYCustomerID>
  <Username>$this->username</Username>
  <Password>$this->pw</Password>
</eWAYHeader>
EOT;
   $client->setHeaders($headers);
   return $client;
}

 function getCustomer($ewayId = 123456789012)
 {
    $url = 'https://www.eway.com.au/gateway/ManagedPaymentService/managedCreditCardPayment.asmx?WSDL';
    $client = new nusoap_client($url);
    $client = $this->setHeaders($client);

    $args['QueryCustomer'] = array('managedCustomerID'=>$ewayId);

    $result = $client->call('QueryCustomer', $args, $namespace='https://www.eway.com.au/gateway/managedpayment', $soapAction='https://www.eway.com.au/gateway/managedpayment/QueryCustomer');

    print_r($result);

    //echo "\n{$client->request}\n"; // This echos out the response you are sending for debugging.
}

It seems the namespace and soapAction were the key ingredients. I found these using the link you originally posted: https://www.eway.com.au/gateway/ManagedPaymentService/managedCreditCardPayment.asmx?op=QueryCustomer

Basically, I just looked at that response, and then did some searching to figure out the soapAction, and then just messed with it until the request being sent matched the page you posted. It returns a failed login, but yea. That generally means something is working, and is probably due to the test data. But that gives you a baseline to go off of.

And the $client->request is a handy debugging tool for the future.

任谁 2024-11-01 15:17:09

更新5:
nusoap 实际上使用 SOAP-ENV 包装请求,例如:

<SOAP-ENV:Header><eWAYHeader xmlns="https://www.eway.com.au/gateway/managedpayment"> 
      <eWayCustomerID>87654321</eWayCustomerID> 
      <Username>[email protected]</Username> 
      <Password>test123</Password> 
</eWAYHeader></SOAP-ENV:Header>

在 EWay 的文档中,必须使用soap:Header。我在 nusoap 标题中找不到提及后者。

更新4:
这个链接有一个很好的提示:

明白了。这是一个案例问题,但不是
那里,他们的 PDF 不正确。

对于任何在
未来,PDF 说:

<代码>
应该是:

<代码>

Update 5:
nusoap actually wraps the request with SOAP-ENV, like:

<SOAP-ENV:Header><eWAYHeader xmlns="https://www.eway.com.au/gateway/managedpayment"> 
      <eWayCustomerID>87654321</eWayCustomerID> 
      <Username>[email protected]</Username> 
      <Password>test123</Password> 
</eWAYHeader></SOAP-ENV:Header>

While in the docs for EWay soap:Header must be used. I couldn't find a mention of the latter in nusoap headers.

Update 4:
This link has a good tip:

Got it. It was a case issue but not
there, and their PDF is incorrect.

For anyone that gets this in the
future, the PDF says:

<eWAYHeader
xmlns="http://www.eway.com.au/gateway/managedPayment">

It should be:

<eWAYHeader
xmlns="https://www.eway.com.au/gateway/managedpayment">

揽月 2024-11-01 15:17:09

所以这就是:

$client->setHeaders($headers);

SoapClient 类没有该方法。相反,您可以创建一个新的 SoapHeader

private function setHeaders($client)
{
    $headers = new stdClass;
    $headers->eWAYCustomerID = $this->customerId;
    $headers->Username = $this->username;
    $headers->Password = $this->pw;


    $ewayHeader = new SoapHeader(
        "http://www.eway.com.au/gateway/managedPayment",
        "eWAYHeader",
        $headers
    );

   $client->__setSoapHeaders(array($ewayHeader));
   return $client;
}

编辑:好吧,深入挖掘:

private function prepHeaders()
{
    return array(
        'eWAYHeader' => array(
            'eWAYCustomerID' => $this->customerId,
            'Username' => $this->username,
            'Password' => $this->pw
        )
    );
}

 function getCustomer($ewayId = 9876543211000)
 {
    $url = 'https://www.eway.com.au/gateway/ManagedPaymentService/managedCreditCardPayment.asmx?WSDL';  
    $client = new nusoap_client($url);

    $args['QueryCustomer'] = array('managedCustomerID'=>$ewayId);

    $result = $client->call('QueryCustomer', $args, null, null, $this->prepHeaders());
    print_r($result);
}

如果你这样做会发生什么?

So this right here:

$client->setHeaders($headers);

The SoapClient class doesn't have that method. Instead, you can create a new SoapHeader.

private function setHeaders($client)
{
    $headers = new stdClass;
    $headers->eWAYCustomerID = $this->customerId;
    $headers->Username = $this->username;
    $headers->Password = $this->pw;


    $ewayHeader = new SoapHeader(
        "http://www.eway.com.au/gateway/managedPayment",
        "eWAYHeader",
        $headers
    );

   $client->__setSoapHeaders(array($ewayHeader));
   return $client;
}

Edit: Alright, digging deeper:

private function prepHeaders()
{
    return array(
        'eWAYHeader' => array(
            'eWAYCustomerID' => $this->customerId,
            'Username' => $this->username,
            'Password' => $this->pw
        )
    );
}

 function getCustomer($ewayId = 9876543211000)
 {
    $url = 'https://www.eway.com.au/gateway/ManagedPaymentService/managedCreditCardPayment.asmx?WSDL';  
    $client = new nusoap_client($url);

    $args['QueryCustomer'] = array('managedCustomerID'=>$ewayId);

    $result = $client->call('QueryCustomer', $args, null, null, $this->prepHeaders());
    print_r($result);
}

What happens if you do that?

莳間冲淡了誓言ζ 2024-11-01 15:17:09

我知道这不是问题的完整解决方案,但尽管这个问题已经很老了,但我的发现可能有助于找到具体的解决方案。

我遇到了与您提到的 HTTP“SOAPAction”标头相关的类似错误。 (但是,我正在处理与您不同的 eWay API。我正在处理“Rapid API”,该 API 上周从“Merchant Hosted Payments”重命名为“Merchant Hosted Payments”,这也是我的脚本失败的部分原因工作)。

言归正传,我发现如果您不指定 HTTP“SOAPAction”标头,eWay 将返回一个 SoapFault,并显示以下错误消息。

“System.Web.Services.Protocols.SoapException:如果没有有效的操作参数,则无法处理请求。请提供有效的肥皂操作。”

如果添加 HTTP“SOAPAction”标头,无论将其设置为什么,都会收到错误。

“System.Web.Services.Protocols.SoapException:服务器无法识别 HTTP 标头 SOAPAction 的值:XXX”

eWay 支持人员的一名成员还告诉我,他们在内部重定向方面遇到了问题,他们现在正在解决这个问题正在考虑解决。

<ME> (2012-05-25 02:50:18)
I had an idea of what it could be. What is the "SOAPAction" HTTP header supposed to be set to?

<ME> (2012-05-25 02:52:05)
I couldn't find it in the documentation.

<EWAY_SUPPORT_STAFF> (2012-05-25 02:53:38)
The only thing that is required typically is the endpoint which is https://au.ewaypayments.com/hotpotato/soap.asmx and the <CreateAccessCode xmlns="https://au.ewaypayments.com/hotpotato/">

<EWAY_SUPPORT_STAFF> (2012-05-25 02:54:10)
In my tests it is working but what is happening is that requests are being redirected to the old URL which does not accept the CreateAccessCode method

<ME> (2012-05-25 02:56:58)
You did say that.

<ME> (2012-05-25 02:57:13)
So is this bug happening in the production environment?

<EWAY_SUPPORT_STAFF> (2012-05-25 02:57:57)
Yes it appears so. I have escalated this to Development and attached our last chat transcript and my own test results. They are looking at it now.

I know this is not a full solution to the issue, but although this question is quite old, my findings may help lead to a concrete resolution.

I've been experiencing a similar error in relation to your mention of the HTTP "SOAPAction" header. (I am, however, dealing with a different eWay API than you. I'm dealing with the "Rapid API", which last week was renamed to from "Merchant Hosted Payments", which was part of the reason why my script wasn't working).

To return to the point, I found that if you don't specify the HTTP "SOAPAction" header, eWay returns a SoapFault with the following error message.

"System.Web.Services.Protocols.SoapException: Unable to handle request without a valid action parameter. Please supply a valid soap action."

If you add the HTTP "SOAPAction" header, you get an error no matter what you set it to.

"System.Web.Services.Protocols.SoapException: Server did not recognize the value of HTTP Header SOAPAction: XXX"

I'm also told by a member of eWay's support staff that they have an issues with an internal redirect, which they are now looking into resolving.

<ME> (2012-05-25 02:50:18)
I had an idea of what it could be. What is the "SOAPAction" HTTP header supposed to be set to?

<ME> (2012-05-25 02:52:05)
I couldn't find it in the documentation.

<EWAY_SUPPORT_STAFF> (2012-05-25 02:53:38)
The only thing that is required typically is the endpoint which is https://au.ewaypayments.com/hotpotato/soap.asmx and the <CreateAccessCode xmlns="https://au.ewaypayments.com/hotpotato/">

<EWAY_SUPPORT_STAFF> (2012-05-25 02:54:10)
In my tests it is working but what is happening is that requests are being redirected to the old URL which does not accept the CreateAccessCode method

<ME> (2012-05-25 02:56:58)
You did say that.

<ME> (2012-05-25 02:57:13)
So is this bug happening in the production environment?

<EWAY_SUPPORT_STAFF> (2012-05-25 02:57:57)
Yes it appears so. I have escalated this to Development and attached our last chat transcript and my own test results. They are looking at it now.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文