国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 學(xué)院 > 開(kāi)發(fā)設(shè)計(jì) > 正文

ASP.NET(c#)語(yǔ)音驗(yàn)證碼制作(附源代碼)

2019-11-17 04:01:05
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友
最近發(fā)現(xiàn)語(yǔ)音驗(yàn)證碼越來(lái)越流行,比如有次在注冊(cè)Gmail郵箱看到過(guò),還有msn頁(yè)面也有語(yǔ)音驗(yàn)證碼,還有國(guó)外一些網(wǎng)站等。
花時(shí)間研究了下,語(yǔ)音驗(yàn)證碼主要跟一般驗(yàn)證碼的區(qū)別就在于如何讓驗(yàn)證碼播放。本文語(yǔ)音驗(yàn)證碼原理:從服務(wù)器生成驗(yàn)證碼,
并保存到cookie中(getcode.aspx.cs),當(dāng)點(diǎn)收聽(tīng)驗(yàn)證碼的時(shí)候,調(diào)用javascirpt操作(這里使用jquery)cookie讀取驗(yàn)證碼,
然后把驗(yàn)證碼傳到codevoice.aspx頁(yè),然后按順序把驗(yàn)證碼合成生成一個(gè)mp3文件,最后把這個(gè)文件傳入Flash中播放,
你將收聽(tīng)的聲音為:“當(dāng)前驗(yàn)證碼是5678請(qǐng)輸入”。這個(gè)原理也是大部分網(wǎng)站使用的語(yǔ)音驗(yàn)證碼原理類似。
源碼下載:下載 (請(qǐng)使用VS2008 SP1或VS2010打開(kāi))
頁(yè)面上放置驗(yàn)證碼圖片頁(yè)面代碼
view plaincopy to clipboardPRint?
<form id="form1" runat="server">   
    <div>   
     <input  type="text" name="txtCode" id="txtCode" maxlength="8"  />   
<img onclick="this.src='getcode.aspx';" src="getcode.aspx" mce_src="getcode.aspx" align="absmiddle" style="cursor: pointer" mce_style="cursor: pointer" alt="看不清楚,換一張" title="看不清楚,換一張" />   
<img id="imgRead" src="image/maintb.gif" mce_src="image/maintb.gif" align="absmiddle" style="cursor: pointer" mce_style="cursor: pointer" alt="收聽(tīng)驗(yàn)證碼" title="收聽(tīng)驗(yàn)證碼" onclick="playvoice('player');" />   
<span id="player"></span>    
    </div>   
    </form>  
<form id="form1" runat="server">
    <div>
     <input  type="text" name="txtCode" id="txtCode" maxlength="8"  />
<img onclick="this.src='getcode.aspx';" src="getcode.aspx" mce_src="getcode.aspx" align="absmiddle" style="cursor: pointer" mce_style="cursor: pointer" alt="看不清楚,換一張" title="看不清楚,換一張" />
<img id="imgRead" src="image/maintb.gif" mce_src="image/maintb.gif" align="absmiddle" style="cursor: pointer" mce_style="cursor: pointer" alt="收聽(tīng)驗(yàn)證碼" title="收聽(tīng)驗(yàn)證碼" onclick="playvoice('player');" />
<span id="player"></span>
    </div>
    </form>


點(diǎn)收聽(tīng)驗(yàn)證碼時(shí)調(diào)用的js函數(shù)如下:
view plaincopy to clipboardprint?
function playvoice(id) {   
    var voiceid = document.getElementById(id);   
    var voicecode = $.cookie('ValidateCode');   
    voiceid.innerHTML = "<embed id='sound_play' name='sound_play' src="sound_play.swf?" + (new Date().getTime()) + "" mce_src="sound_play.swf?" + (new Date().getTime()) + ""    
FlashVars='isPlay=1&url=codevoice.aspx&code=" + voicecode + "' width='0' height='0' allowScriptaccess='always'    
ype='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' /></embed>";   
}  
function playvoice(id) {
     var voiceid = document.getElementById(id);
     var voicecode = $.cookie('ValidateCode');
     voiceid.innerHTML = "<embed id='sound_play' name='sound_play' src="sound_play.swf?" + (new Date().getTime()) + "" mce_src="sound_play.swf?" + (new Date().getTime()) + ""
FlashVars='isPlay=1&url=codevoice.aspx&code=" + voicecode + "' width='0' height='0' allowScriptAccess='always'
type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' /></embed>";
}


其中$.cookie('ValidateCode')是讀取cookie驗(yàn)證碼,這里使用了一個(gè)jquery操作cookie插件

生成mp3頁(yè)面代碼如下:
     //讀取驗(yàn)證碼生成mp3,這里包括頭部begin.mp3和尾部end.mp3
view plaincopy to clipboardprint?
Response.ContentType = "audio/mpeg";   
           Response.WriteFile("sound/begin.mp3");   
           string checkCode = HttpContext.Current.Request.QueryString["code"].ToString();// string checkCode ="8888";   
           if (checkCode.Length > 0)   
               for (int i = 0; i < checkCode.Length; i++)   
               {   
                   Response.WriteFile("sound/"+checkCode[i] + ".mp3");   
               }   
           Response.WriteFile("sound/end.mp3");  
Response.ContentType = "audio/mpeg";
            Response.WriteFile("sound/begin.mp3");
            string checkCode = HttpContext.Current.Request.QueryString["code"].ToString();// string checkCode ="8888";
            if (checkCode.Length > 0)
                for (int i = 0; i < checkCode.Length; i++)
                {
                    Response.WriteFile("sound/"+checkCode[i] + ".mp3");
                }
            Response.WriteFile("sound/end.mp3");
            

【本文作者分別在VEVb,csdn,http://www.Ajaxcn.net同步發(fā)布,轉(zhuǎn)載請(qǐng)保留此說(shuō)明】
flash播放代碼主要在第一幀關(guān)鍵幀右擊動(dòng)作,插入以下代碼根據(jù)傳入的播放數(shù)字mp3地址

view plaincopy to clipboardprint?
var mysound = new Sound();   
var mysong = url;   
var isPlay = 1;   
var intnum:Number = setInterval(playSong, 500);   
function playSong() {   
if (isPlay == 1) {   
  mysound.loadSound(mysong+"?code="+code, true);   
  mysound.start();   
  clearInterval(intnum);   
  isPlay = 0;   
}   
}  
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 七台河市| 景泰县| 新乡县| 湘潭市| 四子王旗| 岫岩| 敦化市| 大安市| 大荔县| 齐河县| 天峨县| 常山县| 湖北省| 琼海市| 奈曼旗| 葫芦岛市| 梓潼县| 合阳县| 郑州市| 福清市| 友谊县| 睢宁县| 千阳县| 天津市| 枣庄市| 达拉特旗| 五家渠市| 枝江市| 子长县| 苗栗市| 五大连池市| 蕲春县| 磐石市| 肥西县| 白城市| 内江市| 丰镇市| 昌乐县| 宜兰县| 卢湾区| 山东省|