get_variable('IDCLISERVICO',true); $desbloq = DesbloqueiaCliente($idCliServico); if($desbloq == "success"){ $agi->exec_goto(GetAnuncio('CLIENTE_DESBLOQUEADO_FIBNET')); }else{ $agi->exec_goto(GetAnuncio('AGUARDE_ATENDIMENTO_FIBNET')); } } catch (Exception $ex) { $reg_msg = $ex->getMessage(); $reg_status_exec = 'Er'; __logStr("Desbloqueia Cliente", $reg_msg , $script, true); } @AtualizaIntegracao($uid, $reg_retorno, $reg_msg, $reg_status_exec, $retorno_cliente); if(!$dadosIntegra)@grava_dadosIntegra($reg_retorno); function DesbloqueiaCliente($idCliServico) { $clientId = "5"; $clientSecret = "B7fuHYQykrCYmtWkz7YgDcybwUk509PiF8u99oBp"; $username = "api@simplesip.com.br"; $password = "!@#simplesip_api_fibnet!@#"; if (!empty($idCliServico)) { $requestBody = array( "client_id" => $clientId, "client_secret" => $clientSecret, "username" => $username, "password" => $password, "grant_type" => "password" ); try { $req = curl_init("https://api.fibnet.hubsoft.com.br/oauth/token"); $header = array(); $header[] = 'Accept: application/json'; curl_setopt($req, CURLOPT_HTTPHEADER, $header); curl_setopt($req, CURLOPT_RETURNTRANSFER, true); curl_setopt($req, CURLOPT_POST, true); curl_setopt($req, CURLOPT_POSTFIELDS, http_build_query($requestBody)); $resp = json_decode(curl_exec($req), true); curl_close($req); } catch (Exception $ex) { $msg = $ex->getMessage(); return $msg; } } try { $tokenType = $resp['token_type']; $accessToken = $resp['access_token']; $authorizationToken = $tokenType . " " . $accessToken; $postfields = array( "id_cliente_servico" => $idCliServico, "dias_desbloqueio" => "2" ); $req = curl_init("https://api.fibnet.hubsoft.com.br/api/v1/integracao/cliente/desbloqueio_confianca"); $header = array(); $header[] = 'Accept: application/json'; if (!is_null($authorizationToken)) { $header[] = 'Authorization: ' . $authorizationToken; } curl_setopt($req, CURLOPT_HTTPHEADER, $header); curl_setopt($req, CURLOPT_RETURNTRANSFER, true); curl_setopt($req, CURLOPT_POST, true); curl_setopt($req, CURLOPT_POSTFIELDS, http_build_query($postfields)); $result = json_decode(curl_exec($req), true); curl_close($req); $cliente = objectToArray($result); return $cliente['status']; } catch (Exception $ex) { $msg = $ex->getMessage(); return $msg; } } function objectToArray($d) { if (is_object($d)) { $d = get_object_vars($d); } if (is_array($d)) { return array_map(__FUNCTION__, $d); } else { return $d; } }