当前位置:编程学习 > C#/ASP.NET >>

C#语音读取验证码

<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");
        }

 

 摘自:hongjiaoli的专栏

补充:软件开发 , C# ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,