Imports System.IO
Imports System.Net
Imports System.Text

Public Class AutsSqlApi


    Private  pow As String ="$%@132"
    Private DBName As String = "uts_zongqing"
    Public Shared 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
        '获得请 求流
        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

''' <summary>
''' 机身码与彩盒码绑定
''' {"Mars_ColorBox_BarCode":"CTHM08711382252033277"
'''"Message":"成功"
'''"Barcode":"1234"}   = 
''' </summary>
''' <param name="Uart">网络地址</param>
''' <param name="Barcode">机身码</param>
''' <param name="DBName">数据库名</param>

    Public Function   BindColorBoxCode(Uart As String ,Barcode As String ,DBName As String  )as BindColorBoxCodeClass
         
        Dim jsonString As String = String.Empty
        Try
            jsonString = PostData(Uart, $"Pwd={pow}&Barcode={Barcode}&DBName={DBName}")
            
        Catch ex As Exception
            MsgBox($"{ex.Message}！请联系管理员")
        End Try
        Console.WriteLine(jsonString)


    End Function


    Public sub  ModifyingBindingInfo


   
End Class




Public Class   BindColorBoxCodeClass

   Public  Mars_ColorBox_BarCode As String 
    Public Message As String 
    Public Barcode As  String 

End Class
