溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

VB.NET中怎么獲取中文驗(yàn)證碼

發(fā)布時(shí)間:2021-07-19 16:04:49 來源:億速云 閱讀:127 作者:Leah 欄目:編程語言

這篇文章將為大家詳細(xì)講解有關(guān)VB.NET中怎么獲取中文驗(yàn)證碼,文章內(nèi)容質(zhì)量較高,因此小編分享給大家做個(gè)參考,希望大家閱讀完這篇文章后對相關(guān)知識有一定的了解。

VB.net菜單:項(xiàng)目 --> XXX 屬性... --> 配置 --> 優(yōu)化 --> 選中“移除整數(shù)溢出檢查”復(fù)選框

下面來仔細(xì)研究一下VB.NET中文驗(yàn)證碼的相關(guān)代碼編寫:

  1. Function RndStr()Function 
    RndStr() As String  

  2. Dim gb As SystemSystem.Text.
    Encoding
     = System.Text.Encoding.
    GetEncoding("gb2312")  

  3. Dim bytes As Object() = 
    CreateRegionCode(4)  

  4. Dim str1 As String = gb.GetString
    (DirectCast(Convert.ChangeType
    (bytes(0), GetType(Byte())), Byte()))  

  5. Dim str2 As String = gb.GetString
    (DirectCast(Convert.ChangeType
    (bytes(1), GetType(Byte())), Byte()))  

  6. Dim str3 As String = gb.GetString
    (DirectCast(Convert.ChangeType
    (bytes(2), GetType(Byte())), Byte()))  

  7. Dim str4 As String = gb.GetString
    (DirectCast(Convert.ChangeType
    (bytes(3), GetType(Byte())), Byte()))  

  8. Dim txt As String = (str1 & 
    str2 & str3 & str4)  

  9. End Function  

  10. Function CreateRegionCode()Function 
    CreateRegionCode(ByVal strlength 
    As Integer) As Object()  

  11. Dim rBase As String() = New String() 
    {"0", "1", "2", "3", "4", "5", 
    "6", "7", "8", "9", "a", "b", 
    "c", "d", "e", "f"}  

  12. Dim rnd As New Random  

  13. Dim bytes As Object() = New 
    Object(strlength - 1) {}  

  14. Dim i As Integer = 0 

  15. Do While (i < strlength)  

  16. Dim r2 As Integer  

  17. Dim r4 As Integer  

  18. Dim r1 As Integer = rnd.Next(11, 14)  

  19. Dim str_r1 As String = rBase(r1).Trim  

  20. rnd = New Random(r1 * DateTime.
    Now.Ticks + i)  

  21. If (r1 = 13) Then  

  22. r2 = rnd.Next(0, 7)  

  23. Else  

  24. r2 = rnd.Next(0, &H10)  

  25. End If  

  26. Dim str_r2 As String = rBase(r2).Trim  

  27. Dim r3 As Integer = New Random(
    (r2 * DateTime.Now.Ticks) + i).
    Next(10, &H10)  

  28. Dim str_r3 As String = rBase(r3).Trim  

  29. rnd = New Random((r3 * DateTime.
    Now.Ticks) + i)  

  30. Select Case r3  

  31. Case 10  

  32. r4 = rnd.Next(1, &H10)  

  33. Exit Select  

  34. Case 15  

  35. r4 = rnd.Next(0, 15)  

  36. Exit Select  

  37. Case Else  

  38. r4 = rnd.Next(0, &H10)  

  39. Exit Select  

  40. End Select  

  41. Dim str_r4 As String = rBase(r4).Trim  

  42. Dim byte1 As Byte = Convert.
    ToByte((str_r1 & str_r2), &H10)  

  43. Dim byte2 As Byte = Convert.
    ToByte((str_r3 & str_r4), &H10)  

  44. Dim str_r As Byte() = New Byte() 
    {byte1, byte2}  

  45. bytes.SetValue(str_r, i)  

  46. i += 1  

  47. Loop  

  48. Return bytes  

  49. End Function 

關(guān)于VB.NET中怎么獲取中文驗(yàn)證碼就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,可以學(xué)到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI