您好,登錄后才能下訂單哦!
這篇文章將為大家詳細講解有關VB.NET中怎么獲取中文驗證碼,文章內容質量較高,因此小編分享給大家做個參考,希望大家閱讀完這篇文章后對相關知識有一定的了解。
VB.net菜單:項目 --> XXX 屬性... --> 配置 --> 優化 --> 選中“移除整數溢出檢查”復選框
下面來仔細研究一下VB.NET中文驗證碼的相關代碼編寫:
Function RndStr()Function
RndStr() As String
Dim gb As SystemSystem.Text.
Encoding = System.Text.Encoding.
GetEncoding("gb2312")
Dim bytes As Object() =
CreateRegionCode(4)
Dim str1 As String = gb.GetString
(DirectCast(Convert.ChangeType
(bytes(0), GetType(Byte())), Byte()))
Dim str2 As String = gb.GetString
(DirectCast(Convert.ChangeType
(bytes(1), GetType(Byte())), Byte()))
Dim str3 As String = gb.GetString
(DirectCast(Convert.ChangeType
(bytes(2), GetType(Byte())), Byte()))
Dim str4 As String = gb.GetString
(DirectCast(Convert.ChangeType
(bytes(3), GetType(Byte())), Byte()))
Dim txt As String = (str1 &
str2 & str3 & str4)
End Function
Function CreateRegionCode()Function
CreateRegionCode(ByVal strlength
As Integer) As Object()
Dim rBase As String() = New String()
{"0", "1", "2", "3", "4", "5",
"6", "7", "8", "9", "a", "b",
"c", "d", "e", "f"}
Dim rnd As New Random
Dim bytes As Object() = New
Object(strlength - 1) {}
Dim i As Integer = 0
Do While (i < strlength)
Dim r2 As Integer
Dim r4 As Integer
Dim r1 As Integer = rnd.Next(11, 14)
Dim str_r1 As String = rBase(r1).Trim
rnd = New Random(r1 * DateTime.
Now.Ticks + i)
If (r1 = 13) Then
r2 = rnd.Next(0, 7)
Else
r2 = rnd.Next(0, &H10)
End If
Dim str_r2 As String = rBase(r2).Trim
Dim r3 As Integer = New Random(
(r2 * DateTime.Now.Ticks) + i).
Next(10, &H10)
Dim str_r3 As String = rBase(r3).Trim
rnd = New Random((r3 * DateTime.
Now.Ticks) + i)
Select Case r3
Case 10
r4 = rnd.Next(1, &H10)
Exit Select
Case 15
r4 = rnd.Next(0, 15)
Exit Select
Case Else
r4 = rnd.Next(0, &H10)
Exit Select
End Select
Dim str_r4 As String = rBase(r4).Trim
Dim byte1 As Byte = Convert.
ToByte((str_r1 & str_r2), &H10)
Dim byte2 As Byte = Convert.
ToByte((str_r3 & str_r4), &H10)
Dim str_r As Byte() = New Byte()
{byte1, byte2}
bytes.SetValue(str_r, i)
i += 1
Loop
Return bytes
End Function
關于VB.NET中怎么獲取中文驗證碼就分享到這里了,希望以上內容可以對大家有一定的幫助,可以學到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。