hampel / synergy-wholesale
使用 SoapClient 的 Synergy Wholesale API 包装器
Requires
- php: >=5.4.0
- psr/log: ~1.0
Requires (Dev)
- mockery/mockery: ~1.0
- phpunit/phpunit: ^8.0|^9.0
README
使用 SoapClient 的 Synergy Wholesale API 包装器
由 Simon Hampel 编写
安装
要使用 composer 安装,请运行以下命令
composer require hampel/synergy-wholesale
注意,如果您打算使用此软件包与 Laravel 结合,我们建议安装 hampel/synergy-wholesale-laravel 软件包,它提供了一个简单的 Laravel 服务提供者和 Facade,以便与该 API 包装器一起工作。Laravel 版本也会自动链接到 Laravel 日志系统,使跟踪 API 问题变得容易。
用法
您需要在 Synergy Wholesale 控制面板中开启 API 访问,这将告诉您您的 Reseller ID。您还需要将您的 Web 服务器 IP 地址添加到 IP 白名单中,以启用 API 密钥。
将 Reseller ID 和 API 密钥作为参数传递给 SynergyWholesle 构造函数。
您可以选择指定一个使用 psr/log 接口的日志实现(例如 Monolog),这将允许将 API 调用和响应记录下来,以便进行调试和错误跟踪。
此 API 包装器提供了丰富的面向对象接口,用于 API 调用,使用值对象构造输入,以提供对输入数据的细致验证。
API 的原始响应是包含具有响应值的公共属性的 stdClass 对象。此包装器处理和验证这些响应,并为访问返回数据提供了更丰富的接口。
在出现错误时抛出异常。
长格式初始化示例
// start by creating a SoapClient with the location of the WSDL file supplied by Synergy Wholesale $client = new SoapClient(null, array('location' => SynergyWholesale::WSDL_URL, 'uri' => '')); // create a Response generator (the engine which maps command objects to response objects) $responseGenerator = new \SynergyWholesale\BasicResponseGenerator(); // now we can build our command execution engine, pass "null" for the logger if we don't have one $sw = new \SynergyWholesale\SynergyWholesale($client, $responseGenerator, null, "reseller_id", "api_key");
静态工厂示例
// does all the heavy lifting for you if you don't need a logger $sw = \SynergyWholesale\SynergyWholesale::make("reseller_id", "api_key");
余额查询命令示例
// create a command object for the SynergyWholesale service to execute $command = new BalanceQueryCommand(); // no parameters required for this call! // execute the command try { $response = $sw->execute($command); } catch (Exception $e) { // different exceptions are thrown on different types of errors // you can be as coarse or as granular as you like with error handling exit("Error executing command: " . $e->getMessage()); } echo "Account balance: " . $response->getBalance();
域名信息命令示例
// need to create a Domain object first try { $domain = new \SynergyWholesale\Types\Domain('example.com'); } catch (\SynergyWholesale\Exception\InvalidArgumentException $e) { exit("Error building domain object: " . $e->getMessage()); } // pass this as a parameter to the command $command = new DomainInfoCommand($domain); // execute the command try { $response = $sw->execute($command); } catch (Exception $e) { exit("Error executing command: " . $e->getMessage()); } echo " // check availability of a domain for registration $command = new CheckDomainCommand('example.com'); $response = $sw->execute($command); var_dump($response);
备注
只有域名和 SMS API 调用已经实现
待办事项
- 实现 SynergyWholesale API 的所有其他调用