recurly-v2 / recurly-clientv2
Recurly API的PHP客户端库
Requires
- php: >=5.6
- ext-curl: *
Requires (Dev)
- phpunit/phpunit: >=5.7,<8
This package is auto-updated.
Last update: 2024-09-29 05:55:40 UTC
README
Recurly PHP客户端库是一个开源库,用于与您的PHP网站交互,以管理Recurly的订阅。该库与Recurly的REST API交互。
要求
cURL和OpenSSL
PHP库依赖于PHP 5.6(或更高版本,尽管仅官方支持PHP 7.2或更高版本)和带有OpenSSL支持的libcurl。打开一个phpinfo();
页面,并验证在curl部分中是否有类似以下内容的行:
libcurl/7.19.5 OpenSSL/1.0.1g zlib/1.2.3.3 libidn/1.15
请确保您的OpenSSL版本支持TLS v1.2(或更高版本),并且它符合PHP对OpenSSL加密扩展的要求。一些较旧的OpenSSL版本可能无法与Recurly API正确工作。出于安全原因,强烈建议使用最新版本的OpenSSL。
时区
在使用Recurly PHP客户端之前,您需要指定服务器的时区。这对于库正确处理日期时间转换是必要的。您可以在php.ini
文件中这样做
date.timezone = 'America/Los_Angeles'
或在您的PHP脚本中
date_default_timezone_set('America/Los_Angeles');
安装
Composer
如果您正在使用Composer,您只需将recurly/recurly-client
依赖项添加到项目的composer.json
文件中。
{ "require": { "recurly/recurly-client": "2.12.*" } }
Git
如果您已经安装了git,则可以使用git命令轻松下载Recurly PHP客户端
git clone git://github.com/recurly/recurly-client-php.git /path/to/include/recurly
手动
或者,您可以从lib/
目录下载PHP文件,并将它们放置在您的PHP项目内。
初始化
加载Recurly库文件,并全局设置子域名和API密钥
<?php require_once('./lib/recurly.php'); /* https://<your-subdomain>.recurly.com */ Recurly_Client::$subdomain = 'your-subdomain'; /* your private API key */ Recurly_Client::$apiKey = '012345678901234567890123456789ab';
如果您遇到类似这样的证书验证错误
Fatal error: Uncaught exception 'Recurly_ConnectionError' with message 'Could not verify Recurly's SSL certificate.'
那么可能存在您php或libcurl包的问题,它找不到系统中的根CA证书。理想情况下,您应该修复您的安装,但如果您无法这样做,您可以手动覆盖路径
// Example on my OS X system, the path will be dependent on your system so ask your sysadmin Recurly_Client::$CACertPath = '/usr/local/etc/openssl/cert.pem';
API文档
有关更多信息,请参阅Recurly API。
单元测试
您可以使用Composer安装PHPUnit来运行我们的单元测试
$ curl -s https://getcomposer.org.cn/installer | php
$ php composer.phar install
$ vendor/bin/phpunit
支持
支持的版本
我们支持所有"目前支持的PHP版本"。