thinkphp5 使用soap调用接口
来源:互联网 发布:外立面效果图制作软件 编辑:程序博客网 时间:2024/06/06 07:34
分享下厚典在上海网站开发中的技术,thinkphp3.2调用soap这里不讲了,直接说一下thinkphp5调用soap,需要对tp5的结构有一定的了解,不然看不懂。
先要开启php_soap,不然会报错
一、服务器端
1、先在common.php下建function
如图:
代码如下:
function WebService($uri,$class_name='',$namespace='controller',$persistence = false){
$class = 'index\\'. $namespace .'\\'. $class_name;
$class = 'app\index\controller\Web';
$serv = new \SoapServer(null,array("uri"=>$uri));
$serv->setClass($class);
if($persistence)
$serv->setPersistence(SOAP_PERSISTENCE_SESSION);//默认是SOAP_PERSISTENCE_REQUEST
$serv->handle();
return $serv;
}
2、在服务器端建调用的function
如图
代码发下:
class Web extends Controller {
public function index(){
WebService(url('web/index'),'Web');
}
public function itemType( $type='', $style='' )
{
echo $type.$style;
}
二、客户端
同样是在common,php下建个function 注意:我这个客户端跟服务端并不在同一个项目下,是分开得两个访问地址
代码如下:
function WebClient($url='',array $options=array()){
if(stripos($url,'?wsdl')!== false)
{
return new \SoapClient($url,array_merge(array('encoding'=>'utf-8'),$options));//WSDL
}
else
{
$location = "http://yb.houapi.cn/";
$uri = "index/web/index";
$options = array_merge(array('location'=>$location,'uri'=>$uri,'encoding'=>'utf-8'),$options);
return new \SoapClient(null,$options);//non-WSDL
}
}
2、客户端如果需要调用,可直接调用
class Swiper extends Common
{
public function index(){
//
$client = WebClient();
$res = $client->itemType('swiper_price','1234');
}
到此完事。其实很简单。
先要开启php_soap,不然会报错
一、服务器端
1、先在common.php下建function
如图:
代码如下:
function WebService($uri,$class_name='',$namespace='controller',$persistence = false){
$class = 'index\\'. $namespace .'\\'. $class_name;
$class = 'app\index\controller\Web';
$serv = new \SoapServer(null,array("uri"=>$uri));
$serv->setClass($class);
if($persistence)
$serv->setPersistence(SOAP_PERSISTENCE_SESSION);//默认是SOAP_PERSISTENCE_REQUEST
$serv->handle();
return $serv;
}
2、在服务器端建调用的function
如图
代码发下:
class Web extends Controller {
public function index(){
WebService(url('web/index'),'Web');
}
public function itemType( $type='', $style='' )
{
echo $type.$style;
}
二、客户端
同样是在common,php下建个function 注意:我这个客户端跟服务端并不在同一个项目下,是分开得两个访问地址
代码如下:
function WebClient($url='',array $options=array()){
if(stripos($url,'?wsdl')!== false)
{
return new \SoapClient($url,array_merge(array('encoding'=>'utf-8'),$options));//WSDL
}
else
{
$location = "http://yb.houapi.cn/";
$uri = "index/web/index";
$options = array_merge(array('location'=>$location,'uri'=>$uri,'encoding'=>'utf-8'),$options);
return new \SoapClient(null,$options);//non-WSDL
}
}
2、客户端如果需要调用,可直接调用
class Swiper extends Common
{
public function index(){
//
$client = WebClient();
$res = $client->itemType('swiper_price','1234');
}
到此完事。其实很简单。
0 0
- thinkphp5 使用soap调用接口
- 使用soap调用wsdl的接口实战
- SOAP的接口调用
- 如何使用PHP调用ArcGIS Server的Soap接口
- VC++使用Soap ToolKit3.0调用WebService接口
- VC++使用Soap ToolKit3.0调用WebService接口
- PHP 使用SOAP调用接口开发,偶尔会报错
- 基于apache的soap接口分布调用
- iOS调用SOAP协议的WebServices接口
- iOS调用WebService(SOAP接口)
- Javascrpit调用webservice接口(soap方式)
- 使用Soap方式调用Webservice
- webservice接口常见问题1:客户端使用SOAP方式调用CXF服务时异常
- thinkphp5.0调用支付宝接口(扫码支付)
- Thinkphp5微信小程序获取用户信息接口调用笔记
- iOS-90-调用后台接口(WCF,soap访问方式,接口后缀.svc形式),使用WSDL2objc工具才能搞定
- Thinkphp5使用
- 工作中使用SOAP UI测试接口
- linux下MPI开发环境搭建
- poj 2796
- Servlet中Response对象应用1(输出简单文字、实现文件下载)
- 使用Picasso加载图片的内存优化实践
- 食君之禄,忠君之事
- thinkphp5 使用soap调用接口
- Retrofit 学习记录(一)
- 题目1007:奥运排序问题
- 设计模式之单例模式讲解
- 团体程序设计天梯赛L2-017 人以群分
- IAR .map文件中CODE memory,data memory+115absoult,const memeory
- Eclipse的MyBatis的自动提示
- 杭电 HDU ACM 1002
- 从注册表的键值判断OS是32位还是64位