0

尝试调用soapClient 函数但它没有生成正确的XML。

相关代码如下。

function DebugRequest($client)
{
   // <xmp> tag displays xml output in html
   echo "<h2>Request</h2><br/><xmp>", $client->__getLastRequest(), "</xmp><br/><br/>";
}

function DebugResponse($client, $result)
{
   echo('<h2>Result - Size: ' . strlen($client->__getLastResponse()) . '</h2><pre>');
   print_r($result);
   echo("</pre>");
}

class SourceCredentials
{
    public $SourceName;
public $Password;
public $SiteIDs;

function __construct($SourceName, $Password, array $SiteIDs)
{
     $this->SourceName = $SourceName;
     $this->Password = $Password;
     $this->SiteIDs = $SiteIDs;
}

public function ConvertToSOAP()
{
    $arr['SourceName'] = $this->SourceName;
    $arr['Password'] = $this->Password;
    $arr['SiteIDs'] = $this->SiteIDs;
    return $arr;
}
}

class MBClassService
{   
protected $serviceUrl;
protected $client;
protected $debug = false;
protected $defaultCredentials = null;
protected $defaultUserCredentials = null;


function __construct($debug = false)
{
    $endpointUrl = "https://api.mindbodyonline.com/0_5/ClassService.asmx";
    $wsdlUrl = $endpointUrl . "?wsdl";

    $this->debug = $debug;
    $option = array();
    if ($debug)
    {
        $option = array('trace'=>1);
    }
    $this->client = new soapclient($wsdlUrl, $option);
    $this->client->__setLocation($endpointUrl);
}

protected function GetMindbodyParams($additions, $credentials, $XMLDetail, $PageSize, $CurrentPage, $Fields, $UserCredentials = null)
{
    $params['SourceCredentials'] = $credentials->ConvertToSOAP();
    $params['XMLDetail'] = $XMLDetail;
    $params['PageSize'] = $PageSize;
    $params['CurrentPageIndex'] = $CurrentPage;
    $params['Fields'] = $Fields;
    if (isset($UserCredentials))
    {
        $params['UserCredentials'] = $UserCredentials->ConvertToSOAP();
    }

    // Add the additions array and wrap it in Request
    return array('Request' => array_merge($params, $additions));
}

protected function GetCredentials(SourceCredentials $credentials = null)
{
    if (isset($credentials))
    {
        return $credentials;
    }
    else if (isset($this->defaultCredentials))
    {
        return $this->defaultCredentials;
    }
    else
    {
        throw new Exception('No source credentials supplied, and no default credentials stored');
    }
}

public function GetEnrollments(array $locationIDs, array $ClassScheduleIDs, array $staffIDs, array $ProgramIDs, array $SessionTypeIDs, array $SemesterIDs, array $CourseIDs, $startDate, $endDate,  $PageSize = null, $CurrentPage = null, $XMLDetail = XMLDetail::Full, $Fields = NULL, SourceCredentials $credentials = null)
{       
    $additions = array();
    if (count($locationIDs) > 0)
    {
        $additions['locationIDs'] = $locationIDs;
    }
    if (count($ClassScheduleIDs) > 0)
    {
        $additions['ClassScheduleIDs'] = $ClassScheduleIDs;
    }
    if (count($staffIDs) > 0)
    {
        $additions['staffIDs'] = $staffIDs;
    }
    if (count($ProgramIDs) > 0)
    {
        $additions['ProgramIDs'] = $ProgramIDs;
    }
    if (count($SessionTypeIDs) > 0)
    {
        $additions['SessionTypeIDs'] = $SessionTypeIDs;
    }
    if (count($SemesterIDs) > 0)
    {
        $additions['SemesterIDs'] = $SemesterIDs;
    }
    if (count($CourseIDs) > 0)
    {
        $additions['CourseIDs'] = $CourseIDs;
    }
    if (isset($startDate))
    {
        $additions['StartDateTime'] = $startDate->format(DateTime::ATOM);
    }
    if (isset($endDate))
    {
        $additions['EndDateTime'] = $endDate->format(DateTime::ATOM);
    }

    $params = $this->GetMindbodyParams($additions, $this->GetCredentials($credentials), $XMLDetail, $PageSize, $CurrentPage, $Fields);

    try
    {
        $result = $this->client->GetEnrollments($params);
        echo htmlentities($this->client->__getLastRequest());
    }
    catch (SoapFault $fault)
    {
        DebugResponse($this->client);
        // <xmp> tag displays xml output in html
        echo '</xmp><br/><br/> Error Message : <br/>', $fault->getMessage(); 
    }

    if ($this->debug)
    {
        DebugRequest($this->client);
        DebugResponse($this->client, $result);
    }

    return $result;
}

}

$classService = new MBClassService(true);
$sourcename = 'sourcename';
$password = 'passkey';
$siteID = 'siteID';
$creds = new SourceCredentials($sourcename, $password, array($siteID));
$date = new DateTime();
$end = new DateTime('+2 months');
$results = $classService->GetEnrollments(array(4),array(),array(),array(),array(),array(),array(),$date, $end, NULL, NULL, NULL, NULL, $creds);

当我调用 GetEnrollments 函数时,soap 请求不会在 XML 中列出位置或日期。

这里发送的请求

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://clients.mindbodyonline.com/api/0_5" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<SOAP-ENV:Body>
<ns1:GetEnrollments>
  <ns1:Request>
    <ns1:SourceCredentials>
      <ns1:SourceName>sourcename</ns1:SourceName>
      <ns1:Password>sitekey</ns1:Password>
      <ns1:SiteIDs>
        <ns1:int>siteID</ns1:int>
      </ns1:SiteIDs>
    </ns1:SourceCredentials>
    <ns1:XMLDetail xsi:nil="true"/>
    <ns1:PageSize xsi:nil="true"/>
    <ns1:CurrentPageIndex xsi:nil="true"/>
    <ns1:StartDate xsi:nil="true"/>
    <ns1:EndDate xsi:nil="true"/>
  </ns1:Request>
</ns1:GetEnrollments>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope> 

为什么不接受参数

4

1 回答 1

0

参数必须与 WSDL 中的声明完全匹配(区分大小写),因此 $additions['locationIDs'] 需要是 $additions['LocationIDs'] 等等。以此类推

于 2013-10-09T15:39:26.083 回答