CI集成nusoap
来源:互联网 发布:sql 时间按月分组 编辑:程序博客网 时间:2024/06/08 11:53
因为要用php访问一些Web service的接口
需要用到nusoap
关于nusoap的使用
参见http://blog.csdn.net/keyunq/archive/2006/12/06/1431725.aspx
而网站用了ci的架构 所以得想办法集成进来
网上搜了下
找到如下解决方法
1.首先下载nusoap 最新版貌似是0.7.2
将lib目录里的文件放到 ci的libraries目录 如: ci/application/libraries/nusoap-0.7.3
2.编写Nusoap_lib.php 自己的类库文件 放在ci/application/libraries/Nusoap_lib.php
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class Nusoap_lib
{
function __construct()
{
require_once('nusoap-0.7.3/nusoap.php');
}
}
?>
3.然后就可以用$this->load->library("Nusoap_lib") 来调用了
如下
<?php
class Client extends Controller
{
function __construct()
{
parent::Controller();
$this->load->library("Nusoap_lib");
}
function index()
{
$this->nusoap_client = new nusoap_client("http://xxxxxxxx/xxxxxxxx.asmx?wsdl","wsdl");
if($this->nusoap_client->fault)
{
$str = 'Error: '.$this->nusoap_client->fault;
}
else
{
$parameters = array('param1'=>param1,'param2'=>param2,'param3'=>$param3,'param4'=>$param4);
if ($this->nusoap_client->getError())
{
$str = 'Error: '.$this->nusoap_client->getError();
}
else
{
$arr_result = $this->nusoap_client->call('CheckUserName',$parameters);
$str = $arr_result['CheckUserNameResult'];
}
}
echo $str;
}
}
?>
整个过程和集成smarty貌似差不多
以上只是调用webservice 的代码,编写webservice的代码,可以参考下面的网址:
http://codeigniter.com/forums/viewthread/59710/
//add by Q 2008.12.1
通常我们进行 Web Service 开发时都是用的 UTF-8 编码,这时我们需要设置 :
Code:
$client->soap_defencoding = 'utf-8';
同时,需要让 xml 以同样的编码方式传递:
Code:
$client->xml_encoding = 'utf-8';
集成到ci里 就是
$this->nusoap_client->soap_defencoding = 'utf-8';
$this->nusoap_client->xml_encoding = 'utf-8';
到现在,应该是一切正常了才对,但是我们在输出结果的时候,却发现,返回的是乱码。
实际上,开启了调试功能的朋友,相信会发现 $client->response 返回的是正确的结果,为什么 $result = $client->call($action, array('parameters' => $param)); 却是乱码呢?
研究过 NuSOAP 代码后我们会发现,当 xml_encoding 设置为 UTF-8 时,NuSOAP 会检测 decode_utf8 的设置,如果为 true ,会执行 PHP 里面的 utf8_decode 函数,而 NuSOAP 默认为 true,因此,
我们需要设置:
$client->soap_defencoding = 'utf-8';
$client->decode_utf8 = false;
$client->xml_encoding = 'utf-8';
集成到ci里 就是
$this->nusoap_client->soap_defencoding = 'utf-8';
$this->nusoap_client->decode_utf8 = false;
$this->nusoap_client->xml_encoding = 'utf-8';
需要用到nusoap
关于nusoap的使用
参见http://blog.csdn.net/keyunq/archive/2006/12/06/1431725.aspx
而网站用了ci的架构 所以得想办法集成进来
网上搜了下
找到如下解决方法
1.首先下载nusoap 最新版貌似是0.7.2
将lib目录里的文件放到 ci的libraries目录 如: ci/application/libraries/nusoap-0.7.3
2.编写Nusoap_lib.php 自己的类库文件 放在ci/application/libraries/Nusoap_lib.php
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class Nusoap_lib
{
function __construct()
{
require_once('nusoap-0.7.3/nusoap.php');
}
}
?>
3.然后就可以用$this->load->library("Nusoap_lib") 来调用了
如下
<?php
class Client extends Controller
{
function __construct()
{
parent::Controller();
$this->load->library("Nusoap_lib");
}
function index()
{
$this->nusoap_client = new nusoap_client("http://xxxxxxxx/xxxxxxxx.asmx?wsdl","wsdl");
if($this->nusoap_client->fault)
{
$str = 'Error: '.$this->nusoap_client->fault;
}
else
{
$parameters = array('param1'=>param1,'param2'=>param2,'param3'=>$param3,'param4'=>$param4);
if ($this->nusoap_client->getError())
{
$str = 'Error: '.$this->nusoap_client->getError();
}
else
{
$arr_result = $this->nusoap_client->call('CheckUserName',$parameters);
$str = $arr_result['CheckUserNameResult'];
}
}
echo $str;
}
}
?>
整个过程和集成smarty貌似差不多
以上只是调用webservice 的代码,编写webservice的代码,可以参考下面的网址:
http://codeigniter.com/forums/viewthread/59710/
//add by Q 2008.12.1
NuSOAP 调用 Web Service 出现乱码的原因:
通常我们进行 Web Service 开发时都是用的 UTF-8 编码,这时我们需要设置 :
Code:
$client->soap_defencoding = 'utf-8';
同时,需要让 xml 以同样的编码方式传递:
Code:
$client->xml_encoding = 'utf-8';
集成到ci里 就是
$this->nusoap_client->soap_defencoding = 'utf-8';
$this->nusoap_client->xml_encoding = 'utf-8';
到现在,应该是一切正常了才对,但是我们在输出结果的时候,却发现,返回的是乱码。
NuSOAP 调用 Web Service 出现乱码的解决方法:
实际上,开启了调试功能的朋友,相信会发现 $client->response 返回的是正确的结果,为什么 $result = $client->call($action, array('parameters' => $param)); 却是乱码呢?
研究过 NuSOAP 代码后我们会发现,当 xml_encoding 设置为 UTF-8 时,NuSOAP 会检测 decode_utf8 的设置,如果为 true ,会执行 PHP 里面的 utf8_decode 函数,而 NuSOAP 默认为 true,因此,
我们需要设置:
$client->soap_defencoding = 'utf-8';
$client->decode_utf8 = false;
$client->xml_encoding = 'utf-8';
集成到ci里 就是
$this->nusoap_client->soap_defencoding = 'utf-8';
$this->nusoap_client->decode_utf8 = false;
$this->nusoap_client->xml_encoding = 'utf-8';
- CI集成nusoap
- thinkphp集成nusoap
- 持续集成 ci简介
- Travis CI 持续集成
- 持续集成(CI)
- jenkins CI 持续集成
- 持续集成CI
- CI和UEditor集成
- CI持续集成
- Postman-CI集成Jenkins
- [CI] Jenkins - 持续集成
- jenkins 与CI集成
- Postman-CI集成Jenkins
- TFS2015的CI集成
- 持续集成(CI)
- 什么是持续集成(CI)
- CI持续集成组合方案
- CI集成C#和JAVA
- 70、80、90年代人的区别
- 女生在IT计算机行业适合什么工作
- ofbiz的服务(service)export成web service的方法(4)
- 要命的CLASSPATH 设置
- 胡椒鸡汤浸生蚝
- CI集成nusoap
- 纯java的Excel解决方案
- 如何使用SSE指令提高FIR算法效率(进化二)
- 数据库连接池的概念
- 如何在诺基亚NOKIA手机安装JAVA软件程序
- 使用一键粘贴功能
- Sysinternals
- jQuery-toggle()与toggle(fn,fn)的用法 学习笔记五
- Using CToolTipCtrl study