2014-12-05 105 views
2

我以Stripe Payment开始,需要将用户连接到我的Stripe应用程序。我按照Stripe的guildance用PHP代码来获取accesss_token:PHP - Stripe Connect返回null

// 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>"; 
} 

但是,从条纹的响应总是空。有没有人曾经遇到过类似的问题。这次任何帮助对我来说都非常有价值。

非常感谢。

回答

2

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

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