PHP SoapClient и WS-Security Header
WS-Security - это всеобъемлющая концептуальная модель, абстрагирующая различные технологии защиты в "формулы" и "обозначения" ("claims" and "tokens")... Для управляющей информации используются SOAP-заголовки. Это главное место, где обитает SOAP-защита. Здесь также размещена информация системного уровня, используемая для управления сообщением и для его защиты. SOAP-системы времени исполнения и SOAP-программы промежуточного уровня обрабатывают директивы SOAP-заголовка. Заголовки предназначены для добавления новых функциональных возможностей, и здесь будут размещаться заголовки WS-Security. Отправитель может потребовать понимания заголовка получателем. Заголовки общаются непосредственно с SOAP-процессорами и могут потребовать, чтобы процессор отклонил все SOAP-сообщение, если он не понимает заголовок. Если заголовок содержит критическую защищенную информацию, которую не понимает SOAP-процессор, вы, вероятно, не захотите обрабатывать это SOAP-сообщение вообще
предлогаю вам следующий PHP код на рассмотрение:
/**
Пример:
include('WsSoapClient.php');
$url = "WSDL адресс";
$client = new WsSoapClient($url);
$client->__setUsernameToken('Логин','Пароль');
$params=array(); //Параметры сервиса пишем здесь
$result=$client->__soapCall('название функции',$params);
print_r($result);//выводим полученный результат.
*/
class WsSoapClient extends SoapClient{
private $username;
private $password;
/*Generates de WSSecurity header*/
private function wssecurity_header(){
//The timestamp. The computer must be on time or the server you are connecting may reject the password digest for security.
$timestamp = gmdate('Y-m-d\TH:i:s\Z');
//A random word. The use of rand() may repeat the word if the server is very loaded.
$nonce = mt_rand();
$passdigest = $this->password;
$auth='
'.$this->username.' '.$passdigest.' '.base64_encode(pack('H*',$nonce)).' '.$timestamp.' ';
//XSD_ANYXML (or 147) is the code to add xml directly into a SoapVar. Using other codes such as SOAP_ENC, it's really difficult to set the correct namespace for the variables, so the axis server rejects the xml.
$authvalues = new SoapVar($auth, XSD_ANYXML);
$header = new SoapHeader("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", "Security", $authvalues, true);
return $header;
}
/**
* It's necessary to call it if you want to set a different user and password
*/
public function __setUsernameToken($username, $password)
{
$this->username = $username;
$this->password = $password;
}
/**
* Overwrites the original method adding the security header. As you can see, if you want to add more headers, the method needs to be modifyed
*/
public function __soapCall($function_name,$arguments,$options=null, $input_headers=null,$output_headers=null)
{
$result = parent::__soapCall($function_name,$arguments,$options,$this->wssecurity_header());
return $result;
}
}



