PHP使用NuSOAP调用Web服务的方法

yipeiwu_com5年前PHP代码库

本文实例讲述了PHP使用NuSOAP调用Web服务的方法。分享给大家供大家参考。具体如下:

Steps:
1. Download nusoap library from internet.
2. Pass parameter list in your $client->call and enjoy.

<?php
require_once('./lib/nusoap.php');
$client = new soapclientnusoap('http://www.devtrackn.com/webservice/server.php');
$err = $client->getError();
if ($err) {
  // Display the error
  echo '<p><b>Constructor error: ' . $err . '</b></p>';
  // At this point, you know the call that follows will fail
}
////////////////////////////////////////////////////////
////////////////////////////////////////////////////////
// update_location method parameter
$param = array(
    'device_number'   => '9910948357',
    'latitude'     => '40.727757',
    'longitude'     => '-73.984366',
    'battery_status'  => '30'
  );
// user_action method parameter
$param2 = array(
    'device_number'   => '27ab2026da5213ebd6c95e5fbe50965bdfaddf4b',
    'latitude'     => '40.727757',
    'longitude'     => '-73.984366',
    'user_action'    => 'Meeting_Test'
  );
// sos method parameter
$param3 = array(
    'device_number'   => '9910948357',
    'latitude'     => '40.727757',
    'longitude'     => '-73.984366',
  );
//$result = $client->call('update_location', $param);
//$result = $client->call('user_action', $param2);
//$result = $client->call('sos', $param3);
$result = $client->call('user_entity_status', array('device_number' => '27ab2026da5213ebd6c95e5fbe50965bdfaddf4b'));
////////////////////////////////////////////////////////
////////////////////////////////////////////////////////
// Check for a fault
if ($client->fault) {
  echo '<p><b>Fault: ';
  print_r($result);
  echo '</b></p>';
} else {
  // Check for errors
  $err = $client->getError();
  if ($err) {
    // Display the error
    echo '<p><b>Error: ' . $err . '</b></p>';
  } else {
    // Display the result
    echo "<pre>";
    print_r($result);
    echo "</pre>";
  }
}
echo '<h2>Request</h2>';
echo '<pre>' . htmlspecialchars($client->request, ENT_QUOTES) . '</pre>';
echo '<h2>Response</h2>';
echo '<pre>' . htmlspecialchars($client->response, ENT_QUOTES) . '</pre>';
/*
// Display the debug messages
echo '<h2>Debug</h2>';
echo '<pre>' . htmlspecialchars($client->debug_str, ENT_QUOTES) . '</pre>';
*/
?>

希望本文所述对大家的php程序设计有所帮助。

相关文章

PHP给前端返回一个JSON对象的实例讲解

解决问题:用php做后台时,如何给前端发起的AJAX请求返回一个JSON格式的"对象"; 说明:我本身是一个前端,工作久了之后发现要是不掌握一门后端开发语言的话,总感觉有点无力。最近在边...

PHP 组件化编程技巧

PHP 组件化编程技巧

但其在UI方便却有些力不从心,不仅是PHP,任何一种Web编程语言在设计UI都有类似的问题,宿主语言与HTML混和在一个文件中,大量重复的 HTML代码,毫无任何技术含量,但又非常的费时...

php switch语句多个值匹配同一代码块应用示例

先说说switch()语句的格式 switch(表达式){ case 匹配1: 当匹配1和表达式匹配成功执行的代码; break; case 匹配2: 当匹配2和表达式匹配成功执行的代码...

PHP中strtr与str_replace函数运行性能简单测试示例

PHP中strtr与str_replace函数运行性能简单测试示例

本文实例讲述了PHP中strtr与str_replace函数运行性能简单测试。分享给大家供大家参考,具体如下: strtr与str_replace函数性能,很简单的一个测试,只是简单的测...

PHP闭包函数详解

匿名函数也叫闭包函数(closures允许创建一个没有指定没成的函数,最经常用作回调函数参数的值。 闭包函数没有函数名称,直接在function()传入变量即可 使用时将定义的变量当作函...