Jump to content
Sign in to follow this  
Elias Assad Neto

Portal Unico Siscomex DUE (Documento Único de Exportação)

Recommended Posts

Portal Unico Siscomex  DUE (Documento Único de Exportação)


Alguém aqui tem alguma experiencia usando o AutoIt para a autenticação e envio de XML no Portal Único Siscomex

Aqui explica como acessar mas estou bem perdido ainda mais na autenticação
URL: https://val.portalunico.siscomex.gov.br/docs/api/#autentica-o

Abaixo pode ser que ajude.
PUCOMEX MSDN https://social.msdn.microsoft.com/Forums/pt-BR/72c6fefa-6b77-48ce-af32-c5b67d8f7c3f/enviar-xml-via-json-rest-preciso-de-ajuda-urgente?forum=aspnetpt


PUSiscomex.au3
 

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_UseX64=y
#AutoIt3Wrapper_Res_Fileversion=0.0.0.0
#AutoIt3Wrapper_Res_LegalCopyright=Elias Assa Neto Informatica ME 2018
#AutoIt3Wrapper_Run_Au3Stripper=y
#Au3Stripper_Parameters=/so /mo
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.14.2
 Author:         Elias Assad Neto

 Script Function:
    Acesso Portal Unico Siscomex
    https://val.portalunico.siscomex.gov.br/docs/api/#autentica-o

    POST https://<url>/portal/api/autenticar


Pedido se suporte 7/ago/2018 16:32
Solicitação de Serviço 2018SS/0000626704 criada com sucesso!

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here

#include "_sVar.au3" ; Debug
#include "WinHttp.au3"


Opt("MustDeclareVars", 1)

Global $sPUSVal = "val.portalunico.siscomex.gov.br" ; Teste Validação
Global $sPUS = ""; "portalunico.siscomex.gov.br"
Global $sAtenticar = "portal/api/autenticar" ; Autenticação

;https://val.portalunico.siscomex.gov.br/portal/api/autenticar?Role-Type=IMPEXP

If Not @Compiled Then $sPUS = $sPUSVal ; No desenvolvimento trabalha com a Validação

; !!!Note that this example will fail because of invalid username and password!!!

; Use real data for authentication
;Global $sUserName = "SomeUserName"
;Global $sPassword = "SomePassword"
;Global $sDomain = "www.google.com"
;Global $sPage = "accounts/ClientLogin"
; Visit http://code.google.com/apis/accounts/docs/AuthForInstalledApps.html for more informations
;Global $sAdditionalData = "accountType=HOSTED_OR_GOOGLE&Email=" & $sUserName & "&Passwd=" & $sPassword & "&service=mail&source=Gulp-CalGulp-1.05"


; Visit http://code.google.com/apis/accounts/docs/AuthForInstalledApps.html for more informations
;Global $sAdditionalData = Default


Global $sDomain = $sPUS ; Portal Unico Siscomex
Global $sPage = $sAtenticar ; Autenticação
Global $sAdditionalData = "Role-Type:IMPEXP"

; Initialize and get session handle
Global $hOpen = _WinHttpOpen()
; Get connection handle
Global $hConnect = _WinHttpConnect($hOpen, $sDomain)

; SimpleSSL-request it...
Global $sReturned = _WinHttpSimpleSSLRequest($hConnect, "POST", $sPage, Default, $sAdditionalData)
WErrorWinHttp("_WinHttpSimpleSSLRequest",@error)
_Var($sReturned,"$sReturned")
; #FUNCTION# ====================================================================================================================
;_WinHttpSimpleSSLRequest($hConnect, $sType = Default, $sPath = Default, $sReferrer = Default, $sData = Default, $sHeader = Default, $fGetHeaders = Default, $iMode = Default, $sCredName = Default, $sCredPass = Default, $iIgnoreCertErrors = 0)
; Name...........: _WinHttpSimpleSSLRequest
; Description ...: A function to send a SSL request in a simpler form
; Syntax.........: _WinHttpSimpleSSLRequest($hConnect [, $sType [, $sPath [, $sReferrer = Default [, $sData = Default [, $sHeader = Default [, $fGetHeaders = Default [, $iMode = Default ]]]]]]])
; Parameters ....: $hConnect  - Handle from _WinHttpConnect
;                  $sType       - [optional] GET or POST (default: GET)
;                  $sPath       - [optional] request path (default: "" - empty string; meaning 'default' page on the server)
;                  $sReferrer   - [optional] referrer (default: $WINHTTP_NO_REFERER)
;                  $sData       - [optional] POST-Data (default: $WINHTTP_NO_REQUEST_DATA)
;                  $sHeader     - [optional] additional Headers (default: $WINHTTP_NO_ADDITIONAL_HEADERS)
;                  $fGetHeaders - [optional] return response headers (default: False)
;                  $iMode       - [optional] reading mode of result
;                  |0 - ASCII-text
;                  |1 - UTF-8 text
;                  |2 - binary data
; Return values .: Success      - response data if $fGetHeaders = False (default)
;                  |Array if $fGetHeaders = True
;                  | [0] - response headers
;                  | [1] - response data
;                  Failure      - 0 and set @error
;                  |1 - could not open request
;                  |2 - could not send request
;                  |3 - could not receive response
;                  |4 - $iMode is not valid
; Author ........: ProgAndy
; Modified.......: trancexx
; Related .......: _WinHttpSimpleRequest, _WinHttpSimpleSendSSLRequest, _WinHttpSimpleSendRequest, _WinHttpQueryHeaders, _WinHttpSimpleReadData
; ===============================================================================================================================


; Close handles
_WinHttpCloseHandle($hConnect)
_WinHttpCloseHandle($hOpen)

; See what's returned
MsgBox(0, "Returned", $sReturned)


Func WErrorWinHttp($sFunc,$R = 0, $error = @error, $extended = @extended) ; Mostra a descrição do erro de WinHttp.au3
    If $error = 0 Then Return SetError($error, $extended)
    Static $sau3 = FileRead("WinHttp.au3")
    Local $sPattern = "(?s); Name...........: " & $sFunc & ".*?Failure .*?(" & $error & " - .*?)\r"
    ;ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $sPattern = ' & $sPattern & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
    Local $aErr = StringRegExp($sau3,$sPattern,1)
    Local $sErr = ""
    If UBound($aErr) > 0 Then $sErr = $sFunc & " @error: " & $aErr[0]
    ConsoleWrite("!" & $sErr & @CRLF)
    Return SetError($error, $extended)
EndFunc

 

_sVar.au3

WinHttp.au3

PUSiscomex.au3

Edited by Elias Assad Neto
Inclusão do Script e módulos utilizados

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

×