adpmarketplace / api-connection
该软件包的规范仓库似乎已消失,因此该软件包已被冻结。
Requires
- php: >=5.3.0
- adpmarketplace/api-module-installer-plugin: *
This package is not auto-updated.
Last update: 2022-06-04 00:58:55 UTC
README
为了使用此库,您需要满足一些先决条件
- 用您从 CSR工具 收到的证书替换此库中的证书
- 使用凭证文档PDF中提供的客户端ID和客户端密钥更新客户端ID和客户端密钥
- 将端点从
https://iat-api.adp.com
和https://iat-accounts.adp.com
更新到https://api.adp.com
和https://accounts.adp.com
。
ADP Client Connection Library for PHP
ADP Client Connection Library旨在简化并协助对ADP Marketplace API网关进行身份验证、授权和连接的过程。该库包含一个示例应用程序,可以立即运行以连接到ADP Marketplace API 测试网关。
版本
1.0.3
安装
Composer
从您希望用作项目根目录的位置使用Composer。
$ composer require adpmarketplace/api-connection
这将安装连接模块到您的项目。如果您想构建示例客户端,请执行以下操作
$ cd adplib/connection/tools
$ php makeclient.php
如果您想立即测试,请复制并粘贴由makeclient.php脚本生成的正确命令。如果您错过了它们,也可以这样做
(from the project root)
$ cd client
$ php -S 127.0.0.1:8889
这将在一个端口上启动HTTP服务器(此端口必须未使用才能运行示例应用程序)。
运行示例应用程序
请注意,要测试示例应用程序,您必须首先运行makeclient.php脚本,然后按照上面概述的方式启动PHP服务器。
完成后,打开您的网络浏览器并转到
https://:8889
示例应用程序允许您使用 client_credentials 和 authorization_code 授权类型连接到ADP测试API网关。对于 authorization_code 连接,您将被要求提供ADP用户名(MKPLDEMO)和密码(marketplace1)。
示例
创建客户端凭据ADP连接
require_once ("config.php"); // Contains settings require_once ($libroot . "connection/adpapiConnection.class.php"); //---------------------- // Create Config Array //---------------------- $configuration = array ( 'grantType' => 'client_credentials', 'clientID' => $ADP_CC_CLIENTID, 'clientSecret' => $ADP_CC_CLSECRET, 'sslCertPath' => $ADP_CERTFILE, 'sslKeyPath' => $ADP_KEYFILE, 'tokenServerURL' => $ADP_APIROOT ); //---------------------- // Create the class //---------------------- try { $adpConn = adpapiConnectionFactory::create($configuration); } catch (adpException $e) { showADPException($e); exit(); } //------------------------------------------- // Request a token for API access //------------------------------------------- try { $result = $adpConn->Connect(); } catch (adpException $e) { showADPException($e); exit(); }
创建授权码ADP连接
授权码需要2个部分。第一部分处理向网关发送的请求URI的创建。第二部分处理网关的响应,并使用它检索访问令牌。
生成请求URI
require_once ("config.php"); // Contains settings require_once ($libroot . "connection/adpapiConnection.class.php"); //---------------------- // Create Config Array //---------------------- $configuration = array ( 'grantType' => 'authorization_code', 'clientID' => $ADP_AC_CLIENTID, 'clientSecret' => $ADP_AC_CLSECRET, 'sslCertPath' => $ADP_CERTFILE, 'sslKeyPath' => $ADP_KEYFILE, 'tokenServerURL' => $ADP_APIROOT, 'scope' => 'openid', 'responseType' => 'code', 'redirectURL' => $ADP_REDIRECTURL ); //---------------------- // Create the class //---------------------- try { $adpConn = adpapiConnectionFactory::create($configuration); } catch (adpException $e) { showADPException($e); exit(); } //----------------------------------------------- // Request an authentication URL from Connection //----------------------------------------------- try { $result = $adpConn->getAuthRequest(); } catch (adpException $e) { showADPException($e); exit(); } //----------------------------------------------- // Send the browser to the generated URI //----------------------------------------------- header("Location: " . $result);
第二部分,当网关返回时
require ($webroot . "config.php"); require ($libroot . "connection/adpapiConnection.class.php"); // Check to see if there is an error if (isset($_GET['error'])) { echo "<h1>Gateway Error</h1>"; echo "<div class='alert alert-danger'>\n"; echo "The error returned is: " . $_GET['error']; echo "</div>\n"; exit(); } // Get the authorization code, if available. $retcode = $_GET['code']; // restore session object from session. Handle sessions the way you see fit. $adpConn = unserialize($_SESSION['adpConn']); //-------------------------------------------------- // Add the returned code to the connection object //-------------------------------------------------- $adpConn->auth_code = $retcode; //------------------------------------------- // Request a token for API access //------------------------------------------- try { $result = $adpConn->Connect(); } catch (adpException $e) { showADPException($e); exit(); }
API文档
库提供的单个API调用文档在“doc”文件夹中。在浏览器中打开index.html文件以查看文档。
依赖项
此库有以下依赖项。
- PHP版本需≥v5.3,且支持CURL。如果您使用的是OSX系统,这意味着您需要重新编译PHP以支持CURL。
- composer
测试
我们的测试和代码覆盖率是通过PHPUNIT处理的,您必须安装PHPUNIT来运行测试。为了使代码覆盖率功能正常工作,您还必须安装Xdebug。测试单元位于“test”文件夹中,配置已加载到phpunit.xml中。为了运行测试和查看代码覆盖率
phpunit
代码检查器
您必须使用PHP内置的代码检查器来验证代码结构
php -l <sourcefile>
贡献
要为此库做出贡献,请生成一个pull request。在生成pull request之前,请确保以下事项
- 已更新或创建了适当的单元测试。
- 单元测试的代码覆盖率必须不少于95%。
- 您的代码更新已经过全面测试,并且通过代码检查,没有错误。
- 根据需要更新README.md和API文档。
许可
此库可在Apache 2许可下使用(https://apache.ac.cn/licenses/LICENSE-2.0)。