微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何调试需要基本身份验证的php nusoap调用?

我正在尝试重新编写一个Drupal模块,该模块落后于它所连接的网关的API.

我认为导致问题的代码的剥离版本如下:

$namespace = ($this->testing) ? 'https://api.sandBox.ewaypayments.com/' : 'https://api.ewaypayments.com/';
$endpoint = $this->url;
$httpUsername = $this->user_name;
$httpPassword = $this->password;

$client = new nusoap_client($endpoint, TRUE);
$client->setCredentials($httpUsername, $httpPassword, 'basic');
$client->response_timeout = 50;
$result = $client->call($operation, array('request' => $params), $namespace);

$result一直是假的.如果我把这样的东西放到我的代码中,它也会一直返回空:

$error = $client->getError(); 
watchdog('connection_message', $error);

我有点超出我的深度,在我的Apache日志或Drupal看门狗中没有任何错误消息我看不到前进的方向.

解决方法:

1.如果PHP错误报告尚未打开,请将其打开.

在本地开发时,请检查PHP.ini文件中的error_reporting,display_errors设置是否分别设置为E_ALL和On.您还可以在PHP脚本的开头添加这些指令,以便在运行时设置它们:

error_reporting(E_ALL);
ini_set('display_errors', 'On');

2.像这样捕获NuSOAP错误

$result = $client->call($operation, array('request' => $params), $namespace);
if ($client->fault) {
    echo 'Error: ';
    print_r($result);
} else {
    // check result
    $err_msg = $client->getError();
    if ($err_msg) {
        // Print error msg
        echo 'Error: '.$err_msg;
    } else {
        // Print result
        echo 'Result: ';
        print_r($result);
    }
}

3.确认您使用的是正确的API参数和端点:

eWAY API reference开始,您的终端是:

https://api.ewaypayments.com/soap.asmx (production)
https://api.sandBox.ewaypayments.com/soap.asmx (sandBox)

4.类似的eWAY API项目,您可以进行逆向工程:

> Commerce eWAY for Drupal(上一版本是2014年3月)
> eWAY-RapidAPI(使用JSON和cURL)
> eWay-PHP-API(使用XML和cURL)
> eWay Payment Gateway(使用SOAPClient)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐