C#語音讀取驗證碼

來源:互聯網
上載者:User

 <tr>
            <td class="right">
                <span>*</span>驗證碼:</td>
            <td width="165px">
                <input name="checkcode" type="text" maxlength="4" class="login_input" style="width: 80px"
                    id="checkcode" runat="server" /></td>
            <td width="146px">
                <img src="Common/getcode.aspx" id="safecode" onclick="reloadcode();" style="cursor: pointer"
                    height="40px" alt="看不清楚,換一張" title="看不清楚,換一張" /></td>
            <td class="left">
                <img id="imgRead" src="sound/maintb.gif" style="cursor: pointer;" alt="收聽驗證碼" title="收聽驗證碼"
                    onclick="playvoice('player');" align="absmiddle" />
            </td>
        </tr>

=================================================================================================

<script language="javascript" type="text/javascript" event="onkeydown" for="document">

   if( event.keyCode==81 && event.altKey)
   {
    document.suggestForm.verifycode.focus();
    playvoice("player");
   }

    </script>

    <script type="text/javascript" language="javascript">
     function reloadcode()
     {
        var verify=document.getElementById('safecode');
        verify.setAttribute('src','../Common/getcode.aspx?'+Math.random());
     }
    function playvoice(id)
     {
         var voiceid = document.getElementById(id);
         voiceid.innerHTML = "<embed id='sound_play' name='sound_play' src='sound/sound_play.swf?" + (new Date().getTime()) + "'  FlashVars='isPlay=1&url=CodeVoice.aspx&code=" + Math.random() + "' width='0' height='0' allowScriptAccess='always' type='application/x-shockwave-flash'
pluginspage='http://www.macromedia.com/go/getflashplayer' /></embed>";
     }
    </script>

備忘:

1、Registe.aspx(放有讀取驗證碼功能的頁面)需要放在根目錄下。(放在檔案夾下面的話語音功能不能使用,原因暫時不明確)

2、sound檔案夾下面存放的檔案有:begin.mp3;end.mp3 和 sound_play.swf這3個檔案。

      根目錄下CodeVoice.aspx(頁面代碼全部刪除,只留標頭檔即可)

      cs代碼如下:

protected void Page_Load(object sender, EventArgs e)
        {
            //讀取驗證碼產生mp3,這裡包括頭部begin.mp3和尾部end.mp3
            Response.ContentType = "audio/mpeg";
            Response.WriteFile("Sound/begin.mp3");
            string checkCode = "";
            if (Session["CheckCode"] != null)
            {
                checkCode = Session["CheckCode"].ToString();
            }
            if (checkCode.Length > 0)
                for (int i = 0; i < checkCode.Length; i++)
                {
                    Response.WriteFile("Sound/" + checkCode[i] + ".mp3");
                }
            Response.WriteFile("Sound/end.mp3");
        }

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.