php webservice实战

做这个测试之前,要确认你的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
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

wbandzlhgod

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值