我从 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/