advancedideasmechanics / api-client
与 DotKernel 一起工作的 API 服务
Requires
- php: ~8.2.0 || ~8.3.0 || ~8.4.0
- guzzlehttp/guzzle: ^7.9.2
Requires (Dev)
This package is auto-updated.
Last update: 2024-10-03 01:28:50 UTC
README
这是一个主要用于与 DotKernel API 一起工作的 API 客户端。https://github.com/dotkernel/api
当前不稳定
安装
通过 composer 安装
Composer
composer install advancedideasmechanics/apiclient
调用包
初始化
$apiclient = new ApiClient(baseurl, clientId, clientSecret, grantType, scope, userName, userSecret, tokenLocation, tokenFilename, debug, additionalParams);
检查是否工作,如果 API 调用工作正常,将在您选择的位置创建一个 tokenFilename。如果尚未创建,请创建位置路径。
测试
$apiclient->getAccessToken();
向 API 发送数据
$apiclient->makeApiRequest($endpoint, $body, $method = "GET", $additionalHeaders = []);
初始化详细信息
以下使用了一些 DotKernel 默认值。在生产环境中不要使用这些值。
baseurl = https://:8083
clientId = frontend
# DotKernel 默认
clientSecret = frontend
# DotKernel 默认
grantType = password
scope = api
# DotKernel 默认(您可以保留此值)
userName = test@dotkernel.com
# DotKernel 默认
userSecret = dotkernel
# DotKernel 默认
tokenLocation = /var/www/data/
# 保持在外部 web 文件夹外
tokenFilename = token.json
# 可以是您希望的任何文件名。
debug = false
# 可选,默认为 false,这是用于 guzzle 记录日志到文件。
additionParms = []
# 可选 Guzzle 参数。
发送/检索到 API
endpoint = /someapiendpoint
# 从 baseurl 的根开始
body = []
# 将作为 json_encoded() 发送到 API 的信息数组。如果使用 GET,则可以是 []。
method = GET
# 默认为 GET,但可以是端点接受您设置的任何动词
addtionalHeader = []
# 可选的 Guzzle 标头