php - 当我使用 curl 时,我用邮递员访问 api 我得到响应,我得到空响应
问题描述
这是我的代码块。当邮递员给出肯定响应并获取文档中指定的所有必需数据时,我通过 curl 获得了空值。Iam 使用支付网关 iam 还提供文档链接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);
解决方案
我过去遇到过类似的问题,最好的方法是联系支付网关技术人员并询问您的日志,因为在我的情况下代码是 100% 没问题,但每次我都被拒绝,因为我的服务器设置和 SSL 和 TLS 版本。
支付网关有非常严格的要求(关于 ssl/tls)
推荐阅读
- java - 使用 JNI 调用 C++ 库函数以及哪个进程执行该 C++ 库
- swift - 如何通过 ios 中的 cocoapods 使用 vendored 框架发送 dsym 文件
- c# - 如何添加引用 EF 核心中同一个表的多个外键
- typescript - 在运行时从数组值的 Observable 派生联合类型
- elixir - 无法运行 ecto.create,无法创建数据库:连接不可用并且请求已从队列中删除
- javascript - 当我使用变量作为参数时,数据不会出现
- reactjs - 将箭头功能更改为组件列表
- swift - 使用 Swift 和 AWS 开发工具包将视频上传到 S3 存储桶
- c++ - Entity-Component-System 中的拆分组件需要过多的重构
- button - 工具栏 kendo ui 网格上是否有“提交”和“取消”按钮?