用PHP SOAP验证 [英] SOAP authentication with PHP

查看:206
本文介绍了用PHP SOAP验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要连接到需要在纯文本用户名和密码的形式认证证书的Web服务。

I need to connect to a web service that requires authentication credentials in the form of a plain text user name and password.

我有SOAP有基本的了解,并已成功地连接到其他开放式Web服务不需要用户名或密码使用的NuSOAP。

I have a basic understanding of SOAP and have managed to connect to other open web services that do not require a username or password using NuSOAP.

以下是送给我的:

<?php

// Set up security options
$security_options = array("useUsernameToken" => TRUE);
$policy = new WSPolicy(array("security" => $security_options));

$security_token = new WSSecurityToken(array(
    "user" => "xxx",
    "password" => "xxx",
    "passwordType" => "basic"));

// Create client with options
$client = new WSClient(array("wsdl" => "https://xxx.asmx?wsdl",
    "action" => "http://xxx",
    "to" => "https://xxx",
    "useWSA" => 'submission',
    "CACert" => "cert.pem",
    "useSOAP" => 1.1,
    "policy" => $policy,
    "securityToken" => $security_token));

// Send request and capture response
$proxy = $client->getProxy();

$input_array = array("From" => "2010-01-01 00:00:00",
    "To" => "2010-01-31 00:00:00");

$resMessage = $proxy->xxx($input_array);
?>

经过一番研究,我理解的是,上述实现使用WSO2。我需要能够做到这一点,而无需使用WSO2。

After some research I understand that the above implementation uses wso2. I need to be able to do this without using wso2.

我已经尽了全力去寻找有关上述资源(谷歌,论坛等),但一直没能找到任何东西。我已阅读SOAP一些教程,并已经能够使用PHP建立SOAP客户端,但不能让我的头周围所有的认证和政策。

I have tried my best to look for resources (Google, forums, etc) about the above but haven't been able to find anything. I have read some tutorials on SOAP and have been able to set up a SOAP client using PHP but cannot get my head around all the authentication and "policies".

也许有些环节如何实现这一点的解释,并进一步阅读有关这将是非常美联社preciated因为我撕裂我的头发!理想情况下,我想一些链接资源的绝对初学者到SOAP验证。

An explanation of how to achieve this and maybe some links to further reading about this would be very much appreciated as I am tearing my hair out! Ideally I would like some links to resources for an absolute beginner to the SOAP authentication.

感谢。 P.S一些链接/在上面的凭据可能已经xxx'd隐私。

Thanks. P.S some of the links/credentials in the above could have been xxx'd for privacy.

推荐答案

如果您在PHP中启用了SOAP扩展(PHP版本> = 5.0.1),您可以使用的 SoapClient的类来处理您的请求。要验证,您可以将用户名和密码传递给类与目标网址:

If you have the SOAP extension enabled in php (php version >= 5.0.1), you can use the SoapClient class to process your request. To authenticate, you can pass the username and password to the class with the target URL:

$soapURL = "https://www.example.com/soapapi.asmx?wsdl" ;
$soapParameters = Array('login' => "myusername", 'password' => "mypassword") ;
$soapFunction = "someFunction" ;
$soapFunctionParameters = Array('param1' => 42, 'param2' => "Search") ;

$soapClient = new SoapClient($soapURL, $soapParameters);

$soapResult = $soapClient->__soapCall($soapFunction, $soapFunctionParameters) ;

if(is_array($soapResult) && isset($soapResult['someFunctionResult'])) {
    // Process result.
} else {
    // Unexpected result
    if(function_exists("debug_message")) {
        debug_message("Unexpected soapResult for {$soapFunction}: ".print_r($soapResult, TRUE)) ;
    }
}

如果你不知道你可以调用功能,可以查看在浏览器中目标URL(例如,在.ASMX?WSDL结尾)。你应该得到一个XML响应,告诉你可用的SOAP函数可以调用,以及这些功能对预期参数。

If you're not sure about the functions you can call, you can view the target URL (e.g. ending in ".asmx?wsdl") in your browser. You should get an XML response that tells you the available SOAP functions you can call, and the expected parameters of those functions.

这篇关于用PHP SOAP验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆