场景:在对接PayPal支付时,遇到了很多小坑,因为官方提供的是bash脚本,和php的写法还是有点区别,以此记录保留,望后人少走弯路。(官方文档)
1.获取access token,这个token是调用其他REST API身份验证的前提。
public function getAccessToken()
{
$url = "https://api.sandbox.paypal.com/v1/oauth2/token";
$cient_id = $this->_setting['client_id'];
$secret = $this->_setting['secret'];
$headers_array[] = "Content-Type: application/json";
$data = array(
'grant_type' => 'client_credentials'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 500