首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >401未经授权使用Adyen API

401未经授权使用Adyen API
EN

Stack Overflow用户
提问于 2018-04-02 20:37:19
回答 3查看 4.3K关注 0票数 3

我正试图在我的测试环境中用curl支付一笔费用,但出于某种原因,我一直得到401次未经授权的回复。我已经检查了Web服务用户的凭证十几次,但我确信它们是正确的。当我尝试正式的Adyen库(https://github.com/Adyen/adyen-php-api-library)时,我得到了相同的结果。我也尝试过创建一个新的Web服务用户,但是没有结果。有人知道我做错了什么吗?

请求代码:

代码语言:javascript
复制
<?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变量返回一个空字符串。

响应:

代码语言:javascript
复制
*   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
EN

回答 3

Stack Overflow用户

发布于 2018-04-02 22:22:22

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

您可以选择为一般API使用或POS支付生成密码。确保如果打算将这个API用户用于一般API,请使用"Generate“和而不是 "Generate密码”。

票数 2
EN

Stack Overflow用户

发布于 2020-07-03 15:26:37

状态: 401与errorCode: 000一起使用是一个典型的错误,因为以下情况可能不正确:

  • 使用正确的merchantAccount名称而不是companyAccount名称
  • API键-最好重新生成API键并使用customer区域中的复制按钮来复制它。
  • 设置为活动/测试的环境
票数 2
EN

Stack Overflow用户

发布于 2018-04-03 08:33:42

好了,现在起作用了。奇怪的是我什么都没改变。我猜Adyen在他们这边有麻烦。下次有类似事情发生时我会给他们打电话的。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49618442

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档