1
$client = new SoapClient("http://soap.m4u.com.au/?wsdl", array("trace" => 1));
$params = array(

      "authentication" => array(
        "userId" => "user",
        "password" => "pass"
      ),
      "requestBody" => array(
        "messages" => array(
            "message" => array(
                "recipients" => array( "recipient" => array("1" => "9799996899") ),
                "content" => "Message Content"
            )
        )
      )

);

$response = $client->__soapCall("sendMessages", array($params));

但我收到以下错误

Fatal error: Uncaught SoapFault exception: [SOAP-ENV:Client] The request is either not well-formed or is not valid against the relevant schema.

我需要如下的请求格式。

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://xml.m4u.com.au/2009">
<soapenv:Header/>
<soapenv:Body>
    <ns:sendMessages>
        <ns:authentication>
            <ns:userId>Username</ns:userId>
            <ns:password>Password</ns:password>
        </ns:authentication>
        <ns:requestBody>
            <ns:messages>
                <ns:message format="SMS" sequenceNumber="1">
                    <ns:recipients>
                        <ns:recipient uid="1">61400000001</ns:recipient>
                        <ns:recipient uid="2">61400000002</ns:recipient>
                    </ns:recipients>
                <ns:content>Message Content</ns:content>
                </ns:message>
            </ns:messages>
        </ns:requestBody>
    </ns:sendMessages>
</soapenv:Body>
</soapenv:Envelope>

我怎么能做到这一点,请帮忙。

4

1 回答 1

0

你有一个棘手的问题。

我没有时间完全解决它,但看起来 WSDL 的格式意味着 SoapClient 必须提供对象结构。

我无法想到如何在不使用数组的情况下表示多个节点条目(然后在发送之前将其分解)

我知道这不是一个完整的解决方案,但我认为这是正确的路线(作为概念证明)

请注意使用__getLastRequest反对SoapClient来准确检索您发送到服务器的内容。它非常有用...

<?php

class authentication {

    public $userId;
    public $password;

    function __construct( $userId, $password ) {
        $this->userId   = $userId;
        $this->password = $password;
    }
}

class message {

    public $recipients;
    public $content;

    function __construct( $recipients, $content ) {
        $this->recipients = $recipients;
        $this->content    = $content;
    }
}

class requestBody {

    public $messages;

    function __construct( $messages ) {
        $this->messages = $messages;
    }
}

$client = new SoapClient("http://soap.m4u.com.au/?wsdl", array("trace" => 1));
$params = array(
      "authentication" => new authentication( 'user', 'pass' ),
      "requestBody"    => new requestBody( array( new message( array( '1' => '61400000001' )
                                                             , 'message content' )
                                                )
                                         )
      );

try {
    $response = $client->sendMessages( $params );
} catch(SoapFault $e) {
    file_put_contents( 'request.xml', $client->__getLastRequest() );
    throw $e;
}


?>

我认为你最好的选择是与服务供应商联系,看看是否有其他人通过 PHP 连接。

抱歉,我无法提供更多帮助 - 我希望这很有用!

于 2014-01-03T09:35:37.670 回答