SOAP方式访问相关接口信息,用户可以使用PHP5的SoapClient与nusoap的对象来访问我们的接口信息。在这里我们使用PHP5的SoapClient来访问些接口。
在提交运费查询之前,用户须先获取ISHIP系统的国家名称,以供选择。
代码:<table border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td colspan="2" align="center">Get sfcservice.com shipping countrys.</td>
</tr>
<tr>
<td>Country</td>
<td>
<select name="countryName">
<?php
//遍历国家对象集,并生成国家选项
foreach( $result->countries as $country ){
?>
<option value='<?php echo $country->enName ?>'><?php echo $country->enName ?></option>
<?php }?>
</select>
</td>
</tr>
</table>
<?php
//遍历shiptypes对象集,并生成shiptype选项
foreach( $result->shiptypes as $shiptype ){
?>
<!--输出国际邮递方式-->
<option value='<?php echo $shiptype->method_code ?>'><?php echo $shiptype->en_name ?></option>
<?php }?>
</select>
</td>
</tr>
</table>
<?php
//遍历classtypes对象集,并生成classtype选项
foreach( $result->classtypes as $classtype ){
?>
<!--输出国际邮递类型-->
<option value='<?php echo $classtype->class_code ?>'><?php echo $classtype->en_name ?></option>
<?php }?>
</select>
</td>
</tr>
</table>
此查询需要提交国际包裹的目的国家与重量。所以在提交查询时,我们先生成一个表单来取得国家信息与货物重量,再提交查询。
提交查询表单代码:<table border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td colspan="2" align="center">Get sfcservice.com shipping rate.</td>
</tr>
<tr>
<td>Country</td><td>
<select name="countryName">
<?php
//遍历国家对象集,并生成国家选项
foreach( $result->countries as $country ){
?>
<option value='<?php echo $country->enName ?>'><?php echo $country->enName ?></option>
<?php }?>
</select>
</td> </tr>
<tr>
<td>Weight:</td>
<td><input type="text" name="weight" /></td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="GetRates" /></td>
</tr>
</table>
</form>
// var_dump($respones);
}catch(SoapFault$e){
print"Sorry an error was caught executing your request:{$e->getMessage()}";
}
?>
<div align="center">
<p>Get sfcservice.com shipping rate.</p>
<!--生成查询FORM,提供再次查询-->
<form action="getRateRespones.php" method="post">
<table cellpadding="0">
<tr>
<td>Country</td><td>
<select name="countryName">
<?php
//遍历国家对象集,并生成国家选项
foreach( $result->countries as $country ){
?>
<option value='<?php echo $country->enName ?>'><?php echo $country->enName ?></option>
<?php }?>
</select>
</td> </tr>
<tr>
<td>Weight:</td>
<td><input type="text" name="weight" /></td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="GetRates" /></td>
</tr>
</table>
</form>
<?php
if($respones){//如果返回结果不为空,显示费用规则
?>
<hr color="#6794B8" size="2" >
<table cellspacing="1" cellpadding="0" width="85%">
<tr align="center" bgcolor="#C3D5FD">
<th width="30%">Mail Service</th>
<th width="25%">Total Fee(¥CNY)</th>
<th width="25%">Delivery time(Workday)</th>
<th width="10%">Tracking</th>
<th width="10%">By volume</th>
</tr>
<?php
if(count($respones->rates,1)==1){//if return result have only one rate
?>
<tr align="center" bgcolor="#ffffff">
<td width="30%"><?php echo $respones->rates->shiptypename ?></td>
<td width="25%"><?php echo $respones->rates->totalfee ?></td>
<td width="25%"><?php echo $respones->rates->deliverytime ?></td>
<td width="10%"><?php echo $respones->rates->iftracking ?></td>
<td width="10%"><?php echo $respones->rates->isweight ?></td>
</tr>
<?php
}else{
// For each Shippinh Rate Item node, and display all of them
foreach( $respones->rates as $row ){
?>
<tr align="center" bgcolor="#ffffff">
<td width="30%"><?php echo $row->shiptypename ?></td>
<td width="25%"><?php echo $row->totalfee ?></td>
<td width="25%"><?php echo $row->deliverytime ?></td>
<td width="10%"><?php echo $row->iftracking ?></td>
<td width="10%"><?php echo $row->isweight ?></td>
</tr>
<?php
}
}
?> </table>
<?php
}else{
echo 'No Result';
}
?>
</div>
此查询需要提交国际包裹的目的国家、重量与类型。在提交查询前,我们应生成一个表单来取得国家信息、货物重量与类型,再提交查询。
提交查询表单代码:<div align="center">
<p>Get sfcservice.com shipping rate by type.</p>
<form action="getRateByTypeRespones.php" method="post">
<table cellpadding="0">
<tr>
<td>Country</td><td>
<select name="countryName">
<?php
foreach( $result->countries as $country ){
?>
<option value='<?php echo $country->enName ?>'><?php echo $country->enName ?></option>
<?php
}
?>
</select>
</td> </tr>
<tr>
<td>Type</td><td>
<select name="type">
<?php
foreach( $class->classtypes as $classtype ){
?>
<option value='<?php echo $classtype->class_code ?>'><?php echo $classtype->en_name ?></option>
<?php
}
?>
</select>
</td> </tr>
<tr>
<td>Weight:</td>
<td><input type="text" name="weight" /></td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="GetRates" /></td>
</tr>
</table>
</form>
</div>
<?php
if(!$_POST['countryName']){
echo 'Please select Country!';
return;
}
if(!$_POST['weight']){
echo 'Please input weight!';
return;
}
if(!$_POST['type']){
echo 'Please select type!';
return;
}
$country = $_POST['countryName'];
$weight = $_POST['weight'];
$type = $_POST['type'];
$client=new SoapClient('http://www.sendfromchina.com/shipfee/web_service?wsdl');
try{
//调用getCountries,取得国家列表
$result=$client->getCountries();
//获取ISHIP的运输方式类型
$class=$client->getClassTypes();
//require getRatesByType
$respones = $client->getRatesByType($weight,$country,$type);
}catch(SoapFault$e){
print"Sorry an error was caught executing your request:{$e->getMessage()}";
}
?>
<div align="center">
<p>Get sfcservice.com shipping rate by type.</p>
<form action="getRateByTypeRespones.php" method="post">
<table cellpadding="0">
<tr>
<td>Country</td><td>
<select name="countryName">
<?php
//遍历国家对象集,并生成国家选项--iteration the country object,and print every country
foreach( $result->countries as $country ){
?>
<option value='<?php echo $country->enName ?>'><?php echo $country->enName ?></option>
<?php }?>
</select>
</td> </tr>
<tr>
<td>Type</td><td>
<select name="type">
<!-- generate sendfromchin.com shipping Type option -->
<?php
foreach( $class->classtypes as $classtype ){
?>
<option value='<?php echo $classtype->class_code ?>'><?php echo $classtype->en_name ?></option>
<?php
}
?>
</select>
</td>
</tr>
<tr>
<td>Weight:</td>
<td><input type="text" name="weight" /></td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="GetRates" /></td>
</tr>
</table>
</form>
<?php
if($respones){//if there have any result
?>
<hr color="#6794B8" size="2" >
<table cellspacing="1" cellpadding="0" width="85%">
<tr align="center" bgcolor="#C3D5FD">
<th width="30%">Mail Service</th>
<th width="25%">Total Fee(¥CNY)</th>
<th width="25%">Delivery time(Workday)</th>
<th width="10%">Tracking</th>
<th width="10%">By volume</th>
</tr>
<?php
if(count($respones->rates,1)==1){//if return result have only one rate
?>
<tr align="center" bgcolor="#ffffff">
<td width="30%"><?php echo $respones->rates->shiptypename ?></td>
<td width="25%"><?php echo $respones->rates->totalfee ?></td>
<td width="25%"><?php echo $respones->rates->deliverytime ?></td>
<td width="10%"><?php echo $respones->rates->iftracking ?></td>
<td width="10%"><?php echo $respones->rates->isweight ?></td>
</tr>
<?php
}else{
// iteration return Shipping Rate Item node, and display all of them
foreach( $respones->rates as $row ){
?>
<tr align="center" bgcolor="#ffffff">
<td width="30%"><?php echo $row->shiptypename ?></td>
<td width="25%"><?php echo $row->totalfee ?></td>
<td width="25%"><?php echo $row->deliverytime ?></td>
<td width="10%"><?php echo $row->iftracking ?></td>
<td width="10%"><?php echo $row->isweight ?></td>
</tr>
<?php
}
}
?> </table>
<?php
}else{
echo 'No Result';
}
?>
</div>
此查询需要提交国际包裹的目的国家、重量与邮寄方式。在提交查询前,我们应生成一个表单来取得国家信息、货物重量与邮寄方式,再提交查询。
提交查询表单代码:<?php
$client=new SoapClient('http://www.sendfromchina.com/shipfee/web_service?wsdl');
try{
//调用getCountries,取得国家列表
$result=$client->getCountries();
//获取ISHIP的所有运输方式
$method=$client->getShipTypes();
}catch(SoapFault$e){
print"Sorry an error was caught executing your request:{$e->getMessage()}";
}
?>
<div align="center">
<p>Get sfcservice.com shipping rate by mode.</p>
<form action="getRateByModeRespones.php" method="post">
<table cellpadding="0">
<tr>
<td>Country:</td><td>
<select name="countryName">
<?php
foreach( $result->countries as $country ){
?>
<option value='<?php echo $country->enName ?>'><?php echo $country->enName ?></option>
<?php }?>
</select>
</td> </tr>
<tr>
<td>Mode:</td><td>
<select name="mode">
<?php
foreach( $method->shiptypes as $method ){ //生成ISHIP邮递方式选项
?>
<option value='<?php echo $method->method_code ?>'><?php echo $method->en_name ?></option>
<?php }?>
</select>
</td> </tr>
<tr>
<td>Weight:</td>
<td><input type="text" name="weight" /></td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="GetRate" /></td>
</tr>
</table>
</form>
</div>
<table cellpadding="0">
<tr>
<td>Country</td><td>
<select name="countryName">
<?php
//遍历国家对象集,并生成国家选项--iteration the country object,and print every country
foreach( $result->countries as $country ){
?>
<option value='<?php echo $country->enName ?>'><?php echo $country->enName ?></option>
<?php }?>
</select>
</td> </tr>
<tr>
<td>Mode:</td><td>
<select name="mode">
<?php
foreach( $method->shiptypes as $method ){ //生成ISHIP邮递方式选项
?>
<option value='<?php echo $method->method_code ?>'><?php echo $method->en_name ?></option>
<?php }?>
</select>
</td> </tr>
<tr>
<td>Weight:</td>
<td><input type="text" name="weight" /></td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="GetRate" /></td>
</tr>
</table>
</form>
<?php
if($respones){//if there have any result
?>
<hr color="#6794B8" size="2" >
<table cellspacing="1" cellpadding="0" width="85%">
<tr align="center" bgcolor="#C3D5FD">
<th width="30%">Mail Service</th>
<th width="25%">Total Fee(¥CNY)</th>
<th width="25%">Delivery time(Workday)</th>
<th width="10%">Tracking</th>
<th width="10%">By volume</th>
<tr align="center" bgcolor="#ffffff">
<td width="30%"><?php echo $respones->shiptypename ?></td>
<td width="25%"><?php echo $respones->totalfee ?></td>
<td width="25%"><?php echo $respones->deliverytime ?></td>
<td width="10%"><?php echo $respones->iftracking ?></td>
<td width="10%"><?php echo $respones->isweight ?></td>
</tr>
</table>
<?php
}else{
echo 'No Result';
}
?>
此查询需要提交ISHIP提供的订单ID或者ISHIP提供的跟踪号码。在提交查询前,我们应生成一个表单来输入订单ID或者跟踪号码,再提交查询。
代码:<h2>Get Track Information </h2>
<form action="getTrackInfoRespone.php" method="post">
<table cellpadding="0">
<tr>
<td>Track & Confirm :</td>
<td><input type ="text" name= "trackingNumber" value="" /></td>
<td><input type="submit" value= "Track" name ="Track"/></td>
</tr>
</table>
</form>
getTrackInfoRespone.php