Recently, we found that voice verification codes are becoming more and more popular. For example, we once saw it in the registered Gmail mailbox, and we also saw the voice verification code on the MSN page, as well as some foreign websites.
The difference between the voice verification code and the general verification code is how to play the verification code. Principle of voice verification code in this article: generate a verification code from the server,
And save it to the cookie (getcode. aspx. CS). When you listen to the Verification Code, call the unzip cirpt operation (jquery is used here) to read the verification code,
Then, upload the verification code to the codevoice. ASPX page, combine the verification code to generate an MP3 file, and pass the file to flash for playback,
The voice you will listen to is: "The current verification code is 5678 please input ". This principle is similar to the principle of voice verification codes used by most websites.
Source code download: Download (use vs2008 SP1 or vs2010)
On the page, place the verification code image page.Code
< Form ID = "Form1" Runat = "Server" >
< Div >
< Input Type = "Text" Name = "Txtcode" ID = "Txtcode" Maxlength = "8" />
< IMG Onclick = "This. src = 'getcode. aspx ';" SRC = "Getcode. aspx" Align = "Absmiddle" Style = "Cursor: Pointer" ALT = "I can't see clearly. Change one" Title = "I can't see clearly. Change one" />
< IMG ID = "Imgread" SRC = "Image/maintb.gif" Align = "Absmiddle" Style = "Cursor: Pointer" ALT = "Listen to verification code" Title = "Listen to verification code" Onclick = "Playvoice ('player ');" />
< Span ID = "Player" > </ Span >
</ Div >
</ Form >
The JS function called when you listen to the Verification Code is as follows:
Function playvoice (ID ){
VaR voiceid = Document. getelementbyid (ID );
VaR voicecode = $. Cookie ('validatecode ');
Voiceid. innerhtml =" < Embed ID = 'Sound _ play' Name = 'Sound _ play' SRC Response 'sound_play.swf? " + (New date (). gettime () + "'
Flashvars = 'Isplay = 1 & url = codevoice. aspx & code =" + Voicecode + "'width = '0' Height = '0' AllowScriptAccess = 'Alway'
Type = 'Application/X-Shockwave-flash' Pluginspage = 'HTTP: // www.macromedia.com/go/getflashplayer' /> </ Embed > ";
}
$. Cookie ('validatecode') is used to read the cookie verification code. A jquery operation cookie plug-in is used here.
The code for generating an MP3 page is as follows:
// Read and verify the code to generate the MP3 package.
Response. contenttype = " Audio/MPEG " ;
Response. writefile ( " Sound/begin.pdf " );
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/Endpoint " );
[The authors of this article are at cnblogs, csdn, http://www.ajaxcn.net/, download, please reserve this description]
The Flash playback code is mainly used to right-click the key frame of the first frame, and insert the following code based on the input playback digital MP3 address.
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 ;
}
}
For more information, see jumbotcms.