SoapService.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Think.Admin
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2014~2017 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://think.ctolog.com
  8. // +----------------------------------------------------------------------
  9. // | 开源协议 ( https://mit-license.org )
  10. // +----------------------------------------------------------------------
  11. // | github开源项目:https://github.com/zoujingli/Think.Admin
  12. // +----------------------------------------------------------------------
  13. namespace service;
  14. use think\Log;
  15. /**
  16. * Soap服务对象
  17. * Class SoapService
  18. * @package service
  19. */
  20. class SoapService
  21. {
  22. /**
  23. * SOAP实例对象
  24. * @var \SoapClient
  25. */
  26. protected $soap;
  27. /**
  28. * 错误消息
  29. * @var string
  30. */
  31. protected $error;
  32. /**
  33. * SoapService constructor.
  34. * @param string|null $wsdl WSDL连接参数
  35. * @param array $params Params连接参数
  36. * @throws \Exception
  37. */
  38. public function __construct($wsdl, $params)
  39. {
  40. set_time_limit(3600);
  41. if (!extension_loaded('soap')) {
  42. throw new \Exception('Not support soap.');
  43. }
  44. $this->soap = new \SoapClient($wsdl, $params);
  45. }
  46. /**
  47. * 属性获取转换
  48. * @param $name
  49. * @return string
  50. */
  51. public function __get($name)
  52. {
  53. switch (strtolower($name)) {
  54. case 'errmsg':
  55. return $this->getError();
  56. case 'errcode':
  57. return $this->getErrorCode();
  58. }
  59. return '';
  60. }
  61. /**
  62. * @param string $name SOAP调用方法名
  63. * @param array|string $arguments SOAP调用参数
  64. * @return array|string|bool
  65. * @throws \Exception
  66. */
  67. public function __call($name, $arguments)
  68. {
  69. try {
  70. return $this->soap->__call($name, $arguments);
  71. } catch (\Exception $e) {
  72. Log::error("Soap Error. Call {$name} Method --- " . $e->getMessage());
  73. return false;
  74. }
  75. }
  76. }