卷曲获取请求响应不正确

时间:2019-10-25 13:07:22

标签: curl get response

Curl获取请求响应位于url参数内。下面是代码。

    $url = "?data=$data&product_key=$this->product_key";
        return $this->Connect('GET', 'creditcomplete' . $url);


    public function Connect($requestMethod, $entity, $body = null) {

            $curl = curl_init(BASE_API_URL . 'v1/' . $entity);
            $options = array(
                'Apikey: ' . api_key . '',
                'Token: ' . token . '',
                'Secret: ' . secret . '',
                'Content-Type: application/json',
                'Accept: application/json'
            );

            curl_setopt($curl, CURLOPT_ENCODING, "");
            curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 
            curl_setopt($curl, CURLOPT_HTTPHEADER, $options);
            curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $requestMethod);
            curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
            curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);

            if ($requestMethod == 'POST' || $requestMethod == 'PUT') {
                curl_setopt($curl, CURLOPT_POSTFIELDS, $body);
            }

            $curlResponse = curl_exec($curl);

            if($this->isJSON($curlResponse)) {
                $curlResponse = json_decode($curlResponse, 1);
            }       

            curl_close($curl);

            return $curlResponse;
    }

    private function isJSON($string) {
        return is_string($string) && is_object(json_decode($string)) ? true : false;
    }

响应为:

creditcomplete{"Response": {"Reminders": [],"Repayments": [],"Payouts": [],"Transactions": []}}

我不知道为什么creditcomplete添加了响应。任何帮助将不胜感激。 PHP版本7.1.23。

1 个答案:

答案 0 :(得分:0)

检查$ options变量。是api_key,令牌,秘密常量吗?