php - ADP API 无法通过 SSL 错误

标签 php api ssl xampp

我有一个 ADP SSL key 、pem、pfx、csr。我正在尝试使用 Xampp 服务器从我的本地计算机进行连接。

对于我来说,我无法克服这个错误: “无法使用客户端证书(未找到 key 或密码短语错误?)”。

通过在 MS 管理控制台中安装 .pfx 文件,我能够让 Google Postman 使用 ADP API。

我是否需要将这些文件安装在 Xampp 服务器本身的某处?

我在应用程序中有一个文件夹,用于存储我指向的 .key 和 .pem 文件。

欢迎任何见解。

$auth = array();
$auth['cert'] = "/certs/xxxxxxxxxxxxxxx.pem";
$auth['key'] = "/certs/xxxxxxxxxxxxxxxx.key";
$auth['user'] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";

$postfields = array(
   "grant_type" => "client_credentials"
);

$ch = curl_init();
curl_setopt_array($ch, array(
   CURLOPT_URL => "https://api.adp.com/auth/oauth/v2/token",
   CURLOPT_SSLCERT => $auth['cert'],
   CURLOPT_SSLKEY => $auth['key'],
   CURLOPT_USERPWD => $auth['user'],
   CURLOPT_RETURNTRANSFER => 1,
   CURLOPT_POSTFIELDS => http_build_query($postfields, '', '&')
));

$auth['token'] = curl_exec($ch);
curl_close($ch);

$response = json_decode($auth['token'], true);


$_SESSION['bearer'] = $response['access_token'];

$ch = curl_init();

curl_setopt_array($ch, array(

   CURLOPT_URL => 'https://api.adp.com/hr/v1/corporate-contacts' ,
   CURLOPT_SSLCERT => $auth['cert'],
   CURLOPT_SSLKEY => $auth['key'],
   CURLOPT_RETURNTRANSFER => 1,
   CURLOPT_HTTPHEADER => array(
   'Accept: application/json',
   'Authorization: Bearer ' . $auth['token']
)

));
$data = curl_exec($ch);

if(!$data)
    print_r('ERROR: ' . curl_error($ch));
else
    print_r('SUCCESS: ' . curl_error($ch));

curl_close($ch);

最佳答案

.. I cannot get past this error: "unable to use client certificate (no key found or wrong pass phrase?)".

我不了解 ADP API,但错误消息表明要么找不到 key (您声称它在那里),要么没有正确的权限(网络服务器可读吗?),要么格式不正确(应以 -----BEGIN RSA PRIVATE KEY----- 等开头)或者您有此 key 的密码短语但您提供了错误的密码或没有密码.查看代码,我发现您提供了证书和 key 但没有密码:

CURLOPT_SSLCERT => $auth['cert'],
CURLOPT_SSLKEY => $auth['key'],
CURLOPT_USERPWD => $auth['user'],

如果密码完全丢失,我不知道您是否尝试错误地使用 CURLOPT_USERPWD 来提供密码,但是要添加您需要使用 CURLOPT_KEYPASSWD .

关于php - ADP API 无法通过 SSL 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36602948/

相关文章:

php - 通过更新多行删除不需要的内容

PHP imap_fetchbody 无法获取 HTML a 标签链接 url

Azure 网站 - 共享计划和 SSL(又名 HTTPS)

python - 在 Python 中读取证书

javascript - 使用 javascript 或 php 发送 post 请求

ubuntu - letsencrypt ssl 安装快捷方式

php - 如何将多个语句循环合二为一? (性能概率/PHP)

php - Facebook 喜欢状态 url 检测

azure - Azure 函数的出站 IP 地址

java - 我可以使用 Fitbit Api 获取我的 Fitbit 的加速度数据吗?