大家早上好,
我在这个网站上搜索了一个有用的响应,用于在PHP中集成SOAP请求,但我没有找到解决我问题的任何内容。
我是SOAP的新手,无法弄清楚为什么我会收到以下错误消息作为回复:
object(stdClass)#3(1){[" CU_Check_BalanceResult"] => object(stdClass)#4(1){[" error"] =>字符串(20)"错误的身份验证" }}
这是我的PHP脚本:
<?php
/* Initialize webservice with your WSDL */
$client = new SoapClient("https://loyalty.brain-behind.com/CU_WebAPI.asmx?wsdl");
class CU_Check_Balance{
public $provider,
$password,
$CardID,
$TerminalID;
}
$parameters = new CU_Check_Balance();
$parameters->provider = "string";
$parameters->password = "string";
$parameters->CardID = "string";
$parameters->TerminalID = "string";
$response = $client->CU_Check_Balance($parameters);
var_dump($response);
?>
可在此处找到相应的WSDL:
http://loyalty.brain-behind.com/CU_WebAPI.asmx?wsdl
我也尝试在JS中实现它,但这也没有用。
我还安装了SOAP UI,用这个wsdl做了一个测试项目,它运行良好。
这是我使用SOAP UI获得的示例请求:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:loy="https://loyalty.brain-behind.com">
<soapenv:Header>
<loy:AuthSoapHd3>
<!--Optional:-->
<!--type: string-->
<!--Optional:-->
<!--type: string-->
<loy:provider>string</loy:provider><loy:password>string</loy:password>
</loy:AuthSoapHd3>
</soapenv:Header>
<soapenv:Body>
<loy:CU_Check_Balance>
<!--Optional:-->
<!--type: string-->
<!--Optional:-->
<!--type: string-->
<loy:CardID>string</loy:CardID><loy:TerminalID>string</loy:TerminalID>
</loy:CU_Check_Balance>
</soapenv:Body>
</soapenv:Envelope>
请有人帮助我在php中使用这个东西。
答案 0 :(得分:0)
我也一直在解决这个问题,希望这可以帮助,这是brain-behind.com的可行解决方案。两种变体 - 测试和生产凭证。
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
date_default_timezone_set('Europe/Prague');
//*
$wsdl = "https://loyalty.brain-behind.com/CU_WebAPI.asmx?wsdl";
/*/
$wsdl = "https://testo.brain-behind.com/CU_WebAPI.asmx?wsdl"; //for your testing credentials, change only this $wsdl address, not $location
//*/
$location = "https://loyalty.brain-behind.com";
$provider = "TESTBB|1111";
$password = "abcdefghijkl";
$cardId = '111111111111111';
$terminalId = 'AA111111';
$login = new stdClass();
$login->provider = $provider;
$login->password = $password;
$params = new stdClass();
$params->CardID = $cardId;
$params->TerminalID = $terminalId;
$dump = array("trace" => 1, "exceptions" => 0);
///////////////////////////////////////////////////////////////////////////////////////////
//*
$soap = new SoapClient($wsdl);
/*/
$soap = new SoapClient($wsdl, $dump); // trace ON, then print LastRequest, LastResponse, LastRequestHeaders
//*/
//var_dump($soap->__getFunctions());
//var_dump($soap->__getTypes());
$header = new SoapHeader($location, 'AuthSoapHd3', $login);
$soap->__setSoapHeaders($header);
try {
// check balance
$response = $soap->CU_Check_Balance($params);
var_dump($response);
//////////////////////////////////////
$count = 2;
$ticketPrice = 28;
$cashback = 2; //cashback per ticket
$params->PurchaseDate = date('c'); //UTF format
$params->PurchaseAmount = $count * $ticketPrice; // in Euros
$params->BonusAmount = $count * $cashback * 100; // in Eurocents
$params->Encryption='';
// add kredit to account
$response = $soap->CU_Add_Bonus($params);
var_dump($response);
} catch (Exception $exc) {
echo 'Exception:<br>';
print_r($exc->getTrace());
}
echo '<br><br>LastRequest:';
var_dump($soap->__getLastRequest());
echo '<br><br>LastResponse:';
var_dump($soap->__getLastResponse());
echo '<br><br>LastHeaders:';
var_dump($soap->__getLastRequestHeaders());