laravel框架下soapServer支持wsdl的代码示例

本篇文章给大家带来的内容是关于laravelsoapserver支持wsdl的代码示例,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。

$server = new SoapServer(null, ['uri' => 'noganluonguri']);$server->setObject(new NganluongServer());ob_start();$server->handle();return ob_get_clean();

上边这段代码是无wsdl模式下的,但是这次是对接第三方的服务,需要我们这边去定义soap webservice,第三方来调用,第三方定义的是wsdl模式的,所以今天研究了下。

laravel代码示例(其它框架类似思考方式):

主要逻辑代码 – SoapService.php

<?php/** * soap服务端 */namespace AppServices;Class SoapService{    public function getSum($param1, $param2)    {         return $param1 + $param2;    }}

创建路由

$api->any('soapUrl', 'SoapCallbackController@soapFun');

路由主要实现方法-wsdl不存在则创建,不需要手动创建,url:https:xxx/soapurl?wsdl

getWSDL());                    fclose($file);                }                $server = new SoapServer($storagePath . '/wsdl/' . $className . '.wsdl', array('soap_version' => SOAP_1_2));                $server->setClass($procClass);                $server->handle();            } catch (Exception $e) {                Log::error('wsdl服务创建异常');            }        }    }

生成wsdl类 – SoapDiscovery.php

class_name = $class_name;        $this->service_name = $service_name;    }    /**     * SoapDiscovery::getWSDL() Returns the WSDL of a class if the class is instantiable.     *      * @return string     * */    public function getWSDL() {        if (empty($this->service_name)) {            throw new Exception('No service name.');        }        $headerWSDL = "";        $headerWSDL.= "service_name" targetNamespace="urn:$this->service_name" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="urn:$this->service_name" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns="http://schemas.xmlsoap.org/wsdl/">";        $headerWSDL.= "";        if (empty($this->class_name)) {            throw new Exception('No class name.');        }        $class = new ReflectionClass($this->class_name);        if (!$class->isInstantiable()) {            throw new Exception('Class is not instantiable.');        }        $methods = $class->getMethods();        $portTypeWSDL = 'service_name . 'Port">';        $bindingWSDL = 'service_name . 'Binding" type="tns:' . $this->service_name . "Port">";        $serviceWSDL = 'service_name . "">service_name . 'Port" binding="tns:' . $this->service_name . "Binding">";        $messageWSDL = '';        foreach ($methods as $method) {            if ($method->isPublic() && !$method->isConstructor()) {                $portTypeWSDL.= 'getName() . "">" . 'getName() . "Request" />getName() . "Response" />";                $bindingWSDL.= 'getName() . "">" . 'service_name . '#' . $this->class_name . '#' . $method->getName() . "" />service_name" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />service_name" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />";                $messageWSDL.= 'getName() . "Request">";                $parameters = $method->getParameters();                foreach ($parameters as $parameter) {                    $messageWSDL.= 'getName() . "" type="xsd:string" />";                }                $messageWSDL.= "";                $messageWSDL.= 'getName() . "Response">";                $messageWSDL.= 'getName() . "" type="xsd:string" />";                $messageWSDL.= "";            }        }        $portTypeWSDL.= "";        $bindingWSDL.= "";        //return sprintf('%s%s%s%s%s%s', $headerWSDL, $portTypeWSDL, $bindingWSDL, $serviceWSDL, $messageWSDL, '');        //生成wsdl文件,将上面的return注释        $fso = fopen($this->class_name . ".wsdl", "w");        fwrite($fso, sprintf('%s%s%s%s%s%s', $headerWSDL, $portTypeWSDL, $bindingWSDL, $serviceWSDL, $messageWSDL, ''));    }    /**     * SoapDiscovery::getDiscovery() Returns discovery of WSDL.     *      * @return string     * */    public function getDiscovery() {        return "";    }}?>

webservice测试

getSum(10, 24);echo $soap->__soapCall('getSum',array(10,24));

以上就是laravel框架下soapServer支持wsdl的代码示例的详细内容,更多请关注php中文网其它相关文章!

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 chuangxiangniao@163.com 举报,一经查实,本站将立刻删除。
发布者:程序猿,转转请注明出处:https://www.chuangxiangniao.com/p/112567.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
linux的boot分区是什么意思
上一篇 2025年11月23日 22:10:45
如何使用Hyperf框架进行支付宝支付
下一篇 2025年11月23日 22:13:48

相关推荐

发表回复

登录后才能评论
关注微信