【问题标题】:PHP - Stripe Connect return nullPHP - 条纹连接返回 null
【发布时间】:2015-02-03 10:26:13
【问题描述】:

我从 Stripe Payment 开始,需要将用户连接到我的 Stripe 应用。我按照Stripe 中的指导使用 PHP 代码获取 accesss_token:

// See full code example here: https://gist.github.com/3507366

if (isset($_GET['code'])) { // Redirect w/ code
  $code = $_GET['code'];

  $token_request_body = array(
    'grant_type' => 'authorization_code',
    'client_id' => 'ca_*************************',
    'code' => $code,
    'client_secret' => 'sk_test_************************'
  );

  $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);
  $resp = json_decode(curl_exec($req), true);
  curl_close($req);

  echo $resp['access_token'];
} else if (isset($_GET['error'])) { // Error
  echo $_GET['error_description'];
} else { // Show OAuth link
  $authorize_request_body = array(
    'response_type' => 'code',
    'scope' => 'read_write',
    'client_id' => 'ca_************************'
  );

  $url = AUTHORIZE_URI . '?' . http_build_query($authorize_request_body);
  echo "<a href='$url'>Connect with Stripe</a>";
}

但来自 Stripe 的响应始终为空。以前有没有人遇到过类似的问题。这次任何帮助对我来说都是非常有价值的。

非常感谢。

【问题讨论】:

    标签: php codeigniter stripe-payments


    【解决方案1】:

    经过一段时间的调试,我发现问题出在我的 PHP 服务器的 cURL 库上。似乎 cURL 不适用于 HTTPS。并基于此线程:PHP cURL Not Working with HTTPS 我找到了绕过验证使其运行的解决方案:

    ...
    curl_setopt($req, CURLOPT_POSTFIELDS, http_build_query($token_request_body));
    curl_setopt($req, CURLOPT_SSL_VERIFYPEER, false); // Bypass the verification
    $resp = json_decode(curl_exec($req), true); // Now has response well.
    ...
    

    P/s:这不是一个好的解决方案,最好多研究一下 (here)

    我希望这对像我这样的初学者有帮助:)

    【讨论】:

      猜你喜欢
      • 2014-12-29
      • 2020-12-09
      • 2023-03-26
      • 2020-08-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-04
      • 2017-01-01
      相关资源
      最近更新 更多