Soap调用sitemider PHP
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Soap调用sitemider PHP相关的知识,希望对你有一定的参考价值。
好的男孩和女孩我真的试过......这里并不缺乏努力......
我有一个预订酒店,活动和管理它的系统,现在我必须连接siteminder和其他服务。哪个好,但我无法理解它是如何工作的...我得到的只是一个错误,我无法理解如何让它工作。
所以我们去编码:
$auth = new stdClass();
$auth->UsernameToken = new stdClass();
$auth->UsernameToken->Username = $user;
$auth->UsernameToken->Password = $pw;
$client = new SoapClient($wsdl,array('trace'=>true));
$header = new SOAPHeader($ns, 'Security', $auth, false);
$hresp = $client->__setSoapHeaders($header);
//This is true... so my authentication is working perfect
//var_dump($hresp);
$arr = array(
'POS' => array(
'Source'=> array(
'RequestorID' => array(
'type'=>'22',
'ID'=>$id,
)
)
),
'AvailStatusMessages' => array(
'HotelCode'=>$hc,
'AvailStatusMessage' => array(
'StatusApplicationControl' => array(
'Start'=>'2016-10-01',
'End'=>'2016-10-01',
'InvTypeCode'=>'TR',
'RatePlanCode'=>'BAR'
),
'RestrictionStatus' => array(
'Status'=>'Close'
)
)
)
);
try{
//here is my issue
$data = $client->__call('HotelAvailNotifRQ',array($arr));
if($data->Errors) {
foreach($data->Errors as $error) {
echo "Error: ".$error;
}
}else {
var_dump($data);
}
} catch (SoapFault $e) {
var_dump($e);
echo $e->faultstring;
}
尝试这个我得到这个错误:找不到肥皂体中的RequestorID / @ ID
但是你可以看到我发送了requestorID
我尝试了不同的方式,对象,XML值,SoapVar,SoapParam和许多其他不同的方式...我得到的是同样的错误...这意味着我出于某种原因在我实际发送时没有发送requestorID它!
完成的夫妻试验:
$arr = array(
'POS' => array(
'_' => array(
'Source' => array(
'_' => array(
'RequestorID' => array(
'type'=>'22',
'ID'=>$id,
)
)
)
)
),
);
$pos = new StdClass();
$pos->source->requestorID = $id;
$pos->source->type = 22;
$asm = new StdClass();
$asm->HotelCode = $hc;
$asm->AvailStatusMessage->StatusApplicationControl->Start = '2016-10-01';
$asm->AvailStatusMessage->StatusApplicationControl->End = '2016-10-02';
$asm->AvailStatusMessage->StatusApplicationControl->InvTypeCode = 'TR';
$asm->AvailStatusMessage->StatusApplicationControl->RatePlanCode = 'BAR';
$arr = array(
'POS' => $pos
'AvailStatusMessages' => $asm
);
$xml = "
<SOAP-ENV:Envelope xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/'>
<SOAP-ENV:Body xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/'>
<OTA_HotelAvailNotifRQ xmlns='http://www.opentravel.org/OTA/2003/05' Version='1.0' TimeStamp='2005-08-01T09:30:47+08:00' EchoToken='echo-abc123'>
<POS>
<Source>
<RequestorID Type='22' ID='$id'/>
</Source>
</POS>
<AvailStatusMessages HotelCode='$hc'>
<AvailStatusMessage>
<StatusApplicationControl Start='2010-01-01' End='2010-01-14' InvTypeCode='A1K' RatePlanCode='GLD'/>
<RestrictionStatus Restriction='Departure' Status='Close' />
</AvailStatusMessage>
</AvailStatusMessages>
</OTA_HotelAvailNotifRQ>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>";
所以基本上我已经尝试了所有可能的方式......我可以想到将其发送到呼叫并使其工作。
任何人都知道如何正确地做到这一点?我真的需要帮助......
我想要做的是:https://siteminder.atlassian.net/wiki/pages/viewpage.action?pageId=2048374#space-menu-link-content
提前致谢。
好吧,据我所知,在互联网上...没有人对我的问题有答案,所以我不得不继续努力,直到我开始工作。我做到了!
以下是我如何使用它的示例:
<?php
$RID = "BAR"; //Requestor ID
$url = 'https://cmtpi.siteminder.com/siteconnect/services/siteconnect_v1.1.0.wsdl';
$endpoint = 'https://cmtpi.siteminder.com/siteconnect/services';
$service_connect = "this is your endpoint";
$User = "test"; // username
$Password = "1234"; // password
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $endpoint);
curl_setopt($ch, CURLOPT_POSTFIELDS, $input_xml);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 300);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml', 'Content-Length: ' . strlen($input_xml)));
$data = curl_exec($ch);
if(curl_exec($ch) === false){
echo 'Curl error: ' . curl_error($ch);
}else {
Header("Content-type: text/xml");
echo $data;
}
curl_close($ch);
有了这个基础,系统将POST和XML数据,并将获得XML数据的响应。
我的$ input XML有这些数据:
<SOAP-ENV:Envelope xmlns="http://www.opentravel.org/OTA/2003/05" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<SOAP-ENV:Header>
<wsse:Security SOAP-ENV:mustUnderstand="1">
<wsse:UsernameToken>
<wsse:Username>test</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">1234</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<OTA_HotelAvailNotifRQ xmlns="http://www.opentravel.org/OTA/2003/05" Version="1.0" EchoToken="3c763f03-6333-4f38-9835-c7cf8433c263" TimeStamp="2016-11-25T18:30:29+01:00">
<POS>
<Source>
<RequestorID TYPE="22" ID="BAR"/>
<BookingChannel Primary="1" Type="1">
<CompanyName Code="TST">TEST</CompanyName>
</BookingChannel>
</Source>
</POS>
<AvailStatusMessages HotelCode="HOTEL_ID">
<AvailStatusMessage>
<StatusApplicationControl Start="2010-01-01" End="2010-01-01" InvTypeCode="A1K" RatePlanCode="GLD" />
<!-- Content omitted -->
</AvailStatusMessage>
<AvailStatusMessage>
<StatusApplicationControl Start="2010-01-02" End="2010-01-02" InvTypeCode="A1K" RatePlanCode="GLD" />
<!-- Content omitted -->
</AvailStatusMessage>
<AvailStatusMessage>
<StatusApplicationControl Start="2010-01-03" End="2010-01-03" InvTypeCode="A1K" RatePlanCode="GLD" />
<!-- Content omitted -->
</AvailStatusMessage>
</AvailStatusMessages>
</OTA_HotelAvailNotifRQ>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
当我发送它们时,它们会响应数据库......我们开始做交易。
我的主要问题是如何传递REQUESTOR ID,请求者ID基本上是来自源的ID属性,我在尝试将其作为对象或变量发送之前已经显示...我的困惑是我试图做一个SOAP调用XML API ...所有搞砸了:)
我的英语不是那么好......但至少我在这里展示我的解决方案。
也许这可以帮助将来的某个人。
做这样的事情,它对我有用:
$params = array(
'Target' => "Test",
'Version' => "1.0",
'POS' => array(
'Source' => array(
'RequestorID' => array(
'ID' => 'test',
'MessagePassword' => 'test',
),
),
),
'Criteria' => array(
'Criterion' => array(
'Address' => array(
'CountryName' => array(
'Code' => 'US',
),
),
),
)
);
$result = $client->HotelAvailNotif($params);
pre_d($result);
<?xml version="1.0" encoding="UTF-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<OTA_HotelAvailNotifRQ Target="Test" xmlns="http://www.test.com/test" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" Version="1.0">
<POS>
<Source>
<RequestorID ID="test" MessagePassword="test" />
</Source>
</POS>
<Criteria>
<Criterion>
<Address>
<CountryName Code="US"></CountryName>
</Address>
</Criterion>
</Criteria>
</OTA_HotelAvailNotifRQ >
</s:Body>
</s:Envelope>
以上是关于Soap调用sitemider PHP的主要内容,如果未能解决你的问题,请参考以下文章
php 如何利用 soap调用.Net的WebService asmx文件