php - Jet API connection problems -
so far, connecting jet.com in postman, when attempt connect via php, not errors or response. page blank. far code have:
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 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 , save last time got 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();
im not sure doing wrong. appreciated. thanks.
i using:
$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);
the key here curl_setopt($curl, curlopt_ssl_verifypeer, false);
Comments
Post a Comment