资讯专栏INFORMATION COLUMN

laravel中soapServer支持wsdl的例子

elarity / 2191人阅读

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

</>复制代码

  1. $server = new SoapServer(null, ["uri" => "noganluonguri"]);
  2. $server->setObject(new NganluongServer());
  3. ob_start();
  4. $server->handle();
  5. return ob_get_clean();

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

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

主要逻辑代码 - SoapService.php

</>复制代码

  1. 创建路由

  2. </>复制代码

    1. $api->any("soapUrl", "SoapCallbackController@soapFun");
  3. 路由主要实现方法-wsdl不存在则创建,不需要手动创建,url:https:xxx/soapurl?wsdl

  4. </>复制代码

    1. getWSDL());
    2. fclose($file);
    3. }
    4. $server = new SoapServer($storagePath . "/wsdl/" . $className . ".wsdl", array("soap_version" => SOAP_1_2));
    5. $server->setClass($procClass);
    6. $server->handle();
    7. } catch (Exception $e) {
    8. Log::error("wsdl服务创建异常");
    9. }
    10. }
    11. }
  5. 生成wsdl- SoapDiscovery.php

  6. </>复制代码

    1. class_name = $class_name;
    2. $this->service_name = $service_name;
    3. }
    4. /**
    5. * SoapDiscovery::getWSDL() Returns the WSDL of a class if the class is instantiable.
    6. *
    7. * @return string
    8. * */
    9. public function getWSDL() {
    10. if (empty($this->service_name)) {
    11. throw new Exception("No service name.");
    12. }
    13. $headerWSDL = "
    14. ";
    15. $headerWSDL.= "
    16. ";
    17. $headerWSDL.= "
    18. ";
    19. if (empty($this->class_name)) {
    20. throw new Exception("No class name.");
    21. }
    22. $class = new ReflectionClass($this->class_name);
    23. if (!$class->isInstantiable()) {
    24. throw new Exception("Class is not instantiable.");
    25. }
    26. $methods = $class->getMethods();
    27. $portTypeWSDL = "service_name . "Port">";
    28. $bindingWSDL = "service_name . "Binding" type="tns:" . $this->service_name . "Port">
    29. ";
    30. $serviceWSDL = "service_name . "">
    31. service_name . "Port" binding="tns:" . $this->service_name . "Binding">
    32. ";
    33. $messageWSDL = "";
    34. foreach ($methods as $method) {
    35. if ($method->isPublic() && !$method->isConstructor()) {
    36. $portTypeWSDL.= "getName() . "">
    37. " . "getName() . "Request" />
    38. getName() . "Response" />
    39. ";
    40. $bindingWSDL.= "getName() . "">
    41. " . "service_name . "#" . $this->class_name . "#" . $method->getName() . "" />
    42. ";
    43. $messageWSDL.= "getName() . "Request">
    44. ";
    45. $parameters = $method->getParameters();
    46. foreach ($parameters as $parameter) {
    47. $messageWSDL.= "getName() . "" type="xsd:string" />
    48. ";
    49. }
    50. $messageWSDL.= "
    51. ";
    52. $messageWSDL.= "getName() . "Response">
    53. ";
    54. $messageWSDL.= "getName() . "" type="xsd:string" />
    55. ";
    56. $messageWSDL.= "
    57. ";
    58. }
    59. }
    60. $portTypeWSDL.= "
    61. ";
    62. $bindingWSDL.= "
    63. ";
    64. //return sprintf("%s%s%s%s%s%s", $headerWSDL, $portTypeWSDL, $bindingWSDL, $serviceWSDL, $messageWSDL, "");
    65. //生成wsdl文件,将上面的return注释
    66. $fso = fopen($this->class_name . ".wsdl", "w");
    67. fwrite($fso, sprintf("%s%s%s%s%s%s", $headerWSDL, $portTypeWSDL, $bindingWSDL, $serviceWSDL, $messageWSDL, ""));
    68. }
    69. /**
    70. * SoapDiscovery::getDiscovery() Returns discovery of WSDL.
    71. *
    72. * @return string
    73. * */
    74. public function getDiscovery() {
    75. return "
    76. ";
    77. }
    78. }
    79. ?>
  7. webservice测试

  8. </>复制代码

    1. getSum(10, 24);
    2. echo $soap->__soapCall("getSum",array(10,24));
  9. 如有问题请请出,谢谢支持。QQ273086429

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/29570.html

相关文章

  • PHP SOAP 扩展使用

    摘要:类也是一个只包含构造器的低级类,与和类相似。安装扩展对于平台,需要在中加入如下代码上面的工作完成之后,还需要注意的是扩展在配置文件中有独立的代码片段这些配置项主要是用来指定处理文件时使用缓存的行为。支持与扩展类似的。 原文地址:PHP SOAP 扩展,本文在原文基础上添加了一些内容和章节,也加入了一些注释,请读者注意。 前两篇文章 《SOAP 介绍》 和 《SOAP Web 服务介绍》...

    Cympros 评论0 收藏0
  • spring boot开发soap webservice

    摘要:本文介绍如何在中开发接口,以及接口如何同时支持和两种协议。该功能很简单,就是通过一个人的姓名查询这个人的详细信息。就是关键,如本次请求报文如下就是,对应。测试使用进行测试,通过地址导入文件进行测试。测试这样就实现了和同时提供的目的。 介绍spring boot web模块提供了RestController实现restful,第一次看到这个名字的时候以为还有SoapController,...

    Ashin 评论0 收藏0
  • 学习 PHP SOAP 扩展一些笔记

    摘要:对的相关学习就先告此一段落,这是最后一篇文章用来记录下学习过程中的一些笔记和心得。对,没错在还没有提供扩展前,的确很多人也是这样做的。总结上面都是自己在学习扩展时的一些零散的笔记,如果有不对的地方,希望大家指出,谢谢。 对 SOAP 的相关学习就先告此一段落,这是最后一篇文章用来记录下学习过程中的一些笔记和心得。 前面三篇文章分别是: 《SOAP 介绍》 《SOAP Web 服务介绍...

    wthee 评论0 收藏0
  • nginx配置laravel项目

    server{ listen 443; server_name 10.0.3.15 ssl on; ssl_certificate /etc/nginx/conf.d/3i.crt; ssl_certificate /etc/nginx/conf.d/3i_nopass.key; root /var/www/html/3i-mobile/publ...

    KavenFan 评论0 收藏0

发表评论

0条评论

elarity

|高级讲师

TA的文章

阅读更多
最新活动
阅读需要支付1元查看
<