'2000',
"currency"=>'usd',
"source"=>$token,
"metadata[order_id]"=>'6735',
);
$i = 0;
foreach ($data as $k=>$v){
$v = urlencode(stripslashes($v));
if($i==0){
$req .= "{$k}={$v}";
}else{
$req .= "&{$k}={$v}";
}
$i++;
}
$username = 'sk_test_BQokikJOvBiI2HlWgH4of2';
$cert = 'ca-certificates.crt';
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$req);
//curl_setopt($ch, CURLOPT_USERNAME, "sk_test_BQokikJOvBi2HlWgH4olfQ2:");
//curl_setopt($ch, CURLOPT_USERPWD,"sk_test_BQokikJOvBi2HlWgH4olfQ2:");
//curl_setopt($ch, CURLOPT_USERPWD, base64_encode("sk_test_BQokikJOBiI2HlWgH4olfQ2:"));
//curl_setopt($ch, CURLOPT_USERNAME, base64_encode("{$username}:"));
// curl_setopt($curl, CURLOPT_USERPWD, $matches['user'].':'.$matches['pass']);
//curl_setopt($ch,CURLOPT_USERNAME,$username.':');
//curl_setopt($ch, CURLOPT_CAINFO, $cert);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/x-www-form-urlencoded'
,'Authorization: Bearer '.$username
));
$res = curl_exec($ch);
$error = curl_error($ch);
curl_close($ch);
var_dump($res);
var_dump($error);
exit;
}
test();
?>
要点:
'Authorization: Bearer '.$username
标准的请求用户头授权方式为Authorization: Basic
curl_setopt($ch,CURLOPT_USERNAME,$username.':');我估计这种方式本来是好用的,因为stripe修改了Basic所以无效了。必须使用Header头
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
禁止HTTPS 认证,这样就可以省掉本地认证文件,否则就得加载认证文件
You must be logged in to post a comment.
博主你好,博主好人