简体   繁体   中英

PHP - SOAP Request | XML/WSDL

I'm looking for a way to send a SOAP request from PHP code. An online game called MovieStarPlanet, has a "library" with many SOAP requests.

Here is the link to all queries:

The WSDL description:

The query is like this:

POST /WebService/ThirdParty/ThirdPartyService.asmx HTTP/1.1
Host: http://www.moviestarplanet.fr
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://moviestarplanet.com/Login"

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Header>
    <ThirdPartyTokenHeader xmlns="http://moviestarplanet.com/">
      <ThirdPartyToken>string</ThirdPartyToken>
    </ThirdPartyTokenHeader>
  </soap:Header>
  <soap:Body>
    <Login xmlns="http://moviestarplanet.com/">
      <username>string</username>
      <password>string</password>
    </Login>
  </soap:Body>
</soap:Envelope>

And the answer to this query is:

HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Header>
    <ThirdPartyTicketHeader xmlns="http://moviestarplanet.com/">
      <Ticket>string</Ticket>
    </ThirdPartyTicketHeader>
  </soap:Header>
  <soap:Body>
    <LoginResponse xmlns="http://moviestarplanet.com/">
      <LoginResult>
        <ServiceResult>
          <Codee>int</Codee>
          <Description>string</Description>
        </ServiceResult>
        <ActorId>int</ActorId>
        <AppToken>string</AppToken>
        <UserInfo>
          <FriendCount>int</FriendCount>
          <MembershipTimeoutDate>dateTime</MembershipTimeoutDate>
          <VipTier>int</VipTier>
          <Level>int</Level>
          <LockedUntil>dateTime</LockedUntil>
          <LockedText>string</LockedText>
          <SkinSWF>string</SkinSWF>
          <LastLogin>dateTime</LastLogin>
        </UserInfo>
      </LoginResult>
    </LoginResponse>
  </soap:Body>
</soap:Envelope>

That would suggest a lot of account information when the username/password combination is correct.

I did a lot of research, but I don't know how to apply the code. Here's what I did:

$soap_request  = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
$soap_request .= "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\n";
$soap_request .= "  <soap:Header>\n";
$soap_request .= "    <ThirdPartyTokenHeader xmlns=\"http://moviestarplanet.com/\">\n";
$soap_request .= "      <ThirdPartyToken>8346D304-F85E-4dc1-98EB-033CBEE0217F</ThirdPartyToken>\n";
$soap_request .= "    </ThirdPartyTokenHeader>\n";
$soap_request .= "  </soap:Header>\n";
$soap_request .= "  <soap:Body>\n";
$soap_request .= "    <Login xmlns=\"http://moviestarplanet.com/\">\n";
$soap_request .= "      <username>string</username>\n";
$soap_request .= "      <password>string</password>\n";
$soap_request .= "    </Login>\n";
$soap_request .= "  </soap:Body>\n";
$soap_request .= "</soap:Envelope>";

$header = array(
  "POST /WebService/ThirdParty/ThirdPartyService.asmx HTTP/1.1",
  "Host: http://www.moviestarplanet.fr",
  "Content-type: text/xml; charset=utf-8",
  "Content-length: ".strlen($soap_request),
  "SOAPAction: \"http://moviestarplanet.com/Login\"",
);

$url = "http://www.moviestarplanet.fr/WebService/ThirdParty/ThirdPartyService.asmx?WSDL";

$soap_do = curl_init();
curl_setopt($soap_do, CURLOPT_URL, $url);
curl_setopt($soap_do, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($soap_do, CURLOPT_TIMEOUT,        10);
curl_setopt($soap_do, CURLOPT_RETURNTRANSFER, true );
curl_setopt($soap_do, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($soap_do, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($soap_do, CURLOPT_POST,           true );
curl_setopt($soap_do, CURLOPT_POSTFIELDS,     $soap_request);
curl_setopt($soap_do, CURLOPT_HTTPHEADER,     $header);

if(curl_exec($soap_do) === false) {
  $err = 'Curl error: ' . curl_error($soap_do);
  curl_close($soap_do);
  print $err;
} else {
  curl_close($soap_do);
  print 'Success.';
}

When I run the code, it tells me an error: "Operation timed out after 10000 milliseconds with 0 bytes received".

Anyone can help me?

You are connecting to the wsdl file in your curl call. ( $url = " http://www.moviestarplanet.fr/WebService/ThirdParty/ThirdPartyService.asmx?WSDL ")

The wsdl is NOT the webservice, the wsdl is a xml file with a description of the webservice.

Insted of doing all the low level coding using curl, you could use the SoapClient class:

$client=new SoapClient('http://www.moviestarplanet.fr/WebService/ThirdParty/ThirdPartyService.asmx?WSDL');

That way a lot of the basic communication with then webservice is handle automatic.

For example, you can start by listing all services on site:

print_r($client->__getFunctions());

I have found the soltuion! :)

<?php
$xml_data = '
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Header>
    <ThirdPartyTokenHeader xmlns="http://moviestarplanet.com/">
      <ThirdPartyToken>8346D304-F85E-4dc1-98EB-033CBEE0217F</ThirdPartyToken>
    </ThirdPartyTokenHeader>
  </soap:Header>
  <soap:Body>
    <Login xmlns="http://moviestarplanet.com/">
      <username>USER</username>
      <password>PASS</password>
    </Login>
  </soap:Body>
</soap:Envelope>
';

$headers = array(
"POST /WebService/ThirdParty/ThirdPartyService.asmx HTTP/1.1",
"Referer: www.moviestarplanet.fr",
"User-Agent: Dalvik/1.6.0 (Linux; U; Android 4.4.2; GT-I9505 Build/KOT49H)",
"Content-Type: text/xml; charset=utf-8",
"Host: www.moviestarplanet.fr",
"Content-length: ".strlen($xml_data),
"Expect: 100-continue"
);

$url = 'http://www.moviestarplanet.fr/WebService/ThirdParty/ThirdPartyService.asmx?WSDL';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_data);

$reply = curl_exec($ch); 

echo($reply);
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM