【问题标题】:on curl "connect.stripe.com/oauth/token" it will get no response在 curl "connect.stripe.com/oauth/token" 上它不会得到响应
【发布时间】:2015-12-17 01:06:30
【问题描述】:

https://connect.stripe.com/oauth/authorize?response_type=code&client_id=ca_XXXXXXXXXXXXXXXXXXXXXX&scope=read_write

从上面提到的 api 我得到了代码。

$code = $_GET['code'];

从这段代码中,我将这个http://connect.stripe.com/oauth/token 卷曲,但问题是它没有得到任何响应

     echo $code;

$token_request_body = array(
    'grant_type' => 'authorization_code',
    'client_id' => 'ca_xxxxxxxxxxxxxxxxxxxxx',
    'code' => $code,
    'client_secret' => 'XXXXXXXXXXXXXXXXXXX'
);

define("TOKEN_URI", "http://connect.stripe.com/oauth/token");

$req = curl_init(TOKEN_URI);
curl_setopt($req, CURLOPT_RETURNTRANSFER, true);
curl_setopt($req, CURLOPT_POST, true);
curl_setopt($req, CURLOPT_POSTFIELDS, http_build_query($token_request_body));

// TODO: Additional error handling
$respCode = curl_getinfo($req, CURLINFO_HTTP_CODE);
echo $respCode;
$resp = json_decode(curl_exec($req), true);
echo $resp;
curl_close($req);

echo $resp['access_token'];

【问题讨论】:

  • 使用 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);并检查
  • 1 是否还有其他含义??我使用 true 作为第三个参数.. 所以两者是否相同??
  • @satishrajak 没用,我改成了 1
  • @satishrajak 我不认为它是如何卷曲请求的问题,因为我已经多次使用 curl,问题是我猜想是条纹 api,我说得对吗,代码完全执行

标签: php curl stripe-payments


【解决方案1】:

您的代码通过纯 HTTP 将 code 发送到端点,这是规范禁止的,服务器不应返回令牌。 stripe.com 上的示例代码还显示了一个 HTTPS URL。开关:

define("TOKEN_URI", "http://connect.stripe.com/oauth/token");

到:

define("TOKEN_URI", "https://connect.stripe.com/oauth/token");

FWIW:纯 HTTP URL 实际上重定向到 HTTPs,这是您的客户端无法处理的,它不应该处理,因为它不安全并且违反规范。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-09
    • 2014-09-29
    • 2021-06-30
    • 2016-08-07
    • 2018-02-24
    相关资源
    最近更新 更多