CURL未在PHP中执行

时间:2019-04-02 16:25:57

标签: php curl oauth stripe-payments php-curl

我将POST请求中的参数传递给了应该运行Stripe cURL请求的PHP后端。问题是cURL请求无法正常工作。

我确保cURL已安装在Apache服务器上。但是,不执行Stripe的URL。

PHP

<?php
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
header("Access-Control-Allow-Methods: POST");
header("Access-Control-Allow-Headers", "Access-Control-Allow-Headers, Origin,Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers");
require_once("../../src/backend/php/init.php");
require_once('../../../../vendor/autoload.php');

$stripe = [
 "secret_key"      => "******************"
];

\Stripe\Stripe::setApiKey($stripe["secret_key"]);

$value = json_decode(file_get_contents("php://input"),true);
$code =  $value['code'];
echo json_encode($code);
$code = json_encode($code);

// output: CURL IS available
 if(in_array  ('curl', get_loaded_extensions())) {
     echo "CURL is available on your web server";
 }
 else{
     echo "CURL is not available on your web server";
 }

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'https://connect.stripe.com/oauth/token');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "client_secret=". $stripe["secret_key"]. "&code=". $code . "&grant_type=authorization_code");
curl_setopt($ch, CURLOPT_POST, 1);

$headers = array();
$headers[] = 'Content-Type: application/x-www-form-urlencoded';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);
if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
}else {
    echo json_encode("success");
}
curl_close ($ch);
?>

0 个答案:

没有答案