Diferencia entre revisiones de «Código de ejemplo»
De Documentación del API Cedula
(→Codigo de ejemplo en Python) |
|||
(12 revisiones intermedias por el mismo usuario no mostrado) | |||
Línea 1: | Línea 1: | ||
− | == | + | '''NOTA IMPORTANTE''': Si usted esta prestando un servicio de registro en línea, es altamente recomendable que utilice un sistema Captcha antes de hacer una consulta a nuestro API ya que si presenta un ataque DDoS en su sistema podría gastarle su número máximo de solicitudes por hora del plan contratado. Para más información le recomendamos leer [http://es.wikipedia.org/wiki/Captcha]. |
+ | |||
+ | También puede ver estos ejemplos en el repositorio GitHub: https://github.com/DesarrollosCuado/API-Cedula.com.ve/tree/master/client_example | ||
+ | |||
+ | == Código de ejemplo en PHP == | ||
<pre><nowiki> | <pre><nowiki> | ||
<?php | <?php | ||
define('APPID_CEDULA', 'APP-ID-AQUI'); | define('APPID_CEDULA', 'APP-ID-AQUI'); | ||
define('TOKEN_CEDULA', 'TOKEN-AQUI'); | define('TOKEN_CEDULA', 'TOKEN-AQUI'); | ||
− | function | + | function getCurlData($url) |
{ | { | ||
− | $ | + | $curl = curl_init(); |
− | + | curl_setopt($curl, CURLOPT_URL, $url); | |
− | + | curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); | |
− | + | curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); | |
− | + | curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); | |
− | + | curl_setopt($curl, CURLOPT_TIMEOUT, 10); | |
− | $curlData = | + | $curlData = curl_exec($curl); |
− | + | curl_close($curl); | |
− | + | return $curlData; | |
} | } | ||
− | function | + | function getCI($cedula, $return_raw = false) { |
− | $ | + | $res = getCurlData("https://api.cedula.com.ve/api/v1?app_id=".APPID_CEDULA."&token=".TOKEN_CEDULA."&cedula=".(int)$cedula); |
− | + | if($return_raw) | |
− | + | return strlen($res)>3?$res:false; | |
− | $ | + | $res = json_decode($res, true); |
− | + | return isset($res['data']) && $res['data']?$res['data']:$res['error_str']; | |
} | } | ||
− | $ | + | $consulta = getCI(00000); |
− | + | if(is_array($consulta)) { | |
− | + | print_r($consulta); | |
− | } | + | }else{ |
− | echo "Ocurrio un error en la consulta: " | + | echo "Ocurrio un error en la consulta: ".$consulta; |
} | } | ||
</nowiki></pre> | </nowiki></pre> | ||
− | == | + | == Código de ejemplo en Python == |
− | < | + | <pre><nowiki> |
import urllib.request | import urllib.request | ||
import json | import json | ||
− | APPID_CEDULA = '' | + | APPID_CEDULA = 'APP-ID-AQUI' |
− | TOKEN_CEDULA = '' | + | TOKEN_CEDULA = 'TOKEN-AQUI' |
def getCI( cedula ): | def getCI( cedula ): | ||
global APPID_CEDULA | global APPID_CEDULA | ||
global TOKEN_CEDULA | global TOKEN_CEDULA | ||
− | response = urllib.request.urlopen('https:// | + | response = urllib.request.urlopen('https://api.cedula.com.ve/api/v1?app_id='+APPID_CEDULA+'&token='+TOKEN_CEDULA+'&cedula='+cedula).read() |
if response: | if response: | ||
data = json.loads(response.decode("utf-8")) | data = json.loads(response.decode("utf-8")) | ||
Línea 56: | Línea 60: | ||
else: | else: | ||
print('Ocurrio un error') | print('Ocurrio un error') | ||
− | </nowiki></ | + | </nowiki></pre> |
− | == | + | == Código de ejemplo en NodeJS == |
+ | |||
+ | <pre><nowiki> | ||
+ | var request = require("request") | ||
+ | var APPID_CEDULA = 'APP-ID-AQUI'; | ||
+ | var TOKEN_CEDULA = 'TOKEN-AQUI'; | ||
+ | |||
+ | function getCI(cedula, cb) { | ||
+ | request({ | ||
+ | url: 'https://api.cedula.com.ve/api/v1?app_id='+APPID_CEDULA+'&token='+TOKEN_CEDULA+'&cedula='+cedula, | ||
+ | json: true, | ||
+ | rejectUnauthorized: false | ||
+ | }, function (error, response, body) { | ||
+ | if (!error && response.statusCode === 200) { | ||
+ | if(body.data) | ||
+ | return cb(true, body.data, false); | ||
+ | else | ||
+ | return cb(true, false, body.error_str); | ||
+ | }else{ | ||
+ | cb(false, false, false); | ||
+ | } | ||
+ | }); | ||
+ | } | ||
+ | |||
+ | |||
+ | getCI('00000', function(result, data, error_str){ | ||
+ | if(result) | ||
+ | if(error_str) | ||
+ | console.log('Ocurrio un error: '+error_str); | ||
+ | else | ||
+ | console.log(data); | ||
+ | else | ||
+ | console.log('Ocurrio un error en la consulta'); | ||
+ | }); | ||
+ | </nowiki></pre> | ||
− | == | + | == Código de ejemplo en Java == |
− | + | Próximamente... |
Última revisión de 01:28 23 jul 2022
NOTA IMPORTANTE: Si usted esta prestando un servicio de registro en línea, es altamente recomendable que utilice un sistema Captcha antes de hacer una consulta a nuestro API ya que si presenta un ataque DDoS en su sistema podría gastarle su número máximo de solicitudes por hora del plan contratado. Para más información le recomendamos leer [1].
También puede ver estos ejemplos en el repositorio GitHub: https://github.com/DesarrollosCuado/API-Cedula.com.ve/tree/master/client_example
Contenido
Código de ejemplo en PHP
<?php define('APPID_CEDULA', 'APP-ID-AQUI'); define('TOKEN_CEDULA', 'TOKEN-AQUI'); function getCurlData($url) { $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_TIMEOUT, 10); $curlData = curl_exec($curl); curl_close($curl); return $curlData; } function getCI($cedula, $return_raw = false) { $res = getCurlData("https://api.cedula.com.ve/api/v1?app_id=".APPID_CEDULA."&token=".TOKEN_CEDULA."&cedula=".(int)$cedula); if($return_raw) return strlen($res)>3?$res:false; $res = json_decode($res, true); return isset($res['data']) && $res['data']?$res['data']:$res['error_str']; } $consulta = getCI(00000); if(is_array($consulta)) { print_r($consulta); }else{ echo "Ocurrio un error en la consulta: ".$consulta; }
Código de ejemplo en Python
import urllib.request import json APPID_CEDULA = 'APP-ID-AQUI' TOKEN_CEDULA = 'TOKEN-AQUI' def getCI( cedula ): global APPID_CEDULA global TOKEN_CEDULA response = urllib.request.urlopen('https://api.cedula.com.ve/api/v1?app_id='+APPID_CEDULA+'&token='+TOKEN_CEDULA+'&cedula='+cedula).read() if response: data = json.loads(response.decode("utf-8")) if data['data']: return data['data'] return false persona = getCI('00000') if persona: print(persona['primer_nombre']) print(persona['primer_apellido']) print(persona) else: print('Ocurrio un error')
Código de ejemplo en NodeJS
var request = require("request") var APPID_CEDULA = 'APP-ID-AQUI'; var TOKEN_CEDULA = 'TOKEN-AQUI'; function getCI(cedula, cb) { request({ url: 'https://api.cedula.com.ve/api/v1?app_id='+APPID_CEDULA+'&token='+TOKEN_CEDULA+'&cedula='+cedula, json: true, rejectUnauthorized: false }, function (error, response, body) { if (!error && response.statusCode === 200) { if(body.data) return cb(true, body.data, false); else return cb(true, false, body.error_str); }else{ cb(false, false, false); } }); } getCI('00000', function(result, data, error_str){ if(result) if(error_str) console.log('Ocurrio un error: '+error_str); else console.log(data); else console.log('Ocurrio un error en la consulta'); });
Código de ejemplo en Java
Próximamente...