PHP SOAP Version1.0示例代码


SOAP方式访问相关接口信息,用户可以使用PHP5的SoapClient与nusoap的对象来访问我们的接口信息。在这里我们使用PHP5的SoapClient来访问些接口。

 

查询ISHIP邮寄国家名称

在提交运费查询之前,用户须先获取ISHIP系统的国家名称,以供选择。

代码:
<?php
//建立SoapClient对象
$client=new SoapClient('http://www.sendfromchina.com/shipfee/web_service?wsdl');
try{
//调用getCountries,取得国家列表
$result=$client->getCountries();
}catch(SoapFault$e){
print"Sorry an error was caught executing your request:{$e->getMessage()}";
}
?>

<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>


 

查询ISHIP支持的邮寄方式

代码:
<?php
//建立SoapClient对象
$client=new SoapClient('http://www.sendfromchina.com/shipfee/web_service?wsdl');
try{
//调用getShipTypes,取得国际邮递方式列表
$result=$client->getShipTypes ();
}catch(SoapFault$e){
print"Sorry an error was caught executing your request:{$e->getMessage()}";
}
?> <table border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td colspan="2" align="center">Get sfcservice.com ship types.</td>
</tr>
<tr>
<td>Ship Type</td>
<td>
<select name="countryName">

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


 

查询ISHIP支持的邮寄类型

代码:
<?php
//建立SoapClient对象
$client=new SoapClient('http://www.sendfromchina.com/shipfee/web_service?wsdl');
try{
//调用getClassTypes,取得国际邮递类型
$result=$client->getClassTypes ();
}catch(SoapFault$e){
print"Sorry an error was caught executing your request:{$e->getMessage()}";
}
?> <table border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td colspan="2" align="center">Get sfcservice.com class types.</td>
</tr>
<tr>
<td>Class Type</td>
<td>
<select name="countryName">

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


 

直接查询可用运费规则

此查询需要提交国际包裹的目的国家与重量。所以在提交查询时,我们先生成一个表单来取得国家信息与货物重量,再提交查询。

提交查询表单代码:
<?php
$client=new SoapClient('http://www.sendfromchina.com/shipfee/web_service?wsdl');
try{
//调用getCountries,取得国家列表
$result=$client->getCountries();
}catch(SoapFault$e){
print"Sorry an error was caught executing your request:{$e->getMessage()}";
}
?>
<!---表单POST提交到getRateRespones.php-->
<form action="getRateRespones.php" method="post">

<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>


getRateRespones.php代码:
<?php
if(!$_POST['countryName']){
echo 'Please select Country!';
return;
}
if(!$_POST['weight']){
echo 'Please input weight!';
return;
}
$country = @$_POST['countryName'];
$weight = @$_POST['weight'];
$client=new SoapClient('http://www.sendfromchina.com/shipfee/web_service?wsdl');
try{

//调用getCountries,取得国家列表
$result=$client->getCountries();
$respones = $client->getRates($weight,$country);//GetRate

// 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(&#165;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>

 

按邮寄类型查询运费规则

此查询需要提交国际包裹的目的国家、重量与类型。在提交查询前,我们应生成一个表单来取得国家信息、货物重量与类型,再提交查询。

提交查询表单代码:
<?php
$client=new SoapClient('http://www.sendfromchina.com/shipfee/web_service?wsdl');
try{

//调用getCountries,取得国家列表
$result=$client->getCountries();
//获取ISHIP的运输方式类型
$class=$client->getClassTypes();

}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

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>


getRateByTypeRespones.php代码:

<?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(&#165;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>


getRateByTypeRespones.php代码:
<?php
if(!$_POST['countryName']){
echo 'Please select Country!';
return;
}
if(!$_POST['weight']){
echo 'Please input weight!';
return;
}
if(!$_POST['mode']){
echo 'Please select mode!';
return;
}
$country = @$_POST['countryName'];
$weight = @$_POST['weight'];
$mode =$_POST['mode'];
$client=new SoapClient('http://www.sendfromchina.com/shipfee/web_service?wsdl');
try{
//调用getCountries,取得国家列表
$result=$client->getCountries();
//获取ISHIP的所有运输方式
$method=$client->getShipTypes();
$respones = $client->getRateByMode($weight,$country,$mode);
}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
//遍历国家对象集,并生成国家选项--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(&#165;CNY)</th>
<th width="25%">Delivery time(Workday)</th>
<th width="10%">Tracking</th>
<th width="10%">By volume</th>

</tr>

<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';

}

?>
</div>

 

查询国际包裹跟踪信息

此查询需要提交ISHIP提供的订单ID或者ISHIP提供的跟踪号码。在提交查询前,我们应生成一个表单来输入订单ID或者跟踪号码,再提交查询。

代码:

<h2>Get Track Information </h2>
<form action="getTrackInfoRespone.php" method="post">
<table cellpadding="0">
<tr>
<td>Track &amp; Confirm :</td>
<td><input type ="text" name= "trackingNumber" value="" /></td>
<td><input type="submit" value= "Track" name ="Track"/></td>
</tr>
</table>
</form>


getTrackInfoRespone.php

<?php
header("Content-type: text/html; charset=utf-8");
?>
<h2>Get Track Information </h2>
<form action="./getTrackInfoRespone.php" method="post">
<table cellpadding="0">
<tr>
<td>Track &amp; Confirm :</td>
<td><input type ="text" name= "trackingNumber" value="" /></td>
<td><input type="submit" value= "Track" name ="Track"/></td>
</tr>
</table>
</form>
<?php
$trackingNumber = @$_POST['trackingNumber'];
if($trackingNumber == ''){
echo "Please fill the Track Number.";
return;
}
$trackingNo['number'] = $trackingNumber;

$client = new SoapClient('http://www.sendfromchina.com/shipfee/web_service?wsdl');
try{
$result = $client->getTrackingInfo($trackingNo);
}catch(SoapFault$e){
print"Sorry an error was caught executing your request:{$e->getMessage()}";
}
?>
<?php

// Check to see if the response has tracking information, else print an error
if( $result->order ){

?>
<hr color="#6794B8" size="2" >
<h3>Order Information </h3>
<table cellspacing="1" cellpadding="0" width="85%">
<tr >
<td>Order Id:</td><td><?php echo $result->order->order_id ?> </td> <td > </td><td>Weight:</td><td><?php echo $result->order->weight ?> </td>
</tr>
<tr >
<td>Type:</td><td><?php echo $result->order->type ?> </td> <td> </td><td>Destination:</td><td><?php echo $result->order->destination ?> </td>
</tr>
</table>

<h3>Shipment Travel History </h3>
<table cellspacing="1" cellpadding="0" width="85%">
<tr align="center" bgcolor="#C3D5FD">
<td>Activity</td>
<td>TrackDate </td>
<td>Location</td>
</tr>
<?php
if(count($result->track,1)>1){//if return result have only one record
foreach( $result->track as $row ){
?>
<tr>
<td><?php echo $row->activity ?></td>
<td><?php echo $row->track_date ?></td>
<td><?php echo $row->locations ?></td>
</tr>
<?php
}
}else{

?>
<tr align="center" bgcolor="#ffffff">
<td><?php echo $result->track->activity ?></td>
<td><?php echo $result->track->track_date ?></td>
<td><?php echo $result->track->locations ?></td>
</tr>
<?php
}
?>
</table>
<?php
}
?>