我已经搜索了所有关于通过PHP与复杂WSDL交流的SO,SU和论坛,没有运气,由于缺乏知识和有帮助的手,我几乎放弃了。
但我找到了一个开源服务 - http://www.stccorp.net/ewsdl2php/wsdl2php.php
它生成了以下代码。
<?php
class Authenticate{
var $clientId;//string
var $username;//string
var $password;//string
}
class AuthenticateResponse{
var $AuthenticateResult;//IntegrationResponse
}
class IntegrationResponse{
var $ResponseId;//int
var $TotalCount;//int
var $Detail;//string
var $Statuses;//ArrayOfIntegrationStatusResponse
var $ImportingQueueId;//int
var $SalesOrdersToDespatchIds;//ArrayOfInt
}
class ArrayOfIntegrationStatusResponse{
var $IntegrationStatusResponse;//IntegrationStatusResponse
}
class IntegrationStatusResponse{
var $Reference;//string
var $Status;//IntegrationResponseStatuses
var $LineNo;//int
var $Details;//string
}
class ArrayOfInt{
var $int;//int
}
class GetData{
var $getRequest;//GetRequest
}
class GetRequest{
var $TemplateName;//string
var $PageNo;//int
var $ItemsPerPage;//int
var $SearchClause;//string
}
class GetDataResponse{
var $GetDataResult;//IntegrationResponse
}
class UserSessionCredentials{
var $UserId;//int
var $ClientId;//string
var $SessionId;//string
}
class GetSystemSettings{
}
class GetSystemSettingsResponse{
var $GetSystemSettingsResult;//IntegrationResponse
}
class GetReportData{
var $getReportRequest;//GetReportRequest
}
class GetReportRequest{
var $FilterClause;//string
var $OrderBy;//string
var $Columns;//string
}
class GetReportDataResponse{
var $GetReportDataResult;//IntegrationResponse
}
class GetReportColumns{
var $templateName;//string
}
class GetReportColumnsResponse{
var $GetReportColumnsResult;//IntegrationResponse
}
class GetSaveTemplate{
var $templateName;//string
}
class GetSaveTemplateResponse{
var $GetSaveTemplateResult;//IntegrationResponse
}
class SaveData{
var $saveRequest;//SaveRequest
}
class SaveRequest{
var $TemplateName;//string
var $CsvData;//string
var $Action;//int
}
class SaveDataResponse{
var $SaveDataResult;//IntegrationResponse
}
class SubscribeEvent{
var $eventType;//SubscriptionEventTypes
var $filter;//string
var $callbackUrl;//string
}
class SubscribeEventResponse{
var $SubscribeEventResult;//IntegrationResponse
}
class SubscribeEventWithSitesFilters{
var $eventType;//SubscriptionEventTypes
var $filter;//string
var $sitesFilter;//string
var $callbackUrl;//string
}
class SubscribeEventWithSitesFiltersResponse{
var $SubscribeEventWithSitesFiltersResult;//IntegrationResponse
}
class SubscribePostEvent{
var $eventType;//SubscriptionEventTypes
var $filter;//string
var $postUrl;//string
var $postParams;//string
}
class SubscribePostEventResponse{
var $SubscribePostEventResult;//IntegrationResponse
}
class UnsubscribeEvent{
var $subscriptionId;//int
}
class UnsubscribeEventResponse{
var $UnsubscribeEventResult;//IntegrationResponse
}
class Range
{
var $soapClient;
private static $classmap = array('Authenticate'=>'Authenticate'
,'AuthenticateResponse'=>'AuthenticateResponse'
,'IntegrationResponse'=>'IntegrationResponse'
,'ArrayOfIntegrationStatusResponse'=>'ArrayOfIntegrationStatusResponse'
,'IntegrationStatusResponse'=>'IntegrationStatusResponse'
,'ArrayOfInt'=>'ArrayOfInt'
,'GetData'=>'GetData'
,'GetRequest'=>'GetRequest'
,'GetDataResponse'=>'GetDataResponse'
,'UserSessionCredentials'=>'UserSessionCredentials'
,'GetSystemSettings'=>'GetSystemSettings'
,'GetSystemSettingsResponse'=>'GetSystemSettingsResponse'
,'GetReportData'=>'GetReportData'
,'GetReportRequest'=>'GetReportRequest'
,'GetReportDataResponse'=>'GetReportDataResponse'
,'GetReportColumns'=>'GetReportColumns'
,'GetReportColumnsResponse'=>'GetReportColumnsResponse'
,'GetSaveTemplate'=>'GetSaveTemplate'
,'GetSaveTemplateResponse'=>'GetSaveTemplateResponse'
,'SaveData'=>'SaveData'
,'SaveRequest'=>'SaveRequest'
,'SaveDataResponse'=>'SaveDataResponse'
,'SubscribeEvent'=>'SubscribeEvent'
,'SubscribeEventResponse'=>'SubscribeEventResponse'
,'SubscribeEventWithSitesFilters'=>'SubscribeEventWithSitesFilters'
,'SubscribeEventWithSitesFiltersResponse'=>'SubscribeEventWithSitesFiltersResponse'
,'SubscribePostEvent'=>'SubscribePostEvent'
,'SubscribePostEventResponse'=>'SubscribePostEventResponse'
,'UnsubscribeEvent'=>'UnsubscribeEvent'
,'UnsubscribeEventResponse'=>'UnsubscribeEventResponse'
);
function __construct($url='integrationservicev4.asmx?WSDL')
{
$this->soapClient = new SoapClient($url,array("classmap"=>self::$classmap,"trace" => true,"exceptions" => true));
}
function Authenticate(Authenticate $Authenticate)
{
$AuthenticateResponse = $this->soapClient->Authenticate($Authenticate);
return $AuthenticateResponse;
}
function GetData(GetData $GetData)
{
$GetDataResponse = $this->soapClient->GetData($GetData);
return $GetDataResponse;
}
function GetSystemSettings(GetSystemSettings $GetSystemSettings)
{
$GetSystemSettingsResponse = $this->soapClient->GetSystemSettings($GetSystemSettings);
return $GetSystemSettingsResponse;
}
function GetReportData(GetReportData $GetReportData)
{
$GetReportDataResponse = $this->soapClient->GetReportData($GetReportData);
return $GetReportDataResponse;
}
function GetReportColumns(GetReportColumns $GetReportColumns)
{
$GetReportColumnsResponse = $this->soapClient->GetReportColumns($GetReportColumns);
return $GetReportColumnsResponse;
}
function GetSaveTemplate(GetSaveTemplate $GetSaveTemplate)
{
$GetSaveTemplateResponse = $this->soapClient->GetSaveTemplate($GetSaveTemplate);
return $GetSaveTemplateResponse;
}
function SaveData(SaveData $SaveData)
{
$SaveDataResponse = $this->soapClient->SaveData($SaveData);
return $SaveDataResponse;
}
function SubscribeEvent(SubscribeEvent $SubscribeEvent)
{
$SubscribeEventResponse = $this->soapClient->SubscribeEvent($SubscribeEvent);
return $SubscribeEventResponse;
}
function SubscribeEventWithSitesFilters(SubscribeEventWithSitesFilters $SubscribeEventWithSitesFilters)
{
$SubscribeEventWithSitesFiltersResponse = $this->soapClient->SubscribeEventWithSitesFilters($SubscribeEventWithSitesFilters);
return $SubscribeEventWithSitesFiltersResponse;
}
function SubscribePostEvent(SubscribePostEvent $SubscribePostEvent)
{
$SubscribePostEventResponse = $this->soapClient->SubscribePostEvent($SubscribePostEvent);
return $SubscribePostEventResponse;
}
function UnsubscribeEvent(UnsubscribeEvent $UnsubscribeEvent)
{
$UnsubscribeEventResponse = $this->soapClient->UnsubscribeEvent($UnsubscribeEvent);
return $UnsubscribeEventResponse;
}
function Authenticate(Authenticate $Authenticate)
{
$AuthenticateResponse = $this->soapClient->Authenticate($Authenticate);
return $AuthenticateResponse;
}
function GetData(GetData $GetData)
{
$GetDataResponse = $this->soapClient->GetData($GetData);
return $GetDataResponse;
}
function GetSystemSettings(GetSystemSettings $GetSystemSettings)
{
$GetSystemSettingsResponse = $this->soapClient->GetSystemSettings($GetSystemSettings);
return $GetSystemSettingsResponse;
}
function GetReportData(GetReportData $GetReportData)
{
$GetReportDataResponse = $this->soapClient->GetReportData($GetReportData);
return $GetReportDataResponse;
}
function GetReportColumns(GetReportColumns $GetReportColumns)
{
$GetReportColumnsResponse = $this->soapClient->GetReportColumns($GetReportColumns);
return $GetReportColumnsResponse;
}
function GetSaveTemplate(GetSaveTemplate $GetSaveTemplate)
{
$GetSaveTemplateResponse = $this->soapClient->GetSaveTemplate($GetSaveTemplate);
return $GetSaveTemplateResponse;
}
function SaveData(SaveData $SaveData)
{
$SaveDataResponse = $this->soapClient->SaveData($SaveData);
return $SaveDataResponse;
}
function SubscribeEvent(SubscribeEvent $SubscribeEvent)
{
$SubscribeEventResponse = $this->soapClient->SubscribeEvent($SubscribeEvent);
return $SubscribeEventResponse;
}
function SubscribeEventWithSitesFilters(SubscribeEventWithSitesFilters $SubscribeEventWithSitesFilters)
{
$SubscribeEventWithSitesFiltersResponse = $this->soapClient->SubscribeEventWithSitesFilters($SubscribeEventWithSitesFilters);
return $SubscribeEventWithSitesFiltersResponse;
}
function SubscribePostEvent(SubscribePostEvent $SubscribePostEvent)
{
$SubscribePostEventResponse = $this->soapClient->SubscribePostEvent($SubscribePostEvent);
return $SubscribePostEventResponse;
}
function UnsubscribeEvent(UnsubscribeEvent $UnsubscribeEvent)
{
$UnsubscribeEventResponse = $this->soapClient->UnsubscribeEvent($UnsubscribeEvent);
return $UnsubscribeEventResponse;
}}
?>
我想问一下,如果有人可以指出我该如何使用它? 我真的很感激任何有关创建请求的帮助:
SOAP标头:
UserSessionCredentials.UserId [0]:
UserSessionCredentials.ClientId [0]:
UserSessionCredentials.SessionId [0]:
SOAP BODY
GetReportData.getReportRequest [0] .TemplateName [0]:
GetReportData.getReportRequest [0] .PageNo [0]:
GetReportData.getReportRequest [0] .ItemsPerPage [0]:
GetReportData.getReportRequest [0] .SearchClause [0]:
GetReportData.getReportRequest [0] .FilterClause [0]:
GetReportData.getReportRequest [0] .OrderBy [0]: GetReportData.getReportRequest [0] .Columns [0]:
解决方案来自以下答案和StackOverflow问题:Set SoapHeaders with multiple namespace in PHP所有需要此服务的客户:
<?php
$ns = "http://www.thenamespace.net/";
$userid = 123; // you can find out this part from loggin into WMS and checking HTTP requests/responses and you can get the ID
$clientid = "aaa1234";
$username = "username";
$password = base64_encode("password");
$socket_context = stream_context_create(array('http' => array('protocol_version' => 1.0)));
$client = new SoapClient("http://wms.system.net/$clientid/resources/integrationservicev4.asmx?WSDL", array('exceptions' => 0,'stream_context' => $socket_context,'trace' => 1));
// body vars
$someTemplateName = 'Critical'; //from the created reporting template
$somePageNo = 1;
$someItemsPerPage = 1000;
$someSearchClause = '';
$someFilterClause = 'RequestedDeliveryDate >= DateTime(2017,04,13,06,00,00)'; // here we can do $date = date(Y,m,d,) . $time
$someOrderBy = '[Type]';
$someColumns = '[Type],[Total]'; // columns to show
$params = array("clientId"=>$clientid,"username"=>$username,"password"=>$password);
$start = $client->Authenticate($params);
if (is_soap_fault($start)) {
trigger_error("SOAP Fault: (faultcode: {$start->faultcode}, faultstring: {$start->faultstring})", E_USER_ERROR);
print "<br />";
} else {
$response = $start->AuthenticateResult->Detail;
$response_explode = explode(",",$response);
$sessionid = $response_explode[1];
//Body of the Soap Header.
$headerbody = array('UserId' => $userid,'ClientId' => $clientid, 'SessionId' => $sessionid);
//Create Soap Header.
$header = new SOAPHeader($ns, 'UserSessionCredentials', $headerbody);
//set the Headers of Soap Client.
$client->__setSoapHeaders($header);
$body = array( 'TemplateName'=>$someTemplateName,
'PageNo'=>$somePageNo,
'ItemsPerPage'=>$someItemsPerPage,
'SearchClause'=>$someSearchClause,
'FilterClause'=>$someFilterClause,
'OrderBy'=>$someOrderBy,
'Columns'=>$someColumns);
}
$params = array('getReportRequest' => $body);
$reply = $client->GetReportData($params); // ACTUAL MAGIC
var_dump($reply);
print_r($start);
echo "<br><br><br>ResponseT:\n" . $client->__getLastResponse() . "\n";
echo "<br><br><br>REQUEST:\n" . $client->__getLastRequest() . "\n";
?>
答案 0 :(得分:1)
仅基于您在第二部分中提到的SOAP Headers和BODY,我可以回答以下问题:
您可以像这样设置您的请求:
//Body of the Soap Header.
$headerbody = array('UserId' => $someUserId,
'ClientId' => $someClientId,
'SessionId' => $someSessionId);
$ns = 'http://namespace.example.com/'; //Namespace of the WS.
//Create Soap Header.
$header = new SOAPHeader($ns, 'RequestorCredentials', $headerbody);
//set the Headers of Soap Client.
$soap_client->__setSoapHeaders($header);
//Soap Body
$body = array( 'TemplateName'=>$someTemplateName,
'PageNo'=>$somePageNo,
'ItemsPerPage'=>$someItemsPerPage,
'SearchClause'=>$someSearchClause,
'FilterClause'=>$someFilterClause,
'OrderBy'=>$someOrderBy,
'Columns'=>$someColumns);
$reply = $soap_client->call('yourfunction', array('parameters' => $body));
的信息
但是,如果我检查您粘贴的PHP2WSDL代码,我注意到类GetReportData
只有字段$FilterClause
,$OrderBy
,$Columns
而字段$TemplateName
,$PageNo
,$ItemsPerPage
和$SearchClause
属于类GetRequest
,但未包含在您的问题中。
根据您需要使用的内容,您应该只使用PHP2WSDL输出中的以下代码
<?php
class UserSessionCredentials{
var $UserId;//int
var $ClientId;//string
var $SessionId;//string
}
class GetReportData{
var $getReportRequest;//GetReportRequest
}
class GetReportRequest{
var $FilterClause;//string
var $OrderBy;//string
var $Columns;//string
}
class GetReportDataResponse{
var $GetReportDataResult;//IntegrationResponse
}
class Range {
var $soapClient;
private static $classmap = array('Authenticate'=>'Authenticate'
,'AuthenticateResponse'=>'AuthenticateResponse'
,'IntegrationResponse'=>'IntegrationResponse'
,'ArrayOfIntegrationStatusResponse'=>'ArrayOfIntegrationStatusResponse'
,'IntegrationStatusResponse'=>'IntegrationStatusResponse'
,'ArrayOfInt'=>'ArrayOfInt'
,'GetData'=>'GetData'
,'GetRequest'=>'GetRequest'
,'GetDataResponse'=>'GetDataResponse'
,'UserSessionCredentials'=>'UserSessionCredentials'
,'GetSystemSettings'=>'GetSystemSettings'
,'GetSystemSettingsResponse'=>'GetSystemSettingsResponse'
,'GetReportData'=>'GetReportData'
,'GetReportRequest'=>'GetReportRequest'
,'GetReportDataResponse'=>'GetReportDataResponse'
,'GetReportColumns'=>'GetReportColumns'
,'GetReportColumnsResponse'=>'GetReportColumnsResponse'
,'GetSaveTemplate'=>'GetSaveTemplate'
,'GetSaveTemplateResponse'=>'GetSaveTemplateResponse'
,'SaveData'=>'SaveData'
,'SaveRequest'=>'SaveRequest'
,'SaveDataResponse'=>'SaveDataResponse'
,'SubscribeEvent'=>'SubscribeEvent'
,'SubscribeEventResponse'=>'SubscribeEventResponse'
,'SubscribeEventWithSitesFilters'=>'SubscribeEventWithSitesFilters'
,'SubscribeEventWithSitesFiltersResponse'=>'SubscribeEventWithSitesFiltersResponse'
,'SubscribePostEvent'=>'SubscribePostEvent'
,'SubscribePostEventResponse'=>'SubscribePostEventResponse'
,'UnsubscribeEvent'=>'UnsubscribeEvent'
,'UnsubscribeEventResponse'=>'UnsubscribeEventResponse'
);
function __construct($url='integrationservicev4.asmx?WSDL')
{
$this->soapClient = new SoapClient($url,array("classmap"=>self::$classmap,"trace" => true,"exceptions" => true));
}
function GetReportData(GetReportData $GetReportData)
{
$GetReportDataResponse = $this->soapClient->GetReportData($GetReportData);
return $GetReportDataResponse;
}
}
?>
最后,我没有在url integrationservicev4.asmx?WSDL上看到任何wsdl,所以如果你自己没有更改它,请小心,因为即使你正确实现了客户端,服务也可能无法回复你/ p>