如何从贝宝配置文件中获取访问令牌
Posted
技术标签:
【中文标题】如何从贝宝配置文件中获取访问令牌【英文标题】:How to get Access-Token from paypal profile 【发布时间】:2018-02-01 08:43:57 【问题描述】:我正在尝试从 PayPal 获取访问访问令牌以在 PayPal Single Payout Developer API 中使用。
但是我如何从这个凭证中获取访问令牌?
$client_id = 'AdXsXfAl9EnbcpQ0809yD7hjZ8fQL5WouTkarNlWq1NhAD1oFBbAy66PDpVo1xTjMF-wAJTqJ76jPFWR'; //DUMMY
$secret = 'EB_DLdxEo5w8bj-jzY1N0RBcIj4RXqgLEKhk-BFJvjvFaMwj9O86ePVGzMZGO6uvCLBaNxbq2P-xB3FJ'; //DUMMY
【问题讨论】:
我建议不要在线发布凭据。 【参考方案1】:<?php
$client_id = 'AdXsXfAl9EnbcpQ0809yD7hjZ8fQL5WouTkarNlWq1NhAD1oFBbAy66PDpVo1xTjMF-wAJTqJ76jPFWR'; //DUMMY
$secret = 'EB_DLdxEo5w8bj-jzY1N0RBcIj4RXqgLEKhk-BFJvjvFaMwj9O86ePVGzMZGO6uvCLBaNxbq2P-xB3FJ'; //DUMMY
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_URL, "https://api.sandbox.paypal.com/v1/oauth2/token"); //DUMMY
//curl_setopt($ch, CURLOPT_URL, "https://api.paypal.com/v1/oauth2/token"); //LIVE
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "grant_type=client_credentials");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_USERPWD, $client_id . ":" . $secret);
$headers = array();
$headers[] = "Accept: application/json";
$headers[] = "Accept-Language: en_US";
$headers[] = "Content-Type: application/x-www-form-urlencoded";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
pr(json_decode($result)->access_token);
if (curl_errno($ch))
echo 'Error:' . curl_error($ch);
curl_close ($ch);
?>
【讨论】:
当心禁用证书验证(CURLOPT_SSL_VERIFYHOST
和 CURLOPT_SSL_VERIFYPEER
)是非常糟糕的安全做法!以上是关于如何从贝宝配置文件中获取访问令牌的主要内容,如果未能解决你的问题,请参考以下文章