demo_wsclient_invoice.php-NORUN 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <?php
  2. /* Copyright (C) 2006-2010 Laurent Destailleur <eldy@users.sourceforge.net>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. */
  17. /**
  18. * \file htdocs/webservices/demo_wsclient_invoice.php
  19. * \brief Demo page to make a client call to Dolibarr WebServices "server_invoice"
  20. */
  21. // This is to make Dolibarr working with Plesk
  22. set_include_path($_SERVER['DOCUMENT_ROOT'].'/htdocs');
  23. require_once '../master.inc.php';
  24. require_once NUSOAP_PATH.'/nusoap.php'; // Include SOAP
  25. $WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_invoice.php';
  26. //$WS_DOL_URL = 'http://localhost:8080/'; // To test with Soapui mock. If not a page, should end with /
  27. $WS_METHOD1 = 'getInvoice';
  28. $WS_METHOD2 = 'getInvoicesForThirdParty';
  29. $ns='http://www.dolibarr.org/ns/';
  30. // Set the WebService URL
  31. dol_syslog("Create nusoap_client for URL=".$WS_DOL_URL);
  32. $soapclient1 = new nusoap_client($WS_DOL_URL);
  33. if ($soapclient1)
  34. {
  35. $soapclient1->soap_defencoding='UTF-8';
  36. $soapclient1->decodeUTF8(false);
  37. }
  38. $soapclient2 = new nusoap_client($WS_DOL_URL);
  39. if ($soapclient2)
  40. {
  41. $soapclient2->soap_defencoding='UTF-8';
  42. $soapclient2->decodeUTF8(false);
  43. }
  44. // Call the WebService method and store its result in $result.
  45. $authentication=array(
  46. 'dolibarrkey'=>$conf->global->WEBSERVICES_KEY,
  47. 'sourceapplication'=>'DEMO',
  48. 'login'=>'admin',
  49. 'password'=>'changeme',
  50. 'entity'=>'');
  51. // Test url 1
  52. if ($WS_METHOD1)
  53. {
  54. $parameters = array('authentication'=>$authentication,'id'=>1,'ref'=>'');
  55. dol_syslog("Call method ".$WS_METHOD1);
  56. $result1 = $soapclient1->call($WS_METHOD1,$parameters,$ns,'');
  57. if (! $result1)
  58. {
  59. print $soapclient1->error_str;
  60. print "<br>\n\n";
  61. print $soapclient1->request;
  62. print "<br>\n\n";
  63. print $soapclient1->response;
  64. exit;
  65. }
  66. }
  67. // Test url 2
  68. if ($WS_METHOD2)
  69. {
  70. $parameters = array('authentication'=>$authentication,'idthirdparty'=>'4');
  71. dol_syslog("Call method ".$WS_METHOD2);
  72. $result2 = $soapclient2->call($WS_METHOD2,$parameters,$ns,'');
  73. if (! $result2)
  74. {
  75. print $soapclient2->error_str;
  76. print "<br>\n\n";
  77. print $soapclient2->request;
  78. print "<br>\n\n";
  79. print $soapclient2->response;
  80. exit;
  81. }
  82. }
  83. /*
  84. * View
  85. */
  86. header("Content-type: text/html; charset=utf8");
  87. print '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">'."\n";
  88. echo '<html>'."\n";
  89. echo '<head>';
  90. echo '<title>WebService Test: '.$WS_METHOD1.'</title>';
  91. echo '</head>'."\n";
  92. echo '<body>'."\n";
  93. echo 'NUSOAP_PATH='.NUSOAP_PATH.'<br>';
  94. echo "<h2>Request:</h2>";
  95. echo '<h4>Function</h4>';
  96. echo $WS_METHOD1;
  97. echo '<h4>SOAP Message</h4>';
  98. echo '<pre>' . htmlspecialchars($soapclient1->request, ENT_QUOTES) . '</pre>';
  99. echo '<hr>';
  100. echo "<h2>Response:</h2>";
  101. echo '<h4>Result</h4>';
  102. echo '<pre>';
  103. print_r($result1);
  104. echo '</pre>';
  105. echo '<h4>SOAP Message</h4>';
  106. echo '<pre>' . htmlspecialchars($soapclient1->response, ENT_QUOTES) . '</pre>';
  107. print '<hr>';
  108. echo "<h2>Request:</h2>";
  109. echo '<h4>Function</h4>';
  110. echo $WS_METHOD2;
  111. echo '<h4>SOAP Message</h4>';
  112. echo '<pre>' . htmlspecialchars($soapclient2->request, ENT_QUOTES) . '</pre>';
  113. echo '<hr>';
  114. echo "<h2>Response:</h2>";
  115. echo '<h4>Result</h4>';
  116. echo '<pre>';
  117. print_r($result2);
  118. echo '</pre>';
  119. echo '<h4>SOAP Message</h4>';
  120. echo '<pre>' . htmlspecialchars($soapclient2->response, ENT_QUOTES) . '</pre>';
  121. echo '</body>'."\n";
  122. echo '</html>'."\n";
  123. ?>