douyou2368 2016-09-09 16:41
浏览 83
已采纳

PHP - SOAP请求| 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\"?>
";
$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/\">
";
$soap_request .= "  <soap:Header>
";
$soap_request .= "    <ThirdPartyTokenHeader xmlns=\"http://moviestarplanet.com/\">
";
$soap_request .= "      <ThirdPartyToken>8346D304-F85E-4dc1-98EB-033CBEE0217F</ThirdPartyToken>
";
$soap_request .= "    </ThirdPartyTokenHeader>
";
$soap_request .= "  </soap:Header>
";
$soap_request .= "  <soap:Body>
";
$soap_request .= "    <Login xmlns=\"http://moviestarplanet.com/\">
";
$soap_request .= "      <username>string</username>
";
$soap_request .= "      <password>string</password>
";
$soap_request .= "    </Login>
";
$soap_request .= "  </soap:Body>
";
$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?

  • 写回答

2条回答 默认 最新

  • 普通网友 2016-09-16 13:55
    关注

    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);
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?