用Curl PHP进行肥皂请求

时间:2018-10-02 06:54:01

标签: php curl soap

如何使用下面的soap格式和url使用Curl php发出Soap请求?我已经在线尝试了可用的解决方案,但都没有解决。

$soap_request = '<?xml version="1.0" encoding="UTF-8"?>
        <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:alisonwsdl" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
          <soap:Header>
            <credentials>
                <alisonOrgId>9ReXlYlpOThe24AWisE</alisonOrgId>
                <alisonOrgKey>C2owrOtRegikaroXaji</alisonOrgKey>
            </credentials>
          </soap:Header>
          <SOAP-ENV:Body>
            <q1:login xmlns:q1="urn:alisonwsdl">
                <email xsi:type="xsd:string">email</email>
                <firstname xsi:type="xsd:string">fname</firstname>
                <lastname xsi:type="xsd:string">lname</lastname>
                <city xsi:type="xsd:string">city</city>
                <country xsi:type="xsd:string">country</country>
                <external_id xsi:type="xsd:string"></external_id>
            </q1:login>
          </SOAP-ENV:Body>
        </SOAP-ENV:Envelope>';

 Url
https://alison.com/api/service.php?wsdl

2 个答案:

答案 0 :(得分:1)

假设您已经安装了php_soap扩展名,则可以这样访问SOAP API:

<?php

$client = new SoapClient('https://alison.com/api/service.php?wsdl', array(
    'stream_context' => stream_context_create(array(
        'ssl' => array(
            'verify_peer' => false,
            'verify_peer_name' => false, 
            'allow_self_signed' => true
        )
    ))
));

您可能还需要定义身份验证标头

$auth = array(
    'alisonOrgId' => '9ReXlYlpOThe24AWisE',
    'alisonOrgKey' => 'C2owrOtRegikaroXaji'
);

$header = new SoapHeader('https://alison.com/api/service.php?wsdl', 'credentials', $auth, false);
$client->__setSoapHeaders($header);

然后您可以获得可用功能列表

// Get function list
$functions = $client->__getFunctions ();
echo "<pre>";
var_dump ($functions);
echo "</pre>";
die;

或立即调用函数,如下所示:

// Run the function
$obj = $client->__soapCall("emailExists", array(
    "email" => "test@email.com"
));
echo "<pre>";
var_dump ($obj);
echo "</pre>";
die;

答案 1 :(得分:0)

经过一周的努力,我可以在youtube https://www.youtube.com/watch?v=6V_myufS89A上的本教程中找到一些东西,并且能够成功地向API发送请求,请先阅读上面的xml格式,然后再继续解决方案

     $options = array('trace'=> true, "exception" => 0);

    $client  = new \SoapClient('your url to wsdl',$options);

   //if you have Authorization parameters in your xml like mine above use SoapVar and SoapHeader as me below

    $params = new \stdClass();
    $params->alisonOrgId = value here';
    $params->alisonOrgKey = 'value here';

    $authentication_parameters = new \SoapVar($params,SOAP_ENC_OBJECT);

    $header = new \SoapHeader('your url to wsdl','credentials',$authentication_parameters);

    $client->__setSoapHeaders(array($header));


   print_r($client->__soapCall("Function here",'Function parameter here or left it as null if has no parameter'));

    //or call your function by

     print_r($client->yourFunction($function_parameters));

    }

希望这将帮助那些苦苦处理包含身份验证信息的肥皂请求的人