976 lines
30 KiB
VB.net
976 lines
30 KiB
VB.net
Imports System.IO
|
||
Imports System.Net
|
||
Imports System.Net.NetworkInformation
|
||
Imports System.Net.Sockets
|
||
Imports System.Security.Cryptography
|
||
Imports System.Text
|
||
Imports System.Threading
|
||
Imports Newtonsoft.Json
|
||
|
||
Module FunctionModule
|
||
|
||
|
||
#Region "发送模式"
|
||
|
||
''' <summary>
|
||
''' 是否是网络发送
|
||
''' </summary>
|
||
Public _isNetWork As Boolean
|
||
|
||
''' <summary>
|
||
''' 是否是串口发送
|
||
''' </summary>
|
||
Public _isSerialPort As Boolean
|
||
|
||
|
||
|
||
#End Region
|
||
|
||
#Region "权限管理"
|
||
|
||
''' <summary>
|
||
''' 查询到的酒店编码
|
||
''' </summary>
|
||
Public _projectNumber As String
|
||
|
||
''' <summary>
|
||
''' 查询到的酒店名称
|
||
''' </summary>
|
||
Public _HotelName As String
|
||
|
||
''' <summary>
|
||
''' 查询到权限
|
||
''' </summary>
|
||
Public _authorityInfo As New Dictionary(Of String, String)
|
||
|
||
|
||
#End Region
|
||
|
||
#Region "数据库操作"
|
||
|
||
''' <summary>
|
||
''' 登录返回数据
|
||
''' json序列号
|
||
''' </summary>
|
||
Public _loginData As New Dictionary(Of String, LoginReturnDataBLL)
|
||
|
||
''' <summary>
|
||
''' 后台接口返回酒店列表数据
|
||
''' </summary>
|
||
Public _hotelListData As New Dictionary(Of String, BackstageHotelListBLL)
|
||
|
||
''' <summary>
|
||
''' 后台接口返回房型列表数据
|
||
''' </summary>
|
||
Public _roomTypeListData As New Dictionary(Of String, BackstageRoomTypeListBLL)
|
||
|
||
''' <summary>
|
||
''' 后台接口返回主机列表数据
|
||
''' </summary>
|
||
Public _hostListData As New Dictionary(Of String, BackstageHostListBLL)
|
||
|
||
''' <summary>
|
||
''' 语言数据
|
||
''' </summary>
|
||
Public LanguageData As MultiLanguageDAL
|
||
|
||
''' <summary>
|
||
''' SqlServer
|
||
''' </summary>
|
||
Public _SqlServer As New SqlServerDAL
|
||
|
||
''' <summary>
|
||
''' 登录数据库
|
||
''' </summary>
|
||
Public _SqlLogin As New BlvMySql("blv-cloud-db.mysql.rds.aliyuncs.com", 3307, "blv_rcu_config", "blv_rcu", "fnadiaJDIJ7546")
|
||
|
||
|
||
Public Function ConnLoginDataSourse() As Boolean
|
||
If _SqlLogin.ConnMySQLBase() = False Then
|
||
MsgBox($"")
|
||
Return False
|
||
End If
|
||
Console.WriteLine($"登录_权限数据库连接成功!")
|
||
Return True
|
||
End Function
|
||
|
||
|
||
''' <summary>
|
||
''' 用户名
|
||
''' </summary>
|
||
Public _userNames As String
|
||
|
||
''' <summary>
|
||
''' 用户表格
|
||
''' </summary>
|
||
Public _userData As New DataTable
|
||
|
||
'''' <summary>
|
||
'''' 后台数据
|
||
'''' </summary>
|
||
'Public _backstageData As New SqlServerDAL
|
||
|
||
|
||
'''' <summary>
|
||
'''' 连接后台数据源
|
||
'''' </summary>
|
||
'Public Sub ConnBackstageData()
|
||
' _backstageData.ConnDataBase($"boonlive-rcu.com", "", False, "blw", "blw@123")
|
||
|
||
' If _backstageData._isConn = True Then
|
||
' Console.WriteLine($"{LanguageData.StringList(MultiLanguageDAL.StringEnum.Background)}{LanguageData.StringList(MultiLanguageDAL.StringEnum.DatabaseConnectionSuccessful)}!")
|
||
' Else
|
||
' Console.WriteLine($"{LanguageData.StringList(MultiLanguageDAL.StringEnum.Background)}{LanguageData.StringList(MultiLanguageDAL.StringEnum.DatabaseConnectionFailed)}!")
|
||
' End If
|
||
'End Sub
|
||
|
||
|
||
|
||
|
||
'''' <summary>
|
||
'''' 获取匹配的用户信息
|
||
'''' </summary>
|
||
'''' <param name="userAccount">用户账号</param>
|
||
'''' <param name="userPassword">用户密码</param>
|
||
'''' <returns></returns>
|
||
'Public Function UtsGetUserInfo(userAccount As String, userPassword As String) As DataTable
|
||
' Dim dtUser As DataTable
|
||
' Dim dbParam As DbExecutorInitParam = GetDbInitParam()
|
||
|
||
' Using db As New DbExecutor(dbParam.Type, dbParam.ConnectionString)
|
||
' db.Open()
|
||
|
||
' Dim tableName As String = DbTableModel.Manage.UserListTable.TableName
|
||
' Dim condition As String = $"`{DbTableModel.Manage.UserListTable.ColNamesEnum.UserName}` = @user and `{DbTableModel.Manage.UserListTable.ColNamesEnum.Password}` = @pwd"
|
||
' db.AddDbParameter(DbType.AnsiString, "user", userAccount)
|
||
' db.AddDbParameter(DbType.AnsiString, "pwd", MD5.GetStringMd5(MD5.GetStringMd5(userPassword)))
|
||
|
||
' If dbParam.Type = DbExecutor.DbTypeEnum.Sqlite Then
|
||
' dtUser = db.ExecuteDataTable(db.CmdHelper.SearchAll(tableName, condition))
|
||
' Else
|
||
' dtUser = db.ExecuteDataTable(db.CmdHelper.DbSearchAll(UtsDb.RemotePublicDb, tableName, condition))
|
||
' End If
|
||
|
||
' db.Close()
|
||
' End Using
|
||
|
||
' Return dtUser
|
||
'End Function
|
||
|
||
|
||
|
||
|
||
|
||
|
||
#End Region
|
||
|
||
#Region "功能模块"
|
||
|
||
''' <summary>
|
||
''' 本地IP
|
||
''' </summary>
|
||
Public _localIP As String
|
||
|
||
''' <summary>
|
||
''' 本地端口号
|
||
''' </summary>
|
||
Public _localPort As Integer
|
||
|
||
''' <summary>
|
||
''' 远程IP地址
|
||
''' </summary>
|
||
Public _RemoteIP As IPAddress = IPAddress.Parse($"192.168.0.23")
|
||
|
||
''' <summary>
|
||
''' 远程端口号
|
||
''' </summary>
|
||
Public _RemotePort As Integer = 3341
|
||
|
||
''' <summary>
|
||
''' 连接状态,默认非连接
|
||
''' </summary>
|
||
Public _connectStatus As Boolean = False
|
||
|
||
|
||
''' <summary>
|
||
''' 是否通过UDP发送数据
|
||
''' </summary>
|
||
Public _isSendByUdp As Boolean
|
||
|
||
''' <summary>
|
||
''' 回复超时
|
||
''' </summary>
|
||
Public ReadOnly _relayTimeout As Integer = 50
|
||
|
||
''' <summary>
|
||
''' 是否重试绑定MAC
|
||
''' </summary>
|
||
Public _isMACRetry As Boolean
|
||
|
||
''' <summary>
|
||
''' 是否解绑MAC
|
||
''' </summary>
|
||
Public _isMACUnbundle As Boolean
|
||
|
||
|
||
|
||
''' <summary>
|
||
''' 获取本地可用IP
|
||
''' </summary>
|
||
''' <returns></returns>
|
||
Public Function GetLocalIp() As List(Of IPAddress)
|
||
Dim address() As IPAddress
|
||
Dim destAddress As New List(Of IPAddress)
|
||
address = Dns.GetHostEntry(Dns.GetHostName()).AddressList
|
||
For Each pAddress As IPAddress In address
|
||
If pAddress.AddressFamily = AddressFamily.InterNetwork Then
|
||
destAddress.Add(pAddress)
|
||
End If
|
||
Next
|
||
Return destAddress
|
||
End Function
|
||
|
||
|
||
''' <summary>
|
||
''' Byte数组转字符串
|
||
''' </summary>
|
||
''' <param name="databuff"></param>
|
||
''' <returns></returns>
|
||
Public Function ByteToString(databuff() As Byte)
|
||
Dim strData As String = String.Empty
|
||
For i = 0 To databuff.Length - 1
|
||
strData &= $" {Hex(databuff(i)).PadLeft(2, "0"c)}"
|
||
Next
|
||
Return strData
|
||
End Function
|
||
|
||
|
||
''' <summary>
|
||
''' 判断文本不能为空
|
||
''' 文本框
|
||
''' </summary>
|
||
''' <param name="txt"></param>
|
||
''' <returns></returns>
|
||
Public Function TextIsNull(txt As TextBox, Tip As String) As Boolean
|
||
If txt.Text = Nothing Or txt.Text = "" Then
|
||
MsgBox($"{Tip}{LanguageData.StringList(MultiLanguageDAL.StringEnum.NOTNULL)}!")
|
||
Return False
|
||
End If
|
||
Return True
|
||
End Function
|
||
|
||
|
||
''' <summary>
|
||
''' 判断文本不能为空
|
||
''' 下拉框
|
||
''' </summary>
|
||
''' <param name="txt"></param>
|
||
''' <returns></returns>
|
||
Public Function TextIsNull(txt As ComboBox, Tip As String) As Boolean
|
||
If txt.Text = Nothing Or txt.Text = "" Then
|
||
MsgBox($"{Tip} {LanguageData.StringList(MultiLanguageDAL.StringEnum.NOTNULL)}!")
|
||
Return False
|
||
End If
|
||
Return True
|
||
End Function
|
||
|
||
|
||
''' <summary>
|
||
''' 等待回复
|
||
''' </summary>
|
||
''' <param name="isReply">是否回复标志位</param>
|
||
''' <param name="TimeOut">超时时间</param>
|
||
Public Sub WaitReply(isReply As Boolean, TimeOut As Integer) 'ByRef
|
||
Dim tick As Integer
|
||
Dim startTick As Integer = My.Computer.Clock.TickCount
|
||
isReply = False
|
||
While isReply = False AndAlso tick <= TimeOut
|
||
Thread.Sleep(3)
|
||
tick = My.Computer.Clock.TickCount - startTick
|
||
Application.DoEvents()
|
||
End While
|
||
End Sub
|
||
|
||
|
||
''' <summary>
|
||
''' 延时N秒
|
||
''' </summary>
|
||
''' <param name="HowLong">延时时间值</param>
|
||
Public Sub PauseWait(ByVal HowLong As Long)
|
||
Dim tick As Long
|
||
tick = My.Computer.Clock.TickCount
|
||
Do
|
||
My.Application.DoEvents()
|
||
Loop Until tick + HowLong < My.Computer.Clock.TickCount
|
||
End Sub
|
||
|
||
|
||
''' <summary>
|
||
''' IP地址转换为Byte数组
|
||
''' </summary>
|
||
''' <param name="addr"></param>
|
||
''' <returns></returns>
|
||
Public Function GetAddressToBytes(addr As String)
|
||
Dim iadd() As String = addr.Split(New Char() {"."c}, StringSplitOptions.RemoveEmptyEntries)
|
||
Dim address(3) As Byte
|
||
address(0) = iadd(0) '例:192
|
||
address(1) = iadd(1) '例:168
|
||
address(2) = iadd(2)
|
||
address(3) = iadd(3)
|
||
|
||
Return address
|
||
End Function
|
||
|
||
|
||
''' <summary>
|
||
''' 端口号转换为Byte数组
|
||
''' </summary>
|
||
''' <param name="port"></param>
|
||
''' <returns></returns>
|
||
Public Function GetPortToBytes(port As String)
|
||
Dim bport As Integer = CInt(port)
|
||
Dim ports() As Byte = IntToByteLB(bport)
|
||
|
||
Return ports
|
||
End Function
|
||
|
||
|
||
''' <summary>
|
||
''' Int转2个字节Byte
|
||
''' 低字节在前,高字节在后
|
||
''' </summary>
|
||
''' <param name="i"></param>
|
||
''' <returns></returns>
|
||
Public Function IntToByteLB(ByVal i As Integer) As Byte()
|
||
Dim btemp() As Byte = {0, 0}
|
||
Dim b() As Byte = BitConverter.GetBytes(i)
|
||
btemp(0) = b(1)
|
||
btemp(1) = b(0)
|
||
Return btemp
|
||
End Function
|
||
|
||
|
||
''' <summary>
|
||
''' Int转2个字节Byte
|
||
''' 高字节在前,低字节在后
|
||
''' </summary>
|
||
''' <param name="i"></param>
|
||
''' <returns></returns>
|
||
Public Function IntToByteHB(ByVal i As Integer) As Byte()
|
||
Dim btemp() As Byte = {0, 0}
|
||
Dim b() As Byte = BitConverter.GetBytes(i)
|
||
btemp(0) = b(0)
|
||
btemp(1) = b(1)
|
||
Return btemp
|
||
End Function
|
||
|
||
|
||
''' <summary>
|
||
''' 获取文件的MD5值
|
||
''' 返回Byte数组值
|
||
''' </summary>
|
||
''' <param name="filepath">文件路径</param>
|
||
''' <returns></returns>
|
||
Public Function GetMd5(filepath As String) As Byte()
|
||
Dim FileStr As FileStream = New FileStream(filepath, FileMode.Open, FileAccess.Read, FileShare.Read)
|
||
Dim data(FileStr.Length - 1) As Byte
|
||
FileStr.Read(data, 0, data.Length)
|
||
|
||
Dim md5s As Byte() = MD5.Create().ComputeHash(data)
|
||
'Dim fileMd5 As New StringBuilder()
|
||
'Dim i As Integer
|
||
'For i = 0 To md5s.Length - 1
|
||
' fileMd5.Append(md5s(i).ToString("x2"))
|
||
'Next
|
||
|
||
'Console.WriteLine($"MD5:{fileMd5}")
|
||
|
||
Return md5s
|
||
End Function
|
||
|
||
|
||
''' <summary>
|
||
''' 获取文件的MD5值
|
||
''' 返回String字符串
|
||
''' </summary>
|
||
''' <param name="filepath">文件路径</param>
|
||
''' <returns></returns>
|
||
Public Function GetMd5String(filepath As String) As String
|
||
Dim FileStr As FileStream = New FileStream(filepath, FileMode.Open, FileAccess.Read, FileShare.Read)
|
||
Dim data(FileStr.Length) As Byte
|
||
FileStr.Read(data, 0, data.Length)
|
||
|
||
Dim md5s As Byte() = MD5.Create().ComputeHash(data)
|
||
Dim fileMd5 As New StringBuilder()
|
||
Dim i As Integer
|
||
For i = 0 To md5s.Length - 1
|
||
fileMd5.Append(md5s(i).ToString("x2"))
|
||
Next
|
||
|
||
Console.WriteLine($"MD5:{fileMd5}")
|
||
|
||
Return fileMd5.ToString()
|
||
End Function
|
||
|
||
|
||
'''' <summary>
|
||
'''' 获取文件的MD5值
|
||
'''' </summary>
|
||
'''' <param name="filepath">文件路径</param>
|
||
'''' <returns></returns>
|
||
'Public Function GetFileMd5String(filepath As String) As String
|
||
' 'Dim data As Byte() = MD5.Create().ComputeHash(filepath)
|
||
' Dim md5Hasher As New MD5CryptoServiceProvider()
|
||
' Dim data As Byte() = md5Hasher.ComputeHash(IO.File.ReadAllBytes(filepath))
|
||
' Dim fileMd5 As New StringBuilder()
|
||
' Dim i As Integer
|
||
' For i = 0 To data.Length - 1
|
||
' fileMd5.Append(data(i).ToString("x2"))
|
||
' Next
|
||
|
||
' Return fileMd5.ToString()
|
||
'End Function
|
||
|
||
|
||
'''' <summary>
|
||
'''' 获取文件的MD5值
|
||
'''' </summary>
|
||
'''' <param name="filepath">文件路径</param>
|
||
'''' <returns></returns>
|
||
'Public Function GetFileMd5Byte(filepath As String) As Byte()
|
||
' Dim md5Hasher As New MD5CryptoServiceProvider()
|
||
' Dim data As Byte() = md5Hasher.ComputeHash(IO.File.ReadAllBytes(filepath))
|
||
' 'Dim fileMd5 As New StringBuilder()
|
||
' 'Dim i As Integer
|
||
' 'For i = 0 To data.Length - 1
|
||
' ' fileMd5.Append(data(i).ToString("X2"))
|
||
' 'Next
|
||
' 'Return fileMd5.ToString()
|
||
' Return data
|
||
'End Function
|
||
|
||
|
||
''' <summary>
|
||
''' 获取数据的MD5值
|
||
''' 返回MD5校验的Byte数组
|
||
''' </summary>
|
||
''' <param name="data">文件数据</param>
|
||
''' <returns></returns>
|
||
Public Function GetDataMd5Byte(data As Byte()) As Byte()
|
||
Dim databuff As Byte() = MD5.Create().ComputeHash(data)
|
||
|
||
Return databuff
|
||
End Function
|
||
|
||
|
||
''' <summary>
|
||
''' 获取数据的MD5值
|
||
''' 返回MD5校验的Byte数组
|
||
''' </summary>
|
||
''' <param name="data">文件数据</param>
|
||
''' <returns></returns>
|
||
Public Function GetDataMd5String(data As Byte()) As String
|
||
Dim databuff As Byte() = MD5.Create().ComputeHash(data)
|
||
Dim strData As String = BitConverter.ToString(databuff)
|
||
|
||
Return strData
|
||
End Function
|
||
|
||
|
||
''' <summary>
|
||
''' 获取字符串的MD5值
|
||
''' </summary>
|
||
''' <param name="str">需要求MD5的原文字符串</param>
|
||
''' <returns></returns>
|
||
Public Function GetStringMd5(str As String) As String
|
||
Dim md5Hasher As New MD5CryptoServiceProvider()
|
||
Dim data As Byte() = md5Hasher.ComputeHash(Encoding.UTF8.GetBytes(str))
|
||
Dim fileMd5 As New StringBuilder()
|
||
Dim i As Integer
|
||
For i = 0 To data.Length - 1
|
||
fileMd5.Append(data(i).ToString("X2"))
|
||
Next
|
||
|
||
Return fileMd5.ToString()
|
||
End Function
|
||
|
||
|
||
''' <summary>
|
||
''' 分块函数
|
||
''' 计算Byte数组的块数
|
||
''' </summary>
|
||
''' <param name="databuff"></param>
|
||
''' <param name="size"></param>
|
||
''' <returns></returns>
|
||
Public Function GetBlocks(databuff As Byte(), size As Integer) As Integer
|
||
Dim blockCount As Integer = databuff.Length \ size
|
||
If databuff.Length Mod size > 0 Then
|
||
blockCount += 1
|
||
End If
|
||
Return blockCount
|
||
End Function
|
||
|
||
|
||
''' <summary>
|
||
''' 字符串转换Byte数组
|
||
''' 字符串为连续且不包含任意字符的字符串
|
||
''' </summary>
|
||
''' <param name="str"></param>
|
||
''' <returns></returns>
|
||
Public Function GetStringToDataByte(str As String) As Byte()
|
||
Dim dataList As New List(Of Byte)
|
||
|
||
For index As Integer = 0 To str.Length - 1 Step 2
|
||
dataList.Add($"&H{str.Substring(index, 2)}")
|
||
Next
|
||
|
||
Return dataList.ToArray
|
||
End Function
|
||
|
||
|
||
''参数:strTime:要转换的时间;intTimeZone:该时间对应的时区
|
||
''返回值:strTime相对于1970年1月1日午夜0点经过的秒数
|
||
''示例:ToUnixTime("2008-5-23 10:51:0", +8),返回值为1211511060
|
||
'Public Function ToUnixTime(strTime, intTimeZone)
|
||
' If strTime Is Nothing Or Not IsDate(strTime) Then strTime = Now
|
||
' If intTimeZone Is Nothing Or Not IsNumeric(intTimeZone) Then intTimeZone = 0
|
||
' ToUnixTime = DateAdd("h", -intTimeZone, strTime)
|
||
' ToUnixTime = DateDiff("s", "1970-1-1 0:0:0", ToUnixTime)
|
||
'End Function
|
||
|
||
|
||
''' <summary>
|
||
''' 把UNIX时间戳转换为标准时间
|
||
''' </summary>
|
||
''' <param name="intTime">要转换的UNIX时间戳</param>
|
||
''' <param name="ime">时区</param>
|
||
''' <returns>intTime所代表的标准时间</returns>
|
||
Public Function FromUnixTime(intTime As Long, ime As Long) As Date
|
||
'If intTime Is Nothing Or Not IsNumeric(intTime) Then
|
||
' FromUnixTime = Now()
|
||
' Exit Function
|
||
'End If
|
||
'If intTime Is Nothing Or Not IsNumeric(intTimeZone) Then intTimeZone = 0
|
||
'FromUnixTime = DateAdd("s", intTime, "1970-1-1 0:0:0")
|
||
'FromUnixTime = DateAdd("h", intTimeZone, FromUnixTime)
|
||
|
||
Dim a As Date = DateTime.Parse("1970-1-1 0:0:0")
|
||
a = a.AddSeconds(intTime)
|
||
a = a.AddHours(ime)
|
||
|
||
Return a
|
||
End Function
|
||
|
||
''' <summary>
|
||
''' 判断网络信息是否合法
|
||
''' </summary>
|
||
''' <param name="text"></param>
|
||
''' <param name="Tip"></param>
|
||
''' <returns></returns>
|
||
Public Function GetNetworkInfoIsLegal(text As String, Tip As String) As Boolean
|
||
If GetTxStringIsLegal(text) = False Then
|
||
MsgBox($"{Tip} 输入不合法!")
|
||
Return False
|
||
End If
|
||
|
||
Return True
|
||
End Function
|
||
|
||
''' <summary>
|
||
''' 判断文本输入控件输入是否合法
|
||
''' </summary>
|
||
''' <param name="text"></param>
|
||
''' <returns></returns>
|
||
Public Function GetTxStringIsLegal(text As String) As Boolean
|
||
If IsNumeric(text) = True AndAlso text <> "" Then
|
||
Return True
|
||
End If
|
||
|
||
Return False
|
||
End Function
|
||
|
||
|
||
'''' <summary>
|
||
'''' 两个字节Byte转Int
|
||
'''' </summary>
|
||
'''' <param name="datas"></param>
|
||
'''' <returns></returns>
|
||
'Private Function GetByteToInt(datas() As Byte)
|
||
' 'Dim ints As Integer = CInt(datas(0)) + CInt(datas(1) * 256)
|
||
' Dim ints As Integer = BitConverter.ToUInt16(datas, 0)
|
||
|
||
' Return ints
|
||
'End Function
|
||
|
||
|
||
|
||
|
||
|
||
#End Region
|
||
|
||
#Region "后台接口"
|
||
|
||
|
||
''' <summary>
|
||
''' Post请求
|
||
''' </summary>
|
||
''' <param name="url"></param>
|
||
''' <param name="data"></param>
|
||
''' <returns></returns>
|
||
Public Function PostData(ByVal url As String, ByVal data As String) As String
|
||
ServicePointManager.Expect100Continue = False
|
||
Dim request As HttpWebRequest = WebRequest.Create(url)
|
||
'//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
|
||
'获得请 求流
|
||
'MsgBox("0.0.1")
|
||
Dim newStream As Stream = request.GetRequestStream()
|
||
' MsgBox("0.0.2")
|
||
newStream.Write(bys, 0, bys.Length)
|
||
newStream.Close()
|
||
'获得响应流
|
||
Dim sr As StreamReader = New StreamReader(request.GetResponse().GetResponseStream)
|
||
' MsgBox("0.0.3")
|
||
Return sr.ReadToEnd
|
||
End Function
|
||
|
||
|
||
''' <summary>
|
||
''' 处理酒店列表接口信息
|
||
''' </summary>
|
||
''' <returns></returns>
|
||
Public Function DealHotelListInterfaceInfo() As Boolean
|
||
Dim key As String = "blw_ws@2015"
|
||
''https://www.boonlive-rcu.com/api/GetHotelList?jsonData={"key":"blw_ws@2015"}
|
||
Dim jsonString As String = PostData("https://www.boonlive-rcu.com/api/GetHotelList", $"jsonData={{""key"":""{key}""}}")
|
||
Console.WriteLine($"后台接口_获取酒店列表:" & jsonString)
|
||
'MsgBox("0.1")
|
||
Dim hotelList As BackstageHotelListResultBLL = JsonConvert.DeserializeObject(Of BackstageHotelListResultBLL)(jsonString)
|
||
'MsgBox("0.2")
|
||
If hotelList.IsSuccess = False Then
|
||
MsgBox($"解析酒店列表接口错误!")
|
||
Return False
|
||
End If
|
||
'MsgBox("0.3")
|
||
_hotelListData.Clear()
|
||
For i = 0 To hotelList.Result.Count - 1
|
||
Dim datalist As New BackstageHotelListBLL
|
||
datalist.ID = hotelList.Result(i).ID
|
||
datalist.Code = hotelList.Result(i).Code
|
||
datalist.Name = hotelList.Result(i).Name
|
||
datalist.EName = hotelList.Result(i).EName
|
||
datalist.TWName = hotelList.Result(i).TWName
|
||
datalist.Contact = hotelList.Result(i).Contact
|
||
datalist.Phone = hotelList.Result(i).Phone
|
||
datalist.Address = hotelList.Result(i).Address
|
||
datalist.ValidateDate = hotelList.Result(i).ValidateDate
|
||
datalist.CreatDate = hotelList.Result(i).CreatDate
|
||
datalist.Remark = hotelList.Result(i).Remark
|
||
datalist.Status = hotelList.Result(i).Status
|
||
datalist.IsApprove = hotelList.Result(i).IsApprove
|
||
datalist.SysHotelGroupID = hotelList.Result(i).SysHotelGroupID
|
||
datalist.SysHotelGroupName = hotelList.Result(i).SysHotelGroupName
|
||
|
||
_hotelListData.Add(datalist.Code, datalist)
|
||
Next
|
||
' MsgBox("0.4")
|
||
Return True
|
||
End Function
|
||
|
||
|
||
''' <summary>
|
||
''' 处理主机列表接口信息
|
||
''' </summary>
|
||
''' <returns></returns>
|
||
Public Function DealRoomTypeListInterfaceInfo(code As String, creatDate As String) As Boolean
|
||
Console.WriteLine($"code:{code}————creatDate:{creatDate}")
|
||
Dim jsonString As String = PostData("https://www.boonlive-rcu.com/api/GetRoomTypeAndModalsList", $"jsonData={{""code"":""{code}"", ""creatDate"":""{creatDate}""}}")
|
||
Console.WriteLine($"后台接口_获取房型列表:" & jsonString)
|
||
|
||
Dim roomTypeList As BackstageRoomTypeListResultBLL = JsonConvert.DeserializeObject(Of BackstageRoomTypeListResultBLL)(jsonString)
|
||
If roomTypeList.IsSuccess = False Then
|
||
MsgBox($"解析房型列表接口错误!")
|
||
Return False
|
||
End If
|
||
|
||
_roomTypeListData.Clear()
|
||
For i = 0 To roomTypeList.Result.Count - 1
|
||
Dim datalist As New BackstageRoomTypeListBLL
|
||
datalist.ID = roomTypeList.Result(i).ID
|
||
datalist.Code = roomTypeList.Result(i).Code
|
||
datalist.Name = roomTypeList.Result(i).Name
|
||
datalist.Modals = roomTypeList.Result(i).Modals
|
||
|
||
_roomTypeListData.Add(i, datalist)
|
||
Next
|
||
|
||
Return True
|
||
End Function
|
||
|
||
|
||
''' <summary>
|
||
''' 处理主机列表接口信息
|
||
''' </summary>
|
||
''' <returns></returns>
|
||
Public Function DealHostListInterfaceInfo(code As String, creatDate As String) As Boolean
|
||
'Dim codes As String = _hotelListData.Keys(1)
|
||
'Dim creatDates As String = _hotelListData.Values(1).CreatDate
|
||
Console.WriteLine($"code:{code}————creatDate:{creatDate}")
|
||
|
||
Dim jsonString As String = PostData("https://www.boonlive-rcu.com/api/GetHostList", $"jsonData={{""code"":""{code}"", ""creatDate"":""{creatDate}""}}")
|
||
Console.WriteLine($"后台接口_获取主机列表:" & jsonString)
|
||
|
||
Dim hostList As BackstageHostListResultBLL = JsonConvert.DeserializeObject(Of BackstageHostListResultBLL)(jsonString)
|
||
If hostList.IsSuccess = False Then
|
||
MsgBox($"解析主机列表接口错误!")
|
||
Return False
|
||
End If
|
||
|
||
_hostListData.Clear()
|
||
For i = 0 To hostList.Result.Count - 1
|
||
Dim datalist As New BackstageHostListBLL
|
||
datalist.ID = hostList.Result(i).ID
|
||
datalist.HotelID = hostList.Result(i).HotelID
|
||
datalist.HotelName = hostList.Result(i).HotelName
|
||
datalist.HostNumber = hostList.Result(i).HostNumber
|
||
datalist.RoomNumber = hostList.Result(i).RoomNumber
|
||
datalist.Status = hostList.Result(i).Status
|
||
datalist.RegisterDate = hostList.Result(i).RegisterDate
|
||
datalist.RoomStatusID = hostList.Result(i).RoomStatusID
|
||
datalist.RoomStatusName = hostList.Result(i).RoomStatusName
|
||
datalist.RoomTypeID = hostList.Result(i).RoomTypeID
|
||
datalist.RoomTypeName = hostList.Result(i).RoomTypeName
|
||
datalist.MAC = hostList.Result(i).MAC
|
||
datalist.MACBindDate = hostList.Result(i).MACBindDate
|
||
datalist.IP = hostList.Result(i).IP
|
||
datalist.Remark = hostList.Result(i).Remark
|
||
|
||
_hostListData.Add(i, datalist)
|
||
Next
|
||
|
||
Return True
|
||
End Function
|
||
|
||
|
||
''' <summary>
|
||
''' 设置MAC地址返回结果
|
||
''' </summary>
|
||
Public _setResult As String
|
||
|
||
|
||
''' <summary>
|
||
''' 处理设置主机MAC接口信息
|
||
''' </summary>
|
||
''' <returns></returns>
|
||
Public Function DealSetHostMACInterfaceInfo(code As String, creatDate As String, roomNumber As String, mac As String) As Boolean
|
||
'code As String, creatDate As String, roomNumber As String, mac As String
|
||
'Dim code As String = _hotelListData.Keys(2)
|
||
'Dim creatDate As String = _hotelListData.Values(2).CreatDate
|
||
'Dim roomNumber As String = _hostListData.Values(1).RoomNumber
|
||
'Dim mac As String = _hostListData.Values(1).MAC
|
||
Console.WriteLine($"code:{code}——creatDate:{creatDate}——roomNumber:{roomNumber}——mac:{mac}")
|
||
|
||
Dim jsonString As String = PostData("https://www.boonlive-rcu.com/api/SetHostMAC", $"jsonData={{""code"":""{code}"", ""creatDate"":""{creatDate}"", ""roomNumber"":""{roomNumber}"", ""mac"":""{mac}""}}")
|
||
Console.WriteLine($"后台接口_设置主机MAC:" & jsonString)
|
||
|
||
Dim setHostMAC As BackstageSetHostMACBLL = JsonConvert.DeserializeObject(Of BackstageSetHostMACBLL)(jsonString)
|
||
'If setHostMAC.IsSuccess = False Then
|
||
' 'MsgBox($"解析主机MAC接口错误!")
|
||
' Return False
|
||
'End If
|
||
|
||
_setResult = setHostMAC.Result
|
||
Return setHostMAC.IsSuccess
|
||
End Function
|
||
|
||
|
||
|
||
|
||
|
||
#End Region
|
||
|
||
#Region "获取端口随机数"
|
||
|
||
''' <summary>
|
||
''' 获取操作系统已用的端口号
|
||
''' </summary>
|
||
Public Function PortIsUsed()
|
||
'获取本地计算机的网络连接和通信统计数据的信息
|
||
Dim ipGlobal As IPGlobalProperties = IPGlobalProperties.GetIPGlobalProperties()
|
||
|
||
'返回本地计算机上的所有Tcp监听程序
|
||
Dim ipsTcp As IPEndPoint() = ipGlobal.GetActiveTcpListeners()
|
||
|
||
'返回本地计算机上的所有UDP监听程序
|
||
Dim ipsUdp As IPEndPoint() = ipGlobal.GetActiveUdpListeners()
|
||
|
||
'返回本地计算机上的Internet协议版本4(IPV4 传输控制协议(TCP)连接的信息
|
||
Dim tcpConn As TcpConnectionInformation() = ipGlobal.GetActiveTcpConnections()
|
||
|
||
Dim allports As IList = New ArrayList()
|
||
For Each ep As IPEndPoint In ipsTcp
|
||
allports.Add(ep.Port)
|
||
Next
|
||
|
||
For Each ep As IPEndPoint In ipsUdp
|
||
allports.Add(ep.Port)
|
||
Next
|
||
|
||
For Each conn As TcpConnectionInformation In tcpConn
|
||
allports.Add(conn.LocalEndPoint.Port)
|
||
Next
|
||
Return allports
|
||
End Function
|
||
|
||
|
||
''' <summary>
|
||
''' 获取随机端口号
|
||
''' </summary>
|
||
''' <returns></returns>
|
||
Public Function GetRandomPort()
|
||
Dim port As Integer = 0
|
||
Dim hasUserdPort As IList = PortIsUsed()
|
||
Dim isRandomOk As Boolean = True
|
||
Dim random As Random = New Random(Date.Now.Millisecond)
|
||
|
||
While isRandomOk
|
||
port = random.Next(1024, 65535)
|
||
isRandomOk = hasUserdPort.Contains(port)
|
||
End While
|
||
|
||
Return port
|
||
End Function
|
||
|
||
|
||
#End Region
|
||
|
||
#Region "机型测试"
|
||
|
||
''' <summary>发送测试数据序号</summary>
|
||
Public _dataNumber As Byte = 0
|
||
|
||
|
||
''' <summary>
|
||
''' 填充C5串口测试
|
||
''' </summary>
|
||
''' <param name="data"></param>
|
||
''' <returns></returns>
|
||
Public Function FillModelsSerialPortTest(cmd As Byte, data As Byte()) As Byte()
|
||
Dim ourAddress As Byte = &H0 '己方地址
|
||
Dim sendNumber As Byte = GetSendNumber() '发送序号
|
||
Dim devType As Byte = &HF2 '设备类型
|
||
Dim putAddress As Byte = &H0 '收方地址
|
||
Dim len(1) As Byte '数据长度,占2个字节
|
||
Dim dataSum As Byte '校验和
|
||
Dim length As Integer = 8 + data.Length
|
||
len = IntToByteHB(length)
|
||
|
||
Dim databuff As New List(Of Byte)
|
||
databuff.Add(ourAddress)
|
||
databuff.Add(sendNumber)
|
||
databuff.Add(devType)
|
||
databuff.Add(putAddress)
|
||
databuff.AddRange(len)
|
||
databuff.Add(cmd)
|
||
databuff.AddRange(data)
|
||
|
||
dataSum = GetSumCheckMod(databuff.ToArray)
|
||
databuff.Insert(6, dataSum)
|
||
|
||
Return databuff.ToArray
|
||
End Function
|
||
|
||
|
||
''' <summary>
|
||
''' 获取发送序号
|
||
''' </summary>
|
||
''' <returns></returns>
|
||
Public Function GetSendNumber()
|
||
_dataNumber += 1
|
||
If _dataNumber > 15 Then
|
||
_dataNumber = 1
|
||
End If
|
||
|
||
Return _dataNumber
|
||
End Function
|
||
|
||
''' <summary>
|
||
''' 和校验取余数
|
||
''' 求Byte数组的和校验取余数
|
||
''' </summary>
|
||
''' <param name="dataPacket">Byte数组</param>
|
||
''' <returns></returns>
|
||
Public Function GetSumCheckMod(dataPacket As Byte()) As Byte
|
||
Dim sum As Integer
|
||
For idx = 0 To dataPacket.Length - 1
|
||
sum += dataPacket(idx)
|
||
sum = sum And &HFF
|
||
Next
|
||
Dim sumMod As Byte = &HFF - sum
|
||
Return sumMod
|
||
End Function
|
||
|
||
''' <summary>
|
||
''' 填充测试数据参数
|
||
''' </summary>
|
||
''' <param name="testState">测试状态</param>
|
||
''' <param name="devType">设备类型</param>
|
||
''' <param name="devAddr">设备地址-默认为0</param>
|
||
''' <param name="devCmd">测试设备Cmd</param>
|
||
''' <param name="param">参数</param>
|
||
''' <returns></returns>
|
||
Public Function FillTestDatabuff(testState As Byte, devType As Byte, devAddr As Byte, devCmd As Byte, param As Byte()) As Byte()
|
||
Dim data As New List(Of Byte)
|
||
data.Add(testState)
|
||
data.Add(devType)
|
||
data.Add(devAddr)
|
||
data.Add(devCmd)
|
||
data.AddRange(param)
|
||
|
||
Return data.ToArray
|
||
End Function
|
||
|
||
''' <summary>
|
||
''' 填充测试数据参数
|
||
''' </summary>
|
||
''' <param name="testState">测试状态</param>
|
||
''' <param name="devType">设备类型</param>
|
||
''' <param name="devAddr">设备地址-默认为0</param>
|
||
''' <param name="devCmd">测试设备Cmd</param>
|
||
''' <returns></returns>
|
||
Public Function FillTestDatabuff(testState As Byte, devType As Byte, devAddr As Byte, devCmd As Byte) As Byte()
|
||
Dim data As New List(Of Byte)
|
||
data.Add(testState)
|
||
data.Add(devType)
|
||
data.Add(devAddr)
|
||
data.Add(devCmd)
|
||
|
||
Return data.ToArray
|
||
End Function
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
#End Region
|
||
|
||
|
||
|
||
|
||
End Module
|