这里仅赘述Paypal的Restful API curl方式的php 代码:
下面这段是PayPal官方给出的命令行下的获取access_token的curl方式:curl https://api.sandbox.paypal.com/v1/oauth2/token \
-H "Accept: application/json" \
-H "Accept-Language: en_US" \
-u "EOJ2S-Z6OoN_le_KS1d75wsZ6y0SFdVsY9183IvxFyZp:EClusMEUk8e9ihI7ZdVLF5cZ6y0SFdVsY9183IvxFyZp" \
-d "grant_type=client_credentials"
ps:-H其实就是header,
-u就是用户名和密码
-d就是data数据,需要POST的数据$ch = curl_init();
$clientId = $this->client_id;
$secret = $this->secret;
curl_setopt($ch, CURLOPT_URL, "https://api.sandbox.paypal.com/v1/oauth2/token");
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, $clientId.":".$secret);
curl_setopt($ch, CURLOPT_POSTFIELDS, "grant_type=client_credentials");
$result = curl_exec($ch);
if(empty($result))die("Error: No response.");
else
{
$json = json_decode($result);
print_r($json);
}
curl_close($ch);die;
okay,就可以了!
ps:关于代码里面的client_id和secret是需要创建一个在PayPal开发者网站上创建一个app就会有了,不多陈述,附上PayPal开发者的网址:https://developer.paypal.com/docs/api/