【发布时间】:2019-10-17 09:19:50
【问题描述】:
这是我的代码块。当邮递员给出肯定响应并获取文档中指定的所有必需数据时,我通过 curl 获得了 null。我正在使用支付网关我还提供文档链接https://docs.ngenius-payments.com/reference#request-an-access-token-paypage
$apikey = "My api key"; // enter your API key here
$ch = curl_init();
// var_dump($ch);
curl_setopt($ch, CURLOPT_URL, "https://identity-uat.ngeniuspayments.com/auth/realms/ni/protocol/openidconnect/token");
$headers = curl_getinfo($ch);
echo "<pre>";
print_r($headers);
echo "</pre>";
$test = curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Authorization: Basic'.$apikey,
'Content-Type: application/x-www-form-urlencoded'));
// var_dump($test);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(array(grant_type => client_credentials)));
var_dump($ch);
$output = json_decode(curl_exec($ch));
$access_token = $output->access_token;
print_r($access_token);
【问题讨论】:
-
您是否收到来自curl_error 和curl_strerror 的任何错误消息?
-
可能很简单,比如“基本”之后缺少空格。我更喜欢使用 CURLOPT_USERPWD。无论如何,要调试它,我首先会在命令行上尝试 curl。少一层失败。