SDK-PHP

SDK-PHP

Hola 
Tengo un codigo en php que se conecta a CRM para hacer unos insert, pero el problema es que el codigo tiene duracion de 10 minutos, hay forma de generar token que teng apersistencia, que no teng alimite de tiempo, adjunto codigo:


function generate_refresh_token () {

$ publicación = [
   'código' => '1000.xxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxx',
   'redirect_uri' => 'http://example.com/callbackurl',
   'client_id' => '1000.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
   'client_secret' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
   'grant_type' => 'código_autorización'
];

$ ch = curl_init ();
curl_setopt ($ ch, CURLOPT_URL, "https://accounts.zoho.com/oauth/v2/token");
curl_setopt ($ ch, CURLOPT_POST, 1);
curl_setopt ($ ch, CURLOPT_POSTFIELDS, http_build_query ($ publicación));
curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, verdadero);
curl_setopt ($ ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt ($ ch, CURLOPT_HTTPHEADER, array ('Content-Type: application / x- www-form-urlencoded'));

$ respuesta = curl_exec ($ ch);
$ respuesta = json_encode ($ respuesta);
var_dump ($ respuesta);
}
generate_refresh_token ();

////////////////////////////////////////////////////////////////////////

function generate_access_token () {

$ publicación = [
   'refresh_token' => '1000.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
   'client_id' => '1000.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
   'client_secret' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
   'grant_type' => 'refresh_token'
];

$ ch = curl_init ();
curl_setopt ($ ch, CURLOPT_URL, "https://accounts.zoho.com/oauth/v2/token");
curl_setopt ($ ch, CURLOPT_POST, 1);
curl_setopt ($ ch, CURLOPT_POSTFIELDS, http_build_query ($ publicación));
curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, verdadero);
curl_setopt ($ ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt ($ ch, CURLOPT_HTTPHEADER, array ('Content-Type: application / x- www-form-urlencoded'));

$ respuesta = curl_exec ($ ch);
$ respuesta = json_encode ($ respuesta);
var_dump ($ respuesta);
}
generate_access_token ();

/////////////////////////////////////////////////////////////

function insert_leads () {

$ access_token = "1000.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxx";

$ post_data = [
  'datos' => [
[
  "Company" => 'Prueba',
  "Last_Name" => 'Prueba',
  "First_Name" => 'Prueba',
  "Email" => 'Prueba',
  "Estado" => 'Floridablanca',
  "Teléfono" => '318-3977596',
  "Description" => 'La URL va aquí'

  ],
  'gatillo' => [
     "aprobación",
"flujo de trabajo",
"Plano"
  ]
];

$ ch = curl_init ();
curl_setopt ($ ch, CURLOPT_URL, "https://www.zohoapis.com/crm/v2/Leads");
curl_setopt ($ ch, CURLOPT_POST, 1);
curl_setopt ($ ch, CURLOPT_POSTFIELDS, json_encode ($ post_data));
curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, verdadero);
curl_setopt ($ ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt ($ ch, CURLOPT_HTTPHEADER, array (
  'Autorización: Zoho-oauthtoken'. $ access_token,
  'Tipo de contenido: aplicación / x- www-form-urlencoded'
));

$ respuesta = curl_exec ($ ch);
$ respuesta = json_decode ($ respuesta);
var_dump ($ respuesta);
}

insert_leads ();