用 composer 安装生成 wsdl 所需的库
composer require piotrooo/wsdl-creator
实现用于外部访问的入口文件,代码示例请参考(其中方法名和参数中出现的 notify 对应一个类名,该类的方法将成为可以通过 soap 调用的外部接口):
renderwsdl(); exit; } $server = new soapserver(null, [ 'uri' => $soapuri ]); $server->setclass('notify'); $server->handle(); }}
实现包含接口功能逻辑的类文件,代码示例请参考(其中方法的注释相当重要,是 wsdl-creator 正确生成 wsdl 的依据,必须严格按照格式进行注释):
class notify{ /** * @desc sendtext 向患者的微信发送文本信息 * @param string $touser 发给哪个用户 * @param string $content 发送的内容 * @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; }}
使用 soapui 软件对接口进行调试
编制相应的接口调用说明文档
参考资料:
了解 soap 的基本文档结构请参考 http://www.sitepoint.com/series/creating-web-services-with-php-and-soap/] 关于生成 wsdl 的库 wsdl-creator 详见: https://github.com/piotrooo/wsdl-creator