2 回答
TA贡献1790条经验 获得超9个赞
解决问题见我下面的代码:
$base_token = '{client_id:secret}';
$curl = curl_init();
$data = array(
CURLOPT_URL => "https://api.sandbox.paypal.com/v1/oauth2/token",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_POSTFIELDS => http_build_query(array(
'grant_type'=>'authorization_code',
'code'=> $request->code,
)),
CURLOPT_HTTPHEADER => array(
"Content-Type: application/x-www-form-urlencoded",
),
CURLOPT_USERPWD => $base_token
);
curl_setopt_array($curl, $data);
$response = curl_exec($curl);
curl_close($curl);
TA贡献1795条经验 获得超7个赞
将数组传递给 CURLOPT_POSTFIELDS 会将内容类型设置为multipart/form-data. 这是错误的。
您需要将查询字符串传递给 CURLOPT_POSTFIELDS。
CURLOPT_POSTFIELDS => http_build_query(array(
'grant_type' => 'authorization_code',
'code' => '{authorization_code}'
)),
- 2 回答
- 0 关注
- 211 浏览
添加回答
举报