cURL(PHP)有问题

所以我有一个带有API的许可系统,尽管我几乎不了解cURL。有人可以解释我做错了什么吗?

大部分代码都是从我正在使用的API的文档中提取的。

这是我的PHP登录页面中的代码。

function checkLicense() {
    $curl = curl_init();
    curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);
    curl_setopt_array($curl,array(
    CURLOPT_URL => "https://www.scriptic.xyz/wp-json/lmfwc/v2/licenses/",$licensekey,"?consumer_key=",$consumer_key,"&consumer_secret=",$consumer_secret,CURLOPT_RETURNTRANSFER => true,CURLOPT_ENCODING => "",CURLOPT_MAXREDIRS => 10,CURLOPT_TIMEOUT => 0,CURLOPT_FOLLOWLOCATION => false,CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,CURLOPT_CUSTOMREQUEST => "GET",));

    $response = curl_exec($curl);
    $err = curl_error($curl);

    curl_close($curl);

    if ($err) {
        return "cURL Error #: " . $err;
    } else {
        return $response;
    }
}

错误:

cURL Error #: Could not resolve proxy: ?consumer_key=

编辑:当我使用数据库中的许可证密钥在“ $ licensekey”位置访问链接并填写其他两个变量时,它将返回我想要的json。

获取json的网址: https://www.scriptic.xyz/wp-json/lmfwc/v2/licenses/license-key-example?consumer_key=key-example&consumer_secret=secret-example

这是它返回的json

{"success":true,"data":{"id":"5","orderId":null,"productId":null,"licenseKey":"hidden-for-privacy","expiresAt":null,"validFor":"0","source":"2","status":"3","timesactivated":null,"timesactivatedMax":"0","createdAt":"2019-11-07 01:43:16","createdBy":"1","updatedAt":null,"updatedBy":null}}

编辑2:

我已将,更改为.

$consumer_key = "hidden-for-privacy";
$consumer_secret = "hidden-for-privacy";
$licensekey = $_SESSION['key'];

function checkLicense() {
    $curl = curl_init();
    curl_setopt($curl,array(
        CURLOPT_URL => "https://www.scriptic.xyz/wp-json/lmfwc/v2/licenses/". $licensekey ."?consumer_key=". $consumer_key ."&consumer_secret=". $consumer_secret,));

    $response = curl_exec($curl);
    $err = curl_error($curl);

    curl_close($curl);

    if ($err) {
        return "cURL Error #:" . $err;
    } else {
        return $response;
    }
}

新错误:

{"code":"lmfwc_rest_authentication_error","message":"Consumer key or secret is missing.","data":{"status":401}}
adolfe5 回答:cURL(PHP)有问题

好,问题已解决,谢谢所有帮助过的人。我将变量移到函数内部,现在它返回了我想要的。

本文链接:https://www.f2er.com/3147666.html

大家都在问