106 lines
2.9 KiB
Plaintext
106 lines
2.9 KiB
Plaintext
IMPORT com
|
|
IMPORT util
|
|
|
|
TYPE t_sync_cmd RECORD
|
|
oper STRING,
|
|
data STRING
|
|
END RECORD
|
|
|
|
|
|
DEFINE url STRING
|
|
MAIN
|
|
|
|
|
|
|
|
CALL testcontacto()
|
|
|
|
END MAIN
|
|
FUNCTION testcontacto()
|
|
DEFINE s STRING,
|
|
r_cmd t_sync_cmd
|
|
|
|
DEFINE p RECORD
|
|
data RECORD
|
|
tipo_cliente SMALLINT,
|
|
sec_cliente INT,
|
|
usuario VARCHAR(50),
|
|
clave VARCHAR(50),
|
|
id_crm STRING
|
|
END RECORD,
|
|
data_arr DYNAMIC ARRAY OF RECORD
|
|
contacto VARCHAR(60),
|
|
tipo_negocio_contacto INT,
|
|
puesto VARCHAR(60),
|
|
puesto1 VARCHAR(60),
|
|
email VARCHAR(60),
|
|
celular VARCHAR(20),
|
|
telefono_of VARCHAR(20),
|
|
telefono_casa VARCHAR(20)
|
|
END RECORD
|
|
END RECORD
|
|
,
|
|
ret INTEGER,
|
|
res STRING
|
|
LET url = "https://ws.marmotech.com.do/gas320/ws/r/restserver"
|
|
LET p.data.tipo_cliente=15
|
|
LET p.data.sec_cliente = 14054
|
|
LET p.data.usuario='jsoto'
|
|
LET p.data.clave='lmmjvsd2014'
|
|
|
|
LET p.data_arr[1].contacto='ERNESTO PERALTA'
|
|
LET p.data_arr[1].celular= '8095656666'
|
|
LET p.data_arr[1].email='eperalta@gmail.com'
|
|
LET p.data_arr[1].puesto='ENC. COMPRAS'
|
|
LET p.data_arr[1].telefono_casa='829333333'
|
|
LET p.data_arr[1].telefono_of='829555555'
|
|
LET p.data_arr[1].tipo_negocio_contacto=3
|
|
|
|
LET r_cmd.oper = 'clientes_contactos'
|
|
LET r_cmd.data = util.JSON.stringify(p)
|
|
LET s = util.JSON.stringify(r_cmd)
|
|
|
|
DISPLAY "s-",s
|
|
CALL sync_send_command(url, s) RETURNING ret, res
|
|
DISPLAY "DATOS ",res
|
|
END FUNCTION
|
|
|
|
FUNCTION sync_send_command(url, cmd)
|
|
|
|
DEFINE url, cmd STRING
|
|
DEFINE result, tmp STRING
|
|
DEFINE http_req com.HTTPRequest
|
|
DEFINE http_resp com.HTTPResponse
|
|
|
|
|
|
TRY
|
|
LET http_req = com.HTTPRequest.Create(url)
|
|
CALL http_req.setConnectionTimeout(40)
|
|
CALL http_req.setTimeout(40)
|
|
CALL http_req.setMethod("POST")
|
|
CALL http_req.setCharset("UTF-8")
|
|
CALL http_req.setHeader("DBSync-Client","mbs")
|
|
CALL http_req.setHeader("Content-Type","dbsync/json")
|
|
|
|
CALL http_req.doTextRequest(cmd)
|
|
LET http_resp=http_req.getResponse()
|
|
IF http_resp.getStatusCode() != 200 THEN
|
|
RETURN http_resp.getStatusCode(), http_resp.getStatusDescription()
|
|
END IF
|
|
LET tmp = http_resp.getStatusDescription()
|
|
IF (tmp == "OK" || tmp == "no error" ) THEN
|
|
RETURN -1, SFMT("HTTP request status description: %1 ",tmp)
|
|
END IF
|
|
LET result = http_resp.getTextResponse()
|
|
CATCH
|
|
RETURN -2, SFMT("HTTP request error: STATUS=%1 (%2)",STATUS,SQLCA.SQLERRM)
|
|
END TRY
|
|
|
|
RETURN 0, result
|
|
|
|
END FUNCTION
|
|
|
|
FUNCTION show_sync_err(msg)
|
|
DEFINE msg STRING
|
|
CALL fgl_winmessage(%"ERROR", msg, "exclamation")
|
|
END FUNCTION
|