PHP - Stripe Connect 返回 null

标签 php codeigniter stripe-payments

我从 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 的响应始终为空。有没有人遇到过类似的问题。这次任何帮助对我来说都非常有值(value)。

非常感谢。

最佳答案

经过一段时间的调试,我发现问题出在我的 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 )

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

关于PHP - Stripe Connect 返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27312699/

相关文章:

php - 正则表达式 - 根据标点符号/空格将字符串拆分为数组

javascript - 在 codeigniter 的数据表中弹出框

php - 如何使用 codeigniter 生成 5 位字母数字唯一 ID?

reactjs - 组件的 NextJS/Script — defer Stripe

javascript - 无法使用 session 更新信用卡

php - 将 flv 与 mp3 合并,而不使用 FFMPEG 替换 flv 音频流

javascript - JQuery load() 无法识别 pre php 包含内容

php - 多行的 SQL 语法

php - codeigniter 的 session 问题

rest - Stripe API - 收据列表