Install the libraries required to generate the WSDL with composer
Composer require Piotrooo/wsdl-creator
- The
-
Implements a portal file for external access, and the code example refers to a class name that appears in the method name and parameter in Notify
, and the method of that class becomes the external interface that can be called by SOAP):
<?phpuse wsdl\documentliteralwrapper;use wsdl\wsdlcreator;use Wsdl\xml\styles\documentliteralwrapped;class Api {public static function soapnotify () {$host = $_server[' http_host '); $soapuri = "http://{$host}/api/soapnotify"; if (Isset ($_get[' WSDL '))) {$wsdl = new Wsdlcreator (' Notify ', $soapuri); $WSDL->renderwsdl (); Exit } $server = new SoapServer (null, [' uri ' = = $soapuri]); $server->setclass (' Notify '); $server->handle (); }}
To implement a class file that contains the interface's functional logic, please refer to the code example (where the annotation of the method is very important and is the basis for wsdl-creator to correctly generate the WSDL, which must be commented in strict format):
Class notify{ /** * @desc sendText send text message to patient * @param string $toUser to which user * @param string $content sent within Capacity * @return string $result * /Public Function SendText ($toUser, $content) { if (! $toUser | |!$ Content) { return e::invalid; } $user = G::xpdo ()->row ("Select * from ' users ' WHERE ' patientid ' =?", [$toUser]); if (! $user) { return e::nodata; } $api = G::xpdo ()->row ("SELECT * from ' API ' WHERE ' token ' =? ', [$user [' token ']]); $weixin = new Weixin ($api [' AppID '], $api [' Appsecret ']); $weixin->sendtext ($user [' OpenID '], $content); return 0;} }
Debugging an interface using the SoapUI software
Preparing the appropriate interface invocation documentation
Resources:
- For the basic document structure of SOAP, refer to http://www.sitepoint.com/series/creating-web-services-with-php-and-soap/]
- About the library that generates the WSDL wsdl-creator see: Https://github.com/piotrooo/wsdl-creator
Implementing SOAP with WSDL in PHP