需要帮助构建一个名为 Nusoap 的网络服务
在尝试解决此问题时遇到了重大问题,我很乐意向可以帮助我完成这项工作的人提供 +500 赏金。
基本上,我尝试使用 Nusoap 调用此 Web 服务:
这是我到目前为止所得到的:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我可能没有抓住要点,但您实际上从未将返回的对象分配给
$client
:如果需要,您也可以将
$client
设置为类变量或通过发送参数作为参考。查看数据,我不知道这是否重要,但是您使用
var
作为类变量声明,然后使用private
作为函数。如果您使用 php5,我会远离var
:使用
private
或public
或protected
(以你的班级需要)而不是保持一致性。我怀疑这能解决你的问题,只是需要注意一下。可能的解决方案
好吧,我自己做了一些挖掘,发现了这一点,您需要将添加的实际标头封装在
SOAP:Header
交易中。我测试了下面的内容,它对我有用,所以尝试一下:它没有返回任何错误。是的,这似乎是罪魁祸首。 (请注意,我还实现了上面提到的
$client = $this->setHeaders($client);
。我的最终答案是:
好吧,做了一点挖掘并发现了一些有用的东西。并不是说它是正确的,但它
似乎是我使用链接找到的关键成分。您最初发布的内容: 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
: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 usingprivate
for the function. If you are using php5 I would stay away from thevar
:Use the
private
orpublic
orprotected
(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: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.
It seems the
namespace
andsoapAction
were the key ingredients. I found these using the link you originally posted: https://www.eway.com.au/gateway/ManagedPaymentService/managedCreditCardPayment.asmx?op=QueryCustomerBasically, 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.更新5:
nusoap 实际上使用 SOAP-ENV 包装请求,例如:
在 EWay 的文档中,必须使用soap:Header。我在 nusoap 标题中找不到提及后者。
更新4:
这个链接有一个很好的提示:
Update 5:
nusoap actually wraps the request with
SOAP-ENV
, like: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:
所以这就是:
SoapClient 类没有该方法。相反,您可以创建一个
新的 SoapHeader
。编辑:好吧,深入挖掘:
如果你这样做会发生什么?
So this right here:
The SoapClient class doesn't have that method. Instead, you can create a
new SoapHeader
.Edit: Alright, digging deeper:
What happens if you do that?
我知道这不是问题的完整解决方案,但尽管这个问题已经很老了,但我的发现可能有助于找到具体的解决方案。
我遇到了与您提到的 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 支持人员的一名成员还告诉我,他们在内部重定向方面遇到了问题,他们现在正在解决这个问题正在考虑解决。
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.