php webservice实战

来源:互联网 发布:淘宝联盟做推广多少钱 编辑:程序博客网 时间:2024/05/01 09:41

做这个测试之前,要确认你的php配置文件中已经将soap扩展打开,即extension=php_soap.dll;

//server端 serverSoap.php

<?php

define('WBIN', TRUE);


$soap = new SoapServer(null,array('uri'=>"http://192.168.1.11/"));//This uri is your SERVER ip.
$soap->addFunction('addData_func');  //Register the function
$soap->addFunction(SOAP_FUNCTIONS_ALL);
$soap->handle();


function addData_func($data  = array()){
    return json_encode($data);

}

//client端 clientSoap.php

<?php
define('WBIN', TRUE);
include 'config.inc.php';
include 'DBmysql.class.php';
include 'common.func.php';
include 'Curl.class.php';
error_reporting(E_ALL);
header("Content-type:text/html;charset=utf-8");


function getLoanInfo()
{
$_db = new DBmysql();

$sql = "SELECT
cld.account_number,cld.accntnm,cld.amt,cld.loan_num,cld.loan_type,cld.loan_time,cld.remark,cld.card,
crd.repay_num,crd.first_repay,crd.repay_date
FROM
crm_loan_dk as cld,
crm_repay_dk as crd

where cld.account_number = crd.account_number 

and cld.status = 2 ";
$rs = $_db->executeQuery($sql);
//echo json_encode($rs);


//webservice post array
try {
   $client = new SoapClient(null,
       array('location' =>"http://192.168.1.11/text/webs/serverSoap.php",'uri' => "http://192.168.1.11/")
   );
   echo $client->addData_func($rs);


} catch (SoapFault $fault){
   echo "Error: ",$fault->faultcode,", string: ",$fault->faultstring;
}
}


$action = strtolower(getParam('a'));
switch ($action)
{
case 'loaninfo':         //放款用户基本信息
getLoanInfo();
break;
}

客户端调用服务器端函数

0 0
原创粉丝点击