kwri / kwapi-wrapper
此软件包已被废弃,不再维护。未建议替代软件包。
kwapi 客户端库
v1.1.0
2017-02-15 19:06 UTC
Requires
- php: ^5.4|^7.0
- guzzlehttp/guzzle: ~5.3|~6.0
Requires (Dev)
- mockery/mockery: ~0.8
- phpunit/phpunit: ~4.0
This package is not auto-updated.
Last update: 2020-01-24 16:22:52 UTC
README
此仓库包含PHP和JS库,允许您从PHP应用程序访问KW-API平台。
PHP库
安装
可以使用Composer安装此库。运行以下命令:
composer require kwri/kwapi-wrapper
使用方法
// Use old method (apiKey header) $credential = new KWApi\Models\Credential("yourApiKey"); $credential->setEndPoint("http://kw-api.dev/v1/"); $service = new KWApi\KWApi($credential); // Use new method (OpenID connect) // Token data $tokenType = 'bearer'; $accessToken = md5(time()); $refreshToken = md5(time()+1); $expiresIn = 24*3600; // User info data $kwUid = '999'; $email = 'pholenkadi17@gmail.com'; $company = 'Refactory'; $appName = 'KW-CRM'; $token = new KWAPI\Models\OpenIDToken($tokenType, $accessToken, $refreshToken, $expiresIn); $userInfo = new KWAPI\Models\OpenIDUserInfo($kwUid, $email, $company, $appName); $credential = new KWAPI\Models\OpenIDCredential($clientId, $token, $userInfo); $credential->setEndPoint("http://kw-api.dev/v1/"); $service = new KWApi\KWApi($credential); $response = $service->event()->browse();
测试
- 在本地开发中启动KW-Api服务
- 将
tests/config.php.dist
复制到tests/config.php
并设置您的凭证值 - 可以通过运行以下命令执行测试:
./vendor/bin/phpunit --coverage-text
JS库
安装
要使用此库,请将此仓库克隆到您的本地机器。
使用方法
// Use old method (apiKey header) const BasePath = 'Your/Path/lib/' const Credential = require(BasePath + 'KWApi/Models/Credential') const KWAPI = require(BasePath + 'KWApi/') const credential = new Credential(apiKey) // There are several services that can be used, please refer at Services dir const ApiUser = new KWAPI(credential) // Use new method (OPENID Connect) // Token data const tokenType = 'Bearer' const accessToken = md5(new Date()) const refreshToken = md5(Math.floor(Date.now() / 1000) + 1) const expiresIn = 24 * 3600 // setUpOpenID const OpenIDToken = require(BasePath + 'KWApi/Models/OpenIDToken') const OpenIDUserInfo = require(BasePath + 'KWApi/Models/OpenIDUserInfo') const OpenIDCredential = require(BasePath + 'KWApi/Models/OpenIDCredential') // You can set the clientId as you type const clientId = "98jjhury866" const KWAPI = require(BasePath + 'KWApi/') const token = new OpenIDToken(tokenType, accessToken, refreshToken, expiresIn) const userInfo = new OpenIDUserInfo(kwUid, email, company, appName) const credential = new OpenIDCredential(clientId, token, userInfo) credential.setEndPoint(endPoint) const KwApi = new KWAPI(credential)
测试
- 在本地开发中启动KW-API服务器
- 可以在您的终端上运行
npm test
来执行测试