This commit is contained in:
JORGE LUIS CAUDILLO ESPARZA
2020-06-07 02:06:11 -07:00
parent 2a7879bfac
commit c080abce6f
4 changed files with 1908 additions and 63 deletions

View File

@@ -43,7 +43,10 @@ Public Class SIGWeb : Implements IHttpHandler, IRequiresSessionState
ActualizaPrePoliza(context)
Case "getpersonal"
getpersonal(context)
Case "GettingCURP"
context.Response.Write(GettingCURP(context.Request("Curp").ToString(), context.Request("year").ToString().ToEntero()))
Case "ValidaCURP"
context.Response.Write(ValidaCURP(context.Request("Curp").ToString()))
End Select
Catch ex As Exception
ex.GuardaLog(ex.Message)
@@ -181,6 +184,225 @@ Public Class SIGWeb : Implements IHttpHandler, IRequiresSessionState
End Sub
#End Region
Private Shared Function sendURL(ByVal URL As String, Optional Methodo As String = "POST", Optional Cookie As String = "", Optional maxTimeMilliseconds As Integer = 120000) As String
Dim resultado As String = ""
Try
Dim request As Net.HttpWebRequest = CType(Net.HttpWebRequest.Create(URL), Net.HttpWebRequest)
request.Timeout = maxTimeMilliseconds
request.Method = Methodo
request.ContentType = "text/html; charset=utf-8" '"text/xml; charset=utf-8"
If Not String.IsNullOrEmpty(Cookie) Then
request.Headers.Add("Cookie", Cookie)
End If
'Using stream As IO.Stream = request.GetRequestStream()
' Using stmw As IO.StreamWriter = New IO.StreamWriter(stream)
' stmw.Write("")
' End Using
'End Using
Dim response As Net.WebResponse = CType(request.GetResponse(), Net.WebResponse)
Dim sr As IO.StreamReader = New IO.StreamReader(response.GetResponseStream())
resultado = sr.ReadToEnd()
sr.Close()
Catch ex As Exception
ex.ToString().GuardaLog()
'Extenciones.ApplicationParameter.GuardaLogEx(ex, $"SOAPAction : {SOAPAction} XML : {xml}")
End Try
Return resultado
End Function
Public Shared Function GettingCURP(ByVal Curp As String, year As Integer) As String
Dim abc As String() = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"}
Dim numeric01 As String() = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}
Dim rule1 As String() = If(year < 2000, numeric01, abc)
Dim curpresult As String = ""
Dim i As Integer = 0
While curpresult.Length = 0 AndAlso i < rule1.Length
Dim z As Integer = 0
While curpresult.Length = 0 AndAlso z < numeric01.Length
curpresult = String.Format("{0}{1}{2}", Curp, rule1(i), numeric01(z))
Dim respuesta As String = sendURL(String.Format("http://www.renapo.sep.gob.mx/wsrenapo/MainControllerParam?curp={0}", curpresult), "GET")
Dim trlines As New List(Of String)
Dim keydict As New System.Collections.Concurrent.ConcurrentDictionary(Of String, String)
Dim indexttr As Integer = 0
Dim indexttrB As Integer = 0
Dim indexttd As Integer = 0
Dim indextdiv As Integer = 0
Dim indexinittext As Integer = 0
While Not IsNothing(respuesta) AndAlso respuesta.Length > 0
indexttr = respuesta.IndexOf("<tr")
If indexttr >= 0 Then
indexttrB = respuesta.Substring(indexttr + 3).IndexOf("<tr")
If indexttrB >= 0 Then
trlines.Add(respuesta.Substring(indexttr, indexttrB))
Else
trlines.Add(respuesta.Substring(indexttr))
End If
respuesta = respuesta.Substring(indexttr + 3)
Else
respuesta = ""
End If
End While
Dim key As String = ""
Dim keyvalue As String = ""
For Each item As String In trlines
key = ""
keyvalue = ""
indexttd = item.IndexOf("<td")
indextdiv = item.IndexOf("<div")
If indextdiv >= 0 Then
indexttr = indextdiv
indexttrB = item.IndexOf("</div")
Else
indexttr = indexttd
indexttrB = item.IndexOf("</td")
End If
If indexttr >= 0 Then
indexinittext = item.Substring(indexttr + 3).IndexOf(">")
key = item.Substring(indexinittext + indexttr + 4, (indexttrB - (indexinittext + indexttr + 4)))
item = item.Substring(indexttrB + 3)
Else
item = ""
End If
If item.Length > 0 Then
indexttd = item.IndexOf("<td")
indextdiv = item.IndexOf("<div")
If indextdiv >= 0 Then
indexttr = indextdiv
indexttrB = item.IndexOf("</div")
Else
indexttr = indexttd
indexttrB = item.IndexOf("</td")
End If
If indexttr >= 0 Then
indexinittext = item.Substring(indexttr + 3).IndexOf(">")
keyvalue = item.Substring(indexinittext + indexttr + 4, (indexttrB - (indexinittext + indexttr + 4)))
item = item.Substring(indexttr + 3)
Else
item = ""
End If
End If
If key.Length > 0 Then
keydict.TryAdd(key.Replace(":", "").Trim(), keyvalue.Trim().ToLower())
End If
Next
Dim Apellido1 As String = "" : keydict.TryGetValue("Apellido1", Apellido1)
Dim Apellido2 As String = "" : keydict.TryGetValue("Apellido1", Apellido1)
Dim Nombres As String = "" : keydict.TryGetValue("Nombres", Nombres)
If Nombres Is Nothing OrElse Nombres.Length = 0 Then
curpresult = ""
End If
System.Threading.Thread.Sleep(100)
z = z + 1
End While
i = i + 1
End While
Return curpresult
End Function
Public Shared Function ValidaCURP(ByVal Curp As String) As String
Dim respuesta As String = sendURL(String.Format("http://www.renapo.sep.gob.mx/wsrenapo/MainControllerParam?curp={0}", Curp), "GET")
Dim trlines As New List(Of String)
Dim keydict As New System.Collections.Concurrent.ConcurrentDictionary(Of String, String)
Dim indexttr As Integer = 0
Dim indexttrB As Integer = 0
Dim indexttd As Integer = 0
Dim indextdiv As Integer = 0
Dim indexinittext As Integer = 0
While Not IsNothing(respuesta) AndAlso respuesta.Length > 0
indexttr = respuesta.IndexOf("<tr")
If indexttr >= 0 Then
indexttrB = respuesta.Substring(indexttr + 3).IndexOf("<tr")
If indexttrB >= 0 Then
trlines.Add(respuesta.Substring(indexttr, indexttrB))
Else
trlines.Add(respuesta.Substring(indexttr))
End If
respuesta = respuesta.Substring(indexttr + 3)
Else
respuesta = ""
End If
End While
Dim key As String = ""
Dim keyvalue As String = ""
For Each item As String In trlines
key = ""
keyvalue = ""
indexttd = item.IndexOf("<td")
indextdiv = item.IndexOf("<div")
If indextdiv >= 0 Then
indexttr = indextdiv
indexttrB = item.IndexOf("</div")
Else
indexttr = indexttd
indexttrB = item.IndexOf("</td")
End If
If indexttr >= 0 Then
indexinittext = item.Substring(indexttr + 3).IndexOf(">")
key = item.Substring(indexinittext + indexttr + 4, (indexttrB - (indexinittext + indexttr + 4)))
item = item.Substring(indexttrB + 3)
Else
item = ""
End If
If item.Length > 0 Then
indexttd = item.IndexOf("<td")
indextdiv = item.IndexOf("<div")
If indextdiv >= 0 Then
indexttr = indextdiv
indexttrB = item.IndexOf("</div")
Else
indexttr = indexttd
indexttrB = item.IndexOf("</td")
End If
If indexttr >= 0 Then
indexinittext = item.Substring(indexttr + 3).IndexOf(">")
keyvalue = item.Substring(indexinittext + indexttr + 4, (indexttrB - (indexinittext + indexttr + 4)))
item = item.Substring(indexttr + 3)
Else
item = ""
End If
End If
If key.Length > 0 Then
keydict.TryAdd(key.Replace(":", "").Trim(), keyvalue.Trim().ToLower())
End If
Next
Dim Apellido1 As String = "" : keydict.TryGetValue("Apellido1", Apellido1)
Dim Apellido2 As String = "" : keydict.TryGetValue("Apellido1", Apellido1)
Dim Nombres As String = "" : keydict.TryGetValue("Nombres", Nombres)
If Nombres Is Nothing OrElse Nombres.Length = 0 Then
Curp = ""
End If
Return Curp
End Function
#Region "Get Cliente"
Private Function GetClientes(ByVal context As HttpContext) As String
Dim retorno As String = ""