PHP SoapClient - 使用变量创建请求

问题描述 投票:0回答:1

我试图在PHP中创建一个SOAP请求。我对此非常陌生并且相当挣扎。我正在使用的网络服务将车辆的VIN作为输入,并发回有关该特定车辆的详细信息。输入:1ZVHT88S375260112作为回报,您将收到有关该VIN所属的2007 Ford Mustang的详细信息。

我创建了一个简单的输入栏和表单来输入VIN。这将通过PHP SOAP Request提供给页面。我还用WSDL链接创建了一个SOAP信封。我省略了我的登录凭据(用户名和密码/密码)。

如何在PHP中使用SoapClient获取VIN输入和信封并创建SOAP请求?任何输入或帮助将不胜感激!

简单的HTML输入/表单:

<!DOCTYPE html>
<html>

<head>
<title>VIN Decoder API Test</title>

<style type="text/css">
input {width: 700px;height:50px;display: block;margin-left: auto;margin-right: auto;margin-top: 200px;font-size:36px;font-family: sans-serif;text-align: center;}
button {display: block;margin-left: auto;margin-right: auto;}
.display1 {display: flex;align-items: center;justify-content: center;}
.button1 {
    background-color: rgba(30, 31, 35);
    border: none;
    color: rgba(215, 214, 219);
    padding: 10px 50px;
    text-align: center;
    text-decoration: none;
    display: inline-block;
    font-size: 28px;
    cursor: pointer;
    font-family: sans-serif;
}
</style>

</head>

<body>

    <form action="request.php" method="post">

    <input type="text" id="VIN" placeholder="Enter VIN" name="VIN" maxlength="100"/>
    <br>
    <div class="display1">
    <button id="submit_btn" class="button1">Submit</button>
    </div>

  </form>

  <br>
  <br>

</body>
</html>

肥皂信封:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:description7b.services.chrome.com">
<soapenv:Header/>
 <soapenv:Body>
  <urn:VehicleDescriptionRequest>
     <urn:accountInfo number="" secret="" country="US" language="en" behalfOf="?"/>
     <urn:vin>$VIN</urn:vin>
  </urn:VehicleDescriptionRequest>
 </soapenv:Body>
</soapenv:Envelope>
php soap soap-client
1个回答
0
投票

如果您的soap信封本身位于一个名为envelope.txt的文件中,您可以在您的php页面中执行此操作:

$soapenv = file_get_contents('/path/to/envelope.txt');
$prepared_envelope = str_replace("$VIN", $VIN, $soapenv);

这会将包络加载到变量中,然后将var替换为var的值。有几种方法可以做到这一点,但这是最容易解释的。

© www.soinside.com 2019 - 2024. All rights reserved.