【问题标题】:401 Unauthorized on Adyen API401 在 Adyen API 上未经授权
【发布时间】:2018-09-12 02:14:22
【问题描述】:

我正在尝试使用 curl 在 Adyen 的测试环境中进行付款,但由于某种原因,我不断收到 401 Unauthorized 响应。我已经检查了十多次 Web 服务用户的凭据,但我确信它们是正确的。当我尝试使用官方 Adyen PHP Api 库 (https://github.com/Adyen/adyen-php-api-library) 时,我得到了相同的结果。我也尝试过创建一个新的 Web 服务用户,但没有结果。有谁知道我做错了什么?

请求代码:

<?php

$request = array(
    "merchantAccount" => "MyWebsite",
    "amount" => array(
        "currency" => "EUR",
        "value" => "199"
    ),
    "reference" => "TEST-PAYMENT-" . date("Y-m-d-H:i:s"),
    "shopperIP" => "2.207.255.255",
    "shopperReference" => "YourReference",
    "billingAddress" => array(
        "street" => "Simon Carmiggeltstraat",
        "postalCode" => "1011DJ",
        "city" => "Amsterdam",
        "houseNumberOrName" => "6-60",
        "stateOrProvince" => "NH",
        "country" => "NL"
    ),
    "card" => array(
        "expiryMonth" => "08",
        "expiryYear" => "2018",
        "holderName" => "Test Card Holder",
        "number" => "4111111111111111",
        "cvc" => "737"
    ),
);

$json = json_encode($request);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://pal-test.adyen.com/pal/servlet/Payment/v25/authorise");
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC  );
curl_setopt($ch, CURLOPT_USERPWD, "xxxx:xxxx");
curl_setopt($ch, CURLOPT_POST, count($request));
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER,array("Content-type: application/json"));

// things I tried
curl_setopt($ch, CURLOPT_USERAGENT,'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.52 Safari/537.17');
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);

$result = curl_exec($ch);

?>

$result 变量返回一个空字符串。

回应:

*   Trying 91.212.42.153...
* Connected to pal-test.adyen.com (91.212.42.153) port 443 (#0)
* ALPN, offering http/1.1
* Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
* successfully set certificate verify locations:
*   CAfile: /etc/ssl/certs/ca-certificates.crt
  CApath: /etc/ssl/certs
* SSL connection using TLSv1.2 / ECDHE-RSA-AES128-GCM-SHA256
* ALPN, server did not agree to a protocol
* Server certificate:
*    subject: C=NL; ST=Noord-Holland; L=Amsterdam; O=Adyen B.V.; CN=*.adyen.com
*    start date: Jun 14 00:00:00 2016 GMT
*    expire date: Aug 13 23:59:59 2018 GMT
*    issuer: C=US; O=thawte, Inc.; CN=thawte SSL CA - G2
*    SSL certificate verify ok.
* Server auth using Basic with user 'xxxxx'
> POST /pal/servlet/Payment/v25/authorise HTTP/1.1
Host: pal-test.adyen.com
Authorization: Basic xxxxxx
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.52 Safari/537.17
Accept: */*
Content-type: application/json
Content-Length: 465

* upload completely sent off: 465 out of 465 bytes
< HTTP/1.1 401 Unauthorized
< Date: Mon, 02 Apr 2018 19:58:11 GMT
< Server: Apache
< Set-Cookie: JSESSIONID=47E667BF9B585DC3BDF40F8D58493E23.test103e; Path=/pal; Secure; HttpOnly
* Authentication problem. Ignoring this.
< WWW-Authenticate: BASIC realm="Adyen PAL Service Authentication"
< Content-Length: 0
< Content-Type: text/plain; charset=UTF-8
< 
* Connection #0 to host pal-test.adyen.com left intact

【问题讨论】:

  • 您现在需要重设密码。还要删除响应中的基本身份验证标头,基本身份验证只是用户/通行证 base64'ed,这意味着您的用户和通行证现在已受到损害。
  • @luke_b 我​​已重置密码并更改了帖子。它是一个空的测试环境,所以不用担心,感谢您的关注。

标签: php curl adyen


【解决方案1】:

Status: 401 with errorCode: 000 是一个典型错误,因为以下可能不正确:

  • 使用正确的商家帐户名称而不是公司帐户名称
  • API 密钥 - 最好重新生成 API 密钥并使用客户区的复制按钮进行复制
  • 环境设置为 LIVE/TEST

【讨论】:

    【解决方案2】:

    好的,现在可以了。奇怪的是我没有改变任何东西。我的猜测是 Adyen 在他们这边遇到了麻烦。下次有类似情况我会打电话给他们的。

    【讨论】:

      【解决方案3】:

      401 身份验证失败。您没有使用正确的用户 + 密码组合。

      您可以选择为一般 API 使用或 POS 支付生成密码。确保如果打算将此 API 用户用于通用 API,请使用“生成密码”和“生成 POS 密码”。

      【讨论】:

      • 我已经重置了“生成密码”和“生成 POS 密码”,它们没有任何区别。我还多次检查了用户密码组合,我确定它们是正确的。这就是整个问题。
      • Adyen 示例的文档 (github.com/Adyen/adyen-php-sample-code/blob/master/2.API/…) 说,如果您符合 PCI 标准,则只能提出付款请求,这是否也适用于测试环境?
      • 对该文件的注释不正确。使用未加密的卡详细信息需要 PCI 合规性。您正在使用的示例使用原始卡详细信息,因此您需要 adyen 的支持才能为您启用它。但是,如果您不符合 pci 标准,为什么还要对其进行测试?
      猜你喜欢
      • 2019-03-07
      • 2017-09-27
      • 2014-01-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多