123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889 |
- /////////////////////////////////////////////////////////////////////////
- var uMaxID=64;
- var uPlayFileID=new Array(64);
- var uRecordID=new Array(64);
- var uCCSessID=-1;
- var vConfID=0;
- var g_interval = 0;//定时器全局变量
- var g_msg = false;
- var isFirefox=navigator.userAgent.toUpperCase().indexOf("FIREFOX")?true:false;
- var isIE=navigator.userAgent.toUpperCase().indexOf("MSIE")?true:false;
- var isChrome=navigator.userAgent.toUpperCase().indexOf("CHROME")?true:false;
- ////////////////////////////////////////////////////////////////////////
- //
- //js脚本调用在IE10以上需要IE10兼容模式如例子html否则js脚本会失效,
- //当然开发者可以重新构造IE10调用activex的js脚本。
- //
- function T_WaitForWin(vWin)
- {
- var vTimeout=5000;
- var vBegintime=new Date();
- var vEndtime=new Date();
- while(vWin.vInit != 1 && vEndtime.getTime() - vBegintime.getTime() < (vTimeout*2))//ns超时
- {
- if(vEndtime.getTime() - vBegintime.getTime() > vTimeout)//1s还没有完成,使用等待方式
- {
- Sleep(100);//等待100ms
- }
- vEndtime=new Date();
- }
- }
- function I_CheckActiveX()
- {
- var iVer = 1;//第一个版本
- check_ver(iVer,function(nRet){
- var szHint="";
- switch(nRet)
- {
- case W_OK://检查成功
- szHint = "安装成功";
- break;
- case W_TRY://试用
- szHint ="试用版本已安装成功";
- break;
- case W_NO_FOUND://没有找到校验服务器
- szHint ="没有找到校验服务器";
- break;
- case W_EXCEED_NUM:
- szHint ="校验服务器超过用户数了";
- break;
- default:
- szHint ="没有安装本地驱动,请下载";
- break;
- }
- AppendStatus(szHint);
- // alert(szHint);
- });
- }
- function TV_Initialize()
- {
- //检测是否安装中间件
- //var qnv = document.getElementById('qnviccub');
- // qnv.attachEvent("OnQnvEvent", T_GetEvent);
- DevInfo(0,QNV_DEVINFO_GETCHANNELS,function (nResult){
- if(nResult <= 0)
- {
- OpenDevice(0,function (nResult){
- DevInfo(0,QNV_DEVINFO_GETCHANNELS,function (channels){
- if(channels > 0)
- { //初始化变量
- for(i=0;i<uMaxID;i=i+1)
- {
- uPlayFileID[i]=-1;
- uRecordID[i]=-1;
- }
- for(j =0; j<channels; j++)
- {
- //SetParam(j,QNV_PARAM_DTMFVOL,5);
- SetParam(j,QNV_PARAM_AM_LINEIN,5,null);//把输入能量增益调为5
- }
- DevInfo(0,QNV_DEVINFO_GETSERIAL,function(sn){
- DevInfo(0,QNV_DEVINFO_GETTYPE,function(type){
- DevInfo(0,QNV_DEVINFO_FILEVERSION,function(ver){
- AppendStatus("打开设备成功 通道数:"+channels+" 序列号:"+sn+" 设备类型:"+type+" ver:"+ver);
- });
- });
- });
-
- }else
- {
- AppendStatus("打开设备失败,请检查设备是否已经插入并安装了驱动,并且没有其它程序已经打开设备");
- // alert('打开设备失败,请检查设备是否已经插入并安装了驱动,并且没有其它程序已经打开设备');
- }
- });
- });//OpenDevice
- }//if(nResult <= 0)
- else
- {
- AppendStatus("设备已经被打开,不需要重复打开");
- // alert('设备已经被打开,不需要重复打开');
- }
- });
- return;
- }
- //配置设备参数函数
- //nChannel通道号
- //paramName//参数名
- //nValue参数值
- function TV_SetParam(nChannel,paramName,nValue,nextFunc)
- {
- if(nChannel >= 0)
- {
- SetParam(nChannel, paramName,nValue,nextFunc);//设置参数
- }
- }
- //控制设备参数函数
- //nChannel通道号
- //paramName//参数名
- //nValue参数值
- function TV_SetDevCtrl(nChannel,paramName,nValue,nextFunc)
- {
- return SetDevCtrl(nChannel,paramName,nValue,nextFunc);
- }
- function TV_StopConference(nextFunc)
- {
- if(vConfID > 0)
- {
- Conference(-1,vConfID,QNV_CONFERENCE_DELETECONF,0,0,function(nResult)
- {
- nextFunc(nResult);
- vConfID = 0;
- AppendStatus("会议停止");
- });//删除会议
- }
- }
- function TV_StartConference()
- {
- OpenDevice(ODT_SOUND,0,0,function (nResult){
- if(nResult <=0)
- {
- AppendStatus("打开声卡模块失败");
- }
- else
- {
- TV_StopConference(function (nResult){
- Conference(-1,0,QNV_CONFERENCE_CREATE,0,"",function (vConfID){
- if(vConfID <= 0)
- AppendStatus("创建会议失败");
- else
- {
- Conference(SOUND_CHANNELID,vConfID,QNV_CONFERENCE_ADDTOCONF,0,"",function(vRet){
- AppendStatus("加入会议完成,Ret="+vRet);
- DevInfo(0,QNV_DEVINFO_GETCHANNELS,function(chammels){
- for(i=0;i<chammels;i=i+1)
- {
- Conference(i,vConfID,QNV_CONFERENCE_ADDTOCONF,0,"",function (nRet){
- AppendStatus("加入会议完成,Ret="+nRet);
- });
-
- }
- AppendStatus("会议创建完成,会议ID="+vConfID);
- });
-
- });//Conference(SOUND_CHANNELID
-
- }
- });//Conference-1
- });//TV_StopConference
- }
- });
- }
- function TV_InitCCModule()
- {
- OpenDevice(ODT_CC,0,QNV_CC_LICENSE,function(nResult){
- if( nResult> 0)
- {
- AppendStatus("加载CC网络模块成功");
- }
- else
- AppendStatus("加载CC网络模块失败");
- });
- }
- function TV_Disable()
- {
- g_msg = true;
- CloseDevice(ODT_ALL,function (nResult){
- AppendStatus("关闭设备完成.");
- });//关闭所有设备
- }
- //---------------------------------------
- function TV_EnableHook(uID,bEnable)
- {
- TV_SetDevCtrl(uID,QNV_CTRL_DOHOOK,bEnable,function(nResult){
- AppendStatusEx(uID,bEnable?"软摘机":"软挂机");
- });
- }
- function TV_OffHookCtrl(uID)
- {
- TV_EnableHook(uID,TRUE);
- }
- function TV_HangUpCtrl(uID)
- {
- TV_EnableHook(uID,FALSE);
- }
- //----------------------------------------
- function TV_EnableMic2Line(uID,bEnable)
- {
- //SetDevCtrl(uID,QNV_CTRL_DOMICTOLINE,bEnable);
- TV_SetDevCtrl(uID,QNV_CTRL_DOMICTOLINE,bEnable);
- }
- function TV_EnableMic(uID,bEnable)
- {
- TV_EnableMic2Line(uID,bEnable);
- }
- //----------------------------------------
- function TV_EnableDoPhone(uID,bEnable)
- {
- SetDevCtrl(uID,QNV_CTRL_DOPHONE,bEnable);
- }
- function TV_EnableRing(uID,bEnable)
- {
- TV_EnableDoPhone(uID,bEnable);
- }
- function TV_StartRing(uID,bEnable)
- {
- if(bEnable)
- General(uID,QNV_GENERAL_STARTRING,0,"1234",null);
- else
- General(uID,QNV_GENERAL_STOPRING,0,"",null);
- }
- //--------------------------------------
- function TV_EnableDoPlay(uID,bEnable)
- {
- SetDevCtrl(uID,QNV_CTRL_DOPLAY,bEnable,null);
- }
- function TV_OpenDoPlay(uID)
- {
- TV_EnableDoPlay(uID,TRUE);
- }
- function TV_CloseDoPlay(uID)
- {
- TV_EnableDoPlay(uID,FALSE);
- }
- //----------------------------------------------
- //线路声音到耳机,用耳机通话时
- function TV_EnableLine2Spk(uID,bEnable)
- {
- SetDevCtrl(uID,QNV_CTRL_DOLINETOSPK,bEnable,null);
- }
- //播放的语音到耳机
- function TV_EnableMicSpk(uID,bEnable)
- {
- SetDevCtrl(uID,QNV_CTRL_DOPLAYTOSPK,bEnable);
- }
- //----------------------------------------------
- function TV_EnablePlay2Spk(uID,bEnable)
- {
- SetDevCtrl(uID,QNV_CTRL_DOPLAYTOSPK,bEnable);
- }
- function TV_EnableRingPower(uID,bEnable)
- {
- GetDevCtrl(uID,QNV_CTRL_DOPHONE,function(nRet){
- if(nRet && bEnable)
- {
- AppendStatusEx(uID,"请先断开电话机");
- // alert("请先断开电话机");
- }
- else{
- SetDevCtrl(uID,QNV_CTRL_RINGPOWER,bEnable,null);
- }
- });
- }
- function TV_RefuseCallIn(uID)
- {
- GetDevCtrl(uID,QNV_CTRL_RINGTIMES,function (nRet){
- if(nRet<=0)
- {
- AppendStatusEx(uID,"没有来电,无效的拒接");
- // alert("没有来电,无效的拒接");
- }
- else
- {
- General(uID,QNV_GENERAL_STARTREFUSE,0,0,null);
- }
- });
- }
- function TV_StartFlash(uID)
- {
- GetDevCtrl(uID,QNV_CTRL_DOHOOK,function(nCon){
- GetDevCtrl(uID,QNV_CTRL_PHONE,function(nRet){
- if(nCon<=0 && nRet<=0 )
- {
- // alert("没有摘机状态,无效的拍插簧");
- AppendStatusEx(uID,"没有摘机状态,无效的拍插簧");
- }
- else
- {
- General(uID,QNV_GENERAL_STARTFLASH,FT_ALL,"",function(nRetCall){
- if(nRetCall<=0)
- {
- AppendStatusEx(uID,"拍插簧失败");
- // alert("拍插簧失败");
- }
- });
- }
- });
- });
- }
- function TV_EnablePhoneRing(uID,bEnable)
- {
- if(bEnable)
- {
- GetDevCtrl(uID,QNV_CTRL_DOPHONE,function(nRet ){
- if(nRet)
- {
- AppendStatusEx(uID,"请先断开电话机");
- // alert("请先断开电话机");
- }
- else
- {
- var szCallID="1234567890";
- SetParam(uID,QNV_PARAM_RINGCALLIDTYPE,DIALTYPE_FSK,function(n){
- General(uID,QNV_GENERAL_STARTRING,0,szCallID,function(k){
- AppendStatusEx(uID,"开始内线模拟间隔震铃 -> 模拟来电号码:"+szCallID);
- });
- });//设置送码方式为一声后FSK模式,默认为一声前dtmf模式//DIALTYPE_DTMF
- }
- });
- }else
- {
-
- General(uID,QNV_GENERAL_STOPRING,0,0,function(h){
- AppendStatusEx(uID,"停止内线震铃");
- });
- }
- }
- function TV_StartPlayFile(uID,szFile)
- {
- // vFilePath ="c:\\test.wav";
- vFilePath = "d:\\wyluyin\\20220608191204_13027625915.wav";
- // alert("播放文件路径为:"+vFilePath);
- if(vFilePath.length > 0)
- {
- // AppendStatus("选择文件:"+vFilePath);
- // TV_StopPlayFile(uID);//先停止上次播放的句柄
- var vmask=PLAYFILE_MASK_REPEAT;//循环播放
- PlayFile(uID,QNV_PLAY_FILE_START,0,vmask,vFilePath,function(id){
- console.log(id);
- // uPlayFileID[uID]=id;
- // if(id<=0)
- // {
- // AppendStatusEx(uID,"播放失败:"+vFilePath);
- // }
- // else
- // {
- // AppendStatusEx(uID,"开始播放文件:"+vFilePath);
- // }
- });
- }
- else
- {
- AppendStatus("没有选择文件")
- }
-
- }
- function TV_StopPlayFile(uID)
- {
- if(uPlayFileID[uID] > 0)
- {
- PlayFile(uID,QNV_PLAY_FILE_STOP,uPlayFileID[uID],0,0,function (nRet){
- AppendStatusEx(uID,"停止播放");
- uPlayFileID[uID] =0;
- });
- }else
- {
- AppendStatusEx(uID,"未播放的句柄");
- uPlayFileID[uID] =0;
- }
- }
- function TV_StopPlayFileEx(uID,nextFunc)
- {
- if(uPlayFileID[uID] > 0)
- {
- PlayFile(uID,QNV_PLAY_FILE_STOP,uPlayFileID[uID],0,0,function (nRet){
- uPlayFileID[uID] =0;
- nextFunc();
- AppendStatusEx(uID,"停止播放");
- });
- }else
- {
- uPlayFileID[uID] =0;
- nextFunc();
- AppendStatusEx(uID,"未播放的句柄");
- }
- }
- function TV_StartRecordFile(uID,fp)
- { vFilePath = fp;
- // vFilePath ="c:\\test.wav"; //有些操作系统c盘保护,保存到c盘可能会失败,可以换到其它盘符
- console.log("录音文件路径为:"+vFilePath);
- if(vFilePath.length > 0)
- {
- TV_StopPlayFileEx(uID,function(){
- var vFormatID=BRI_WAV_FORMAT_PCM8K16B;//选择使用8K16bit采样
- var vmask=RECORD_MASK_ECHO|RECORD_MASK_AGC;//使用回音抵消后并且自动增益的
- RecordFile(uID,QNV_RECORD_FILE_START,vFormatID,vmask,vFilePath,function (hRec){
- uRecordID[uID] = hRec;
- if(uRecordID[uID] <= 0)
- {
- AppendStatusEx(uID,"录音失败:"+vFilePath);
- }else
- {
- AppendStatusEx(uID,"开始录音文件: id="+uRecordID[uID]+" "+vFilePath);
- }
- });
- });
- }
- else
- {
- AppendStatus("没有选择文件");
- }
- }
- function TV_StopRecordFile(uID)
- {
- if(uRecordID[uID] > 0)
- {
- //var vRecPath=GetRecFilePath(uID,uRecordID[uID]);
- RecordFile(uID,QNV_RECORD_FILE_PATH,uRecordID[uID],0,0,function(vRecPath){
- RecordFile(uID,QNV_RECORD_FILE_ELAPSE,uRecordID[uID],0,0,function(vElapse){
- RecordFile(uID,QNV_RECORD_FILE_STOP,uRecordID[uID],0,0,function(nRet){
- AppendStatusEx(uID,"停止录音:"+vRecPath+" 录音时间:"+vElapse);
- uRecordID[uID]=0;
- });
- });
- });
- }
- }
- function TV_DeleteRecordFile(uID)
- {
- CallLog(uID,QNV_CALLLOG_DELRECFILE,"",0,function(vRet){
- if(vRet <= 0)
- {
- alert('删除失败:'+vRet);
- }else
- alert('删除完成');
- });
- }
- function TV_StartDial(uID,szCode)
- {//正常拨号必须使用 DIALTYPE_DTMF
- General(uID,QNV_GENERAL_STARTDIAL,DIALTYPE_DTMF,szCode,function (nRet){
- if(nRet <= 0)
- {
- AppendStatusEx(uID,"拨号失败:"+szCode);
- }
- else{
- AppendStatusEx(uID,"开始拨号:"+szCode);
- }
- });
- }
- function TV_GetDiskList()
- {
- Tool(QNV_TOOL_DISKLIST,0,0,0,function(vDiskList){ ;
- AppendStatus("按逗号分隔的盘符列表:"+vDiskList);
- });
-
- }
- function TV_GetFreeSpace(szDiskname)
- {
- Tool(QNV_TOOL_DISKFREESPACE,0,szDiskname,0,function (vFreeSpace){
- AppendStatus(szDiskname+" 空闲大小为:"+vFreeSpace+"(M)");
- });
- }
- function TV_GetTotalSpace(szDiskname)
- {
- Tool(QNV_TOOL_DISKTOTALSPACE,0,szDiskname,0,function (vTotalSpace){
- AppendStatus(szDiskname+" 总共大小为:"+vTotalSpace+"(M)");
- });
- }
- function TV_BrowerPath()
- {
- Tool(QNV_TOOL_SELECTDIRECTORY,0,"选择目录",0,function(vPath){
- AppendStatus("选择目录:"+vPath);
- });
- }
- function TV_SelectFile()
- {
- Tool(QNV_TOOL_SELECTFILE,0,"wav files|*.wav|all files|*.*||",0,function(vFilePath){
- AppendStatus("选择文件:"+vFilePath);
- });
- }
- function TV_uploadFile(uploadUrl)
- {
- //上传文件
- vFilePath ="c:\\test.wav";
- console.log("上传文件路径为:"+vFilePath);
- Remote(QNV_REMOTE_UPLOAD_START,0,uploadUrl,vFilePath,0,0, function(nRet){
- //nRet <=0表示失败
- if(nRet<=0)
- AppendStatus("上传文件:"+vFilePath+"失败");
- else
- AppendStatus("上传文件:"+vFilePath+"成功");
- });
- }
- /*阿里云的URL
- 可以参照阿里云上传例子把其中的参数签名加密生成如下URL
- http://post-test.oss-cn-hangzhou.aliyuncs.com/?name=message.wav&key=${filename}&policy=eyJleHBpcmF0aW9uIjoiMjAyMC0wMS0wMVQxMjowMDowMC4wMDBaIiwiY29uZGl0aW9ucyI6W1siY29udGVudC1sZ
- */
- function ali_uploadFile(uploadUrl)
- {
- vFilePath ="c:\\test.wav";
- alert("上传文件路径为:"+vFilePath);
- //上传文件
- UploadFile(uploadUrl,vFilePath,function(nRet){
- //nRet <=0表示失败
- if( nRet<=0 )
- AppendStatus("上传文件:"+vFilePath+"失败");
- else
- AppendStatus("上传文件:"+vFilePath+"成功");
- });
- }
- /*
- //登陆CC
- function TV_LoginCC(cc,pwd)
- {
- if(CCCtrl(QNV_CCCTRL_ISLOGON,NULL,0) > 0)
- alert('已经登陆,请先离线');
- else
- {
- var v=cc+','+pwd;
- var vret=CCCtrl(QNV_CCCTRL_LOGIN,v,0);
- if(vret <= 0)//开始登陆
- alert('登陆CC失败:'+vret);
- else
- AppendStatus("开始登陆CC:"+cc);
- }
- }
- //CC离线
- function TV_LogoutCC()
- {
- CCCtrl(QNV_CCCTRL_LOGOUT,NULL,0);//离线
- AppendStatus("已离线");
- }
- function T_GetMsgValue(vmsg,vkey)
- {
- var strs = vmsg.split("\r\n");
- for(var i = 0; i < strs.length; i++)
- {
- var vline=strs[i];
- var vindex=vline.indexOf(vkey);
- if(vindex != -1)
- {
- return vline.slice(vkey.length+1);
- }
- }
- return "";
- }
- */
- //编码问题
- var base64EncodeChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
- var base64DecodeChars = new Array(
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63,
- 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1,
- -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
- 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1,
- -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
- 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1);
- function base64encode(str) {
- var out, i, len;
- var c1, c2, c3;
- len = str.length;
- i = 0;
- out = "";
- while(i < len) {
- c1 = str.charCodeAt(i++) & 0xff;
- if(i == len)
- {
- out += base64EncodeChars.charAt(c1 >> 2);
- out += base64EncodeChars.charAt((c1 & 0x3) << 4);
- out += "==";
- break;
- }
- c2 = str.charCodeAt(i++);
- if(i == len)
- {
- out += base64EncodeChars.charAt(c1 >> 2);
- out += base64EncodeChars.charAt(((c1 & 0x3)<< 4) | ((c2 & 0xF0) >> 4));
- out += base64EncodeChars.charAt((c2 & 0xF) << 2);
- out += "=";
- break;
- }
- c3 = str.charCodeAt(i++);
- out += base64EncodeChars.charAt(c1 >> 2);
- out += base64EncodeChars.charAt(((c1 & 0x3)<< 4) | ((c2 & 0xF0) >> 4));
- out += base64EncodeChars.charAt(((c2 & 0xF) << 2) | ((c3 & 0xC0) >>6));
- out += base64EncodeChars.charAt(c3 & 0x3F);
- }
- return out;
- }
- function base64decode(str) {
- var c1, c2, c3, c4;
- var i, len, out;
- len = str.length;
- i = 0;
- out = "";
- while(i < len) {
- /* c1 */
- do {
- c1 = base64DecodeChars[str.charCodeAt(i++) & 0xff];
- } while(i < len && c1 == -1);
- if(c1 == -1)
- break;
- /* c2 */
- do {
- c2 = base64DecodeChars[str.charCodeAt(i++) & 0xff];
- } while(i < len && c2 == -1);
- if(c2 == -1)
- break;
- out += String.fromCharCode((c1 << 2) | ((c2 & 0x30) >> 4));
- /* c3 */
- do {
- c3 = str.charCodeAt(i++) & 0xff;
- if(c3 == 61)
- return out;
- c3 = base64DecodeChars[c3];
- } while(i < len && c3 == -1);
- if(c3 == -1)
- break;
- out += String.fromCharCode(((c2 & 0XF) << 4) | ((c3 & 0x3C) >> 2));
- /* c4 */
- do {
- c4 = str.charCodeAt(i++) & 0xff;
- if(c4 == 61)
- return out;
- c4 = base64DecodeChars[c4];
- } while(i < len && c4 == -1);
- if(c4 == -1)
- break;
- out += String.fromCharCode(((c3 & 0x03) << 6) | c4);
- }
- return out;
- }
- function utf16to8(str) {
- var out, i, len, c;
- out = "";
- len = str.length;
- for(i = 0; i < len; i++) {
- c = str.charCodeAt(i);
- if ((c >= 0x0001) && (c <= 0x007F)) {
- out += str.charAt(i);
- } else if (c > 0x07FF) {
- out += String.fromCharCode(0xE0 | ((c >> 12) & 0x0F));
- out += String.fromCharCode(0x80 | ((c >> 6) & 0x3F));
- out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));
- } else {
- out += String.fromCharCode(0xC0 | ((c >> 6) & 0x1F));
- out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));
- }
- }
- return out;
- }
- function utf8to16(str) {
- var out, i, len, c;
- var char2, char3;
- out = "";
- len = str.length;
- i = 0;
- while(i < len) {
- c = str.charCodeAt(i++);
- switch(c >> 4)
- {
- case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7:
- // 0xxxxxxx
- out += str.charAt(i-1);
- break;
- case 12: case 13:
- // 110x xxxx 10xx xxxx
- char2 = str.charCodeAt(i++);
- out += String.fromCharCode(((c & 0x1F) << 6) | (char2 & 0x3F));
- break;
- case 14:
- // 1110 xxxx 10xx xxxx 10xx xxxx
- char2 = str.charCodeAt(i++);
- char3 = str.charCodeAt(i++);
- out += String.fromCharCode(((c & 0x0F) << 12) |
- ((char2 & 0x3F) << 6) |
- ((char3 & 0x3F) << 0));
- break;
- }
- }
- return out;
- }
- function getCurrentDate(format) {
- var now = new Date();
- var year = now.getFullYear(); //得到年份
- var month = now.getMonth();//得到月份
- var date = now.getDate();//得到日期
- var day = now.getDay();//得到周几
- var hour = now.getHours();//得到小时
- var minu = now.getMinutes();//得到分钟
- var sec = now.getSeconds();//得到秒
- month = month + 1;
- if (month < 10) month = "0" + month;
- if (date < 10) date = "0" + date;
- if (hour < 10) hour = "0" + hour;
- if (minu < 10) minu = "0" + minu;
- if (sec < 10) sec = "0" + sec;
- var time = "";
- //精确到天
- if(format==1){
- time = year + "-" + month + "-" + date;
- }
- //精确到分
- else if(format==2){
- time = year + "-" + month + "-" + date+ " " + hour + ":" + minu + ":" + sec;
- }else if(format==3){
- time = year + "" + month + "" + date+ "" + hour + "" + minu + "" + sec;
- }
- return time;
- }
|