PHP - SOAP请求| XML / WSDL

时间:2016-09-09 16:41:17

标签: php xml wsdl

我正在寻找一种从PHP代码发送SOAP请求的方法。一款名为MovieStarPlanet的在线游戏,有一个带有许多SOAP请求的“库”。

以下是所有查询的链接:

WSDL描述:

查询是这样的:

 public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    public void showFragment(View view) {

        FragmentA fragmentA=new FragmentA();
        Bundle bundle=new Bundle();
        bundle.putString("name","Ahmed Ezzat");
        fragmentA.setArguments(bundle);

        getSupportFragmentManager()
            .beginTransaction()
            .add(R.id.dumper,fragmentA,"fragment A")
            .commit();
    }
}

这个问题的答案是:

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>

当用户名/密码组合正确时,这会建议很多帐户信息。

我做了很多研究,但我不知道如何应用代码。这是我做的:

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>

当我运行代码时,它告诉我一个错误:“操作在10000毫秒后收到0字节时超时”。

任何人都可以帮助我?

2 个答案:

答案 0 :(得分:0)

您正在连接curl调用中的wsdl文件。 ( $ url =“http://www.moviestarplanet.fr/WebService/ThirdParty/ThirdPartyService.asmx?WSDL”)

wsdl不是web服务,wsdl是一个带有webservice描述的xml文件。

使用curl进行所有低级编码,你可以使用SoapClient类:

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

这样,与web服务的许多基本通信都是自动处理的。

例如,您可以首先列出网站上的所有服务:

print_r($client->__getFunctions());

答案 1 :(得分:0)

我找到了解决方案! :)

<?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);
?>