喷射 API 连接问题


Jet API connection problems

到目前为止,我正在邮递员中连接到 jet.com,但是当我尝试通过php连接时,我没有收到任何错误或响应。页面为空白。到目前为止,这是我拥有的代码:

protected static $api_user_id = "****";
protected static $api_secret = "****";
protected static $merchant_id = "****";
protected static $api_prefix = "https://merchant-api.jet.com/api/";
class Jet
{
    public function getNewToken()
    {
    $ch = curl_init($this::$api_prefix.'/Token');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    //If necessary add your ssl pem: curl_setopt($ch, CURLOPT_CAINFO,'/ssl/cacert.pem');
    $request = json_encode(array(
        "user" => $this::$api_user_id,
        "pass" => $this::$api_secret
    ));                                              
    curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(                                                                          
        'Content-Type: application/json',                                                                                
        'Content-Length: ' . strlen($request))                                                                       
    );       
    $data = curl_exec($ch);
    curl_close($ch);
    if($data = json_decode($data)){
        if($token = $data->id_token){
            //SAVE $token SOMEWHERE and save last time you got a token
            $this->setToken($token);
            $this->setTokenTs(date('r'));
            $this->save();
            echo $token;
            return true;
        }
    }
    return false;
    $return = curl_exec($ch);   
    $err = curl_error($ch);
    curl_close($ch);
    if ($err) 
    {
        echo "cURL Error #:" . $err;
    } 
    else 
    {
        echo $return;
    }
    }
}
$jetAPI = new Jet;
$jetAPI->getNewToken();

不确定我做错了什么。任何帮助将不胜感激。谢谢。

我正在使用:

$curl = curl_init($url);
curl_setopt($curl, CURLOPT_POST, TRUE);
curl_setopt($curl, CURLOPT_POSTFIELDS, $obj);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: $app"));
curl_setopt($curl, CURLOPT_HEADER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
$response = curl_exec($curl);

这里的关键是curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);