Home > Backend Development > PHP Tutorial > PHP interface code example for calling wsdl file type

PHP interface code example for calling wsdl file type

怪我咯
Release: 2023-03-13 20:14:01
Original
4133 people have browsed it

WSDL Introduction

Web service description language (WSDL).
When programmers sit in front of the computer and want to use Web services, their tools (such as Visual Studio) cannot provide them with any help because these tools do not understand Web services at all.
The solution is:
Provide a formal description document in a machine-readable way. Web service description language (WSDL)
is such an XML-based language used to describe Web services and their functions, Parameters and return values. Because it is based on XML, WSDL is both machine-readable and human-readable.
This will be a great benefit. Some of the latest development tools can not only generate WSDL documents based on your Web service, but also import WSDL documents to generate code that calls the corresponding Web service.

This article mainly shares with you an interface code for PHP to call wsdl file type. It is very simple and practical. Friends who have related needs can use it directly.

The code is as follows:

<?php
// 本类由系统自动生成,仅供测试用途
class IndexAction extends Action {
    public function index(){
        //#分销商订单提交、修改、取消、查询接口
         $wsdl1=&#39;http://127.0.0.1:8080/ejfxs/services/order?wsdl&#39;;
         //#分销商可销售产品接口地址
        $wsdl=&#39;http://127.0.0.1:8080/ejfxs/services/availableProducts?wsdl&#39;;
        //实例化对象
        $client=new SoapClient($wsdl);
        //接口参数。
        $param1=array(&#39;password&#39;=>&#39;123456&#39;,&#39;dis_code&#39;=>&#39;fxBZZHLYW&#39;,&#39;checkcode&#39;=>&#39;FXFAXM5U1Y&#39;);
        //接口方法。
        $ret1 = $client->getAvailableProducts($param1); 
        //将XML数据转换成数组
        $array=(array)$ret1;
        //转换成simplexml_load_string对象
        $v=simplexml_load_string($array[&#39;return&#39;]);
        //数组定义
        $Varr=$v->ybproducts->fzhproducts->product;
        //获取到具体的值
        for ($i=0; $i < count($Varr); $i++) { 
            echo $Varr[$i]->prod_id;
            echo $Varr[$i]->product_name;
            echo $Varr[$i]->prod_code;
            echo $Varr[$i]->prod_category;
            echo $Varr[$i]->supply_id;
            echo $Varr[$i]->price;
            echo $Varr[$i]->parprice;
            echo $Varr[$i]->total_ticket_num;
            echo $Varr[$i]->inventory;
            echo $Varr[$i]->product_name;
            echo $Varr[$i]->product_name;
            echo &#39;<br/>&#39;;
        }
        //获取接口所有方法及参数
        // print_r($client->getfunctions());
        // print_r($client->getTypes());
    }
}
?>
Copy after login

The above is the detailed content of PHP interface code example for calling wsdl file type. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template