90 lines
3.0 KiB
VB.net
90 lines
3.0 KiB
VB.net
|
|
Imports System.IO
|
|||
|
|
Imports System.Net
|
|||
|
|
Imports System.Text
|
|||
|
|
Imports Newtonsoft.Json
|
|||
|
|
|
|||
|
|
Public Class RoomControlSystemAPI
|
|||
|
|
|
|||
|
|
Public Shared Function API_AllocationBarCode(roomNumber As String, hotelID As String) As APIRoomNode
|
|||
|
|
Dim jsonString As String = String.Empty
|
|||
|
|
Dim dic As New Dictionary(Of String, String)
|
|||
|
|
dic.Add("roomNumber", roomNumber)
|
|||
|
|
dic.Add("key", "blw_ws@2015")
|
|||
|
|
dic.Add("hotelID", hotelID)
|
|||
|
|
Try
|
|||
|
|
jsonString = PostData("https://www.boonlive-rcu.com/api/GetHostByRoomNumber", $"jsonData={JsonConvert.SerializeObject(dic)}")
|
|||
|
|
Catch ex As Exception
|
|||
|
|
MsgBox($"网络API调用错误,请联系管理员。")
|
|||
|
|
Return Nothing
|
|||
|
|
End Try
|
|||
|
|
'Console.WriteLine(jsonString)
|
|||
|
|
|
|||
|
|
If jsonString = Nothing Then
|
|||
|
|
Return Nothing
|
|||
|
|
End If
|
|||
|
|
|
|||
|
|
Dim login As APIRoomNode = Nothing
|
|||
|
|
Try
|
|||
|
|
login = JsonConvert.DeserializeObject(Of APIRoomNode)(jsonString)
|
|||
|
|
If login.IsSuccess.ToLower.Equals("true") Then
|
|||
|
|
Return login
|
|||
|
|
Else
|
|||
|
|
Return Nothing
|
|||
|
|
End If
|
|||
|
|
Catch ex As Exception
|
|||
|
|
'MsgBox($"Json数据转换错误,请联系管理员。详情 :Json data to AllocationAPI error")
|
|||
|
|
Return Nothing
|
|||
|
|
End Try
|
|||
|
|
|
|||
|
|
End Function
|
|||
|
|
Public Shared Function URLEncode(strInput As String) As String
|
|||
|
|
Dim strOutput As String
|
|||
|
|
Dim intAscii As Integer
|
|||
|
|
Dim i As Integer
|
|||
|
|
|
|||
|
|
|
|||
|
|
For i = 1 To Len(strInput)
|
|||
|
|
intAscii = Asc(Mid(strInput, i, 1))
|
|||
|
|
If ((intAscii < 58) And (intAscii > 47)) Or
|
|||
|
|
((intAscii < 91) And (intAscii > 64)) Or
|
|||
|
|
((intAscii < 123) And (intAscii > 96)) Then
|
|||
|
|
strOutput = strOutput & Chr(intAscii)
|
|||
|
|
Else
|
|||
|
|
strOutput = strOutput &
|
|||
|
|
IIf(intAscii < 16, "%0", "%") &
|
|||
|
|
Trim$(Hex$(intAscii))
|
|||
|
|
End If
|
|||
|
|
Next
|
|||
|
|
URLEncode = strOutput
|
|||
|
|
End Function
|
|||
|
|
|
|||
|
|
|
|||
|
|
Public Shared Function PostData(ByVal url As String, ByVal data As String) As String
|
|||
|
|
|
|||
|
|
ServicePointManager.Expect100Continue = False
|
|||
|
|
Dim request As HttpWebRequest = CType(WebRequest.Create(url), HttpWebRequest)
|
|||
|
|
'//Post请求方式
|
|||
|
|
request.Method = "POST"
|
|||
|
|
|
|||
|
|
'内容类型
|
|||
|
|
request.ContentType = "application/x-www-form-urlencoded"
|
|||
|
|
'将URL编码后的字符串转化为字节
|
|||
|
|
Dim encoding As New UTF8Encoding()
|
|||
|
|
|
|||
|
|
Dim bys As Byte() = encoding.GetBytes(data)
|
|||
|
|
'设置请求的 ContentLength
|
|||
|
|
request.ContentLength = bys.Length
|
|||
|
|
'获得请 求流
|
|||
|
|
Dim newStream As Stream = request.GetRequestStream()
|
|||
|
|
newStream.Write(bys, 0, bys.Length)
|
|||
|
|
newStream.Close()
|
|||
|
|
'获得响应流
|
|||
|
|
Dim sr As StreamReader = New StreamReader(request.GetResponse().GetResponseStream)
|
|||
|
|
Return sr.ReadToEnd
|
|||
|
|
End Function
|
|||
|
|
End Class
|
|||
|
|
Public Class APIRoomNode
|
|||
|
|
Public IsSuccess As String
|
|||
|
|
Public Result As List(Of Dictionary(Of String, String))
|
|||
|
|
End Class
|