java多线程    Java入门    vsftp    ftp    linux配置    centos    FRP教程    HBase    Html5缓存    webp    zabbix    分布式    neo4j图数据库    

利用CURL直接调用Stripe接口

'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 认证,这样就可以省掉本地认证文件,否则就得加载认证文件


This entry was posted in PHP and tagged , , . Bookmark the permalink.
月小升QQ 2651044202, 技术交流QQ群 178491360
首发地址:月小升博客https://java-er.com/blog/curl-stripe/
无特殊说明,文章均为月小升原创,欢迎转载,转载请注明本文地址,谢谢
您的评论是我写作的动力.

One Response to 利用CURL直接调用Stripe接口

Leave a Reply