首页 > 解决方案 > 当我使用 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);

标签: phpopencartpayment

解决方案


我过去遇到过类似的问题,最好的方法是联系支付网关技术人员并询问您的日志,因为在我的情况下代码是 100% 没问题,但每次我都被拒绝,因为我的服务器设置和 SSL 和 TLS 版本。

支付网关有非常严格的要求(关于 ssl/tls)


推荐阅读