0
0

qnvfunc.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889
  1. /////////////////////////////////////////////////////////////////////////
  2. var uMaxID=64;
  3. var uPlayFileID=new Array(64);
  4. var uRecordID=new Array(64);
  5. var uCCSessID=-1;
  6. var vConfID=0;
  7. var g_interval = 0;//定时器全局变量
  8. var g_msg = false;
  9. var isFirefox=navigator.userAgent.toUpperCase().indexOf("FIREFOX")?true:false;
  10. var isIE=navigator.userAgent.toUpperCase().indexOf("MSIE")?true:false;
  11. var isChrome=navigator.userAgent.toUpperCase().indexOf("CHROME")?true:false;
  12. ////////////////////////////////////////////////////////////////////////
  13. //
  14. //js脚本调用在IE10以上需要IE10兼容模式如例子html否则js脚本会失效,
  15. //当然开发者可以重新构造IE10调用activex的js脚本。
  16. //
  17. function T_WaitForWin(vWin)
  18. {
  19. var vTimeout=5000;
  20. var vBegintime=new Date();
  21. var vEndtime=new Date();
  22. while(vWin.vInit != 1 && vEndtime.getTime() - vBegintime.getTime() < (vTimeout*2))//ns超时
  23. {
  24. if(vEndtime.getTime() - vBegintime.getTime() > vTimeout)//1s还没有完成,使用等待方式
  25. {
  26. Sleep(100);//等待100ms
  27. }
  28. vEndtime=new Date();
  29. }
  30. }
  31. function I_CheckActiveX()
  32. {
  33. var iVer = 1;//第一个版本
  34. check_ver(iVer,function(nRet){
  35. var szHint="";
  36. switch(nRet)
  37. {
  38. case W_OK://检查成功
  39. szHint = "安装成功";
  40. break;
  41. case W_TRY://试用
  42. szHint ="试用版本已安装成功";
  43. break;
  44. case W_NO_FOUND://没有找到校验服务器
  45. szHint ="没有找到校验服务器";
  46. break;
  47. case W_EXCEED_NUM:
  48. szHint ="校验服务器超过用户数了";
  49. break;
  50. default:
  51. szHint ="没有安装本地驱动,请下载";
  52. break;
  53. }
  54. AppendStatus(szHint);
  55. // alert(szHint);
  56. });
  57. }
  58. function TV_Initialize()
  59. {
  60. //检测是否安装中间件
  61. //var qnv = document.getElementById('qnviccub');
  62. // qnv.attachEvent("OnQnvEvent", T_GetEvent);
  63. DevInfo(0,QNV_DEVINFO_GETCHANNELS,function (nResult){
  64. if(nResult <= 0)
  65. {
  66. OpenDevice(0,function (nResult){
  67. DevInfo(0,QNV_DEVINFO_GETCHANNELS,function (channels){
  68. if(channels > 0)
  69. { //初始化变量
  70. for(i=0;i<uMaxID;i=i+1)
  71. {
  72. uPlayFileID[i]=-1;
  73. uRecordID[i]=-1;
  74. }
  75. for(j =0; j<channels; j++)
  76. {
  77. //SetParam(j,QNV_PARAM_DTMFVOL,5);
  78. SetParam(j,QNV_PARAM_AM_LINEIN,5,null);//把输入能量增益调为5
  79. }
  80. DevInfo(0,QNV_DEVINFO_GETSERIAL,function(sn){
  81. DevInfo(0,QNV_DEVINFO_GETTYPE,function(type){
  82. DevInfo(0,QNV_DEVINFO_FILEVERSION,function(ver){
  83. AppendStatus("打开设备成功 通道数:"+channels+" 序列号:"+sn+" 设备类型:"+type+" ver:"+ver);
  84. });
  85. });
  86. });
  87. }else
  88. {
  89. AppendStatus("打开设备失败,请检查设备是否已经插入并安装了驱动,并且没有其它程序已经打开设备");
  90. // alert('打开设备失败,请检查设备是否已经插入并安装了驱动,并且没有其它程序已经打开设备');
  91. }
  92. });
  93. });//OpenDevice
  94. }//if(nResult <= 0)
  95. else
  96. {
  97. AppendStatus("设备已经被打开,不需要重复打开");
  98. // alert('设备已经被打开,不需要重复打开');
  99. }
  100. });
  101. return;
  102. }
  103. //配置设备参数函数
  104. //nChannel通道号
  105. //paramName//参数名
  106. //nValue参数值
  107. function TV_SetParam(nChannel,paramName,nValue,nextFunc)
  108. {
  109. if(nChannel >= 0)
  110. {
  111. SetParam(nChannel, paramName,nValue,nextFunc);//设置参数
  112. }
  113. }
  114. //控制设备参数函数
  115. //nChannel通道号
  116. //paramName//参数名
  117. //nValue参数值
  118. function TV_SetDevCtrl(nChannel,paramName,nValue,nextFunc)
  119. {
  120. return SetDevCtrl(nChannel,paramName,nValue,nextFunc);
  121. }
  122. function TV_StopConference(nextFunc)
  123. {
  124. if(vConfID > 0)
  125. {
  126. Conference(-1,vConfID,QNV_CONFERENCE_DELETECONF,0,0,function(nResult)
  127. {
  128. nextFunc(nResult);
  129. vConfID = 0;
  130. AppendStatus("会议停止");
  131. });//删除会议
  132. }
  133. }
  134. function TV_StartConference()
  135. {
  136. OpenDevice(ODT_SOUND,0,0,function (nResult){
  137. if(nResult <=0)
  138. {
  139. AppendStatus("打开声卡模块失败");
  140. }
  141. else
  142. {
  143. TV_StopConference(function (nResult){
  144. Conference(-1,0,QNV_CONFERENCE_CREATE,0,"",function (vConfID){
  145. if(vConfID <= 0)
  146. AppendStatus("创建会议失败");
  147. else
  148. {
  149. Conference(SOUND_CHANNELID,vConfID,QNV_CONFERENCE_ADDTOCONF,0,"",function(vRet){
  150. AppendStatus("加入会议完成,Ret="+vRet);
  151. DevInfo(0,QNV_DEVINFO_GETCHANNELS,function(chammels){
  152. for(i=0;i<chammels;i=i+1)
  153. {
  154. Conference(i,vConfID,QNV_CONFERENCE_ADDTOCONF,0,"",function (nRet){
  155. AppendStatus("加入会议完成,Ret="+nRet);
  156. });
  157. }
  158. AppendStatus("会议创建完成,会议ID="+vConfID);
  159. });
  160. });//Conference(SOUND_CHANNELID
  161. }
  162. });//Conference-1
  163. });//TV_StopConference
  164. }
  165. });
  166. }
  167. function TV_InitCCModule()
  168. {
  169. OpenDevice(ODT_CC,0,QNV_CC_LICENSE,function(nResult){
  170. if( nResult> 0)
  171. {
  172. AppendStatus("加载CC网络模块成功");
  173. }
  174. else
  175. AppendStatus("加载CC网络模块失败");
  176. });
  177. }
  178. function TV_Disable()
  179. {
  180. g_msg = true;
  181. CloseDevice(ODT_ALL,function (nResult){
  182. AppendStatus("关闭设备完成.");
  183. });//关闭所有设备
  184. }
  185. //---------------------------------------
  186. function TV_EnableHook(uID,bEnable)
  187. {
  188. TV_SetDevCtrl(uID,QNV_CTRL_DOHOOK,bEnable,function(nResult){
  189. AppendStatusEx(uID,bEnable?"软摘机":"软挂机");
  190. });
  191. }
  192. function TV_OffHookCtrl(uID)
  193. {
  194. TV_EnableHook(uID,TRUE);
  195. }
  196. function TV_HangUpCtrl(uID)
  197. {
  198. TV_EnableHook(uID,FALSE);
  199. }
  200. //----------------------------------------
  201. function TV_EnableMic2Line(uID,bEnable)
  202. {
  203. //SetDevCtrl(uID,QNV_CTRL_DOMICTOLINE,bEnable);
  204. TV_SetDevCtrl(uID,QNV_CTRL_DOMICTOLINE,bEnable);
  205. }
  206. function TV_EnableMic(uID,bEnable)
  207. {
  208. TV_EnableMic2Line(uID,bEnable);
  209. }
  210. //----------------------------------------
  211. function TV_EnableDoPhone(uID,bEnable)
  212. {
  213. SetDevCtrl(uID,QNV_CTRL_DOPHONE,bEnable);
  214. }
  215. function TV_EnableRing(uID,bEnable)
  216. {
  217. TV_EnableDoPhone(uID,bEnable);
  218. }
  219. function TV_StartRing(uID,bEnable)
  220. {
  221. if(bEnable)
  222. General(uID,QNV_GENERAL_STARTRING,0,"1234",null);
  223. else
  224. General(uID,QNV_GENERAL_STOPRING,0,"",null);
  225. }
  226. //--------------------------------------
  227. function TV_EnableDoPlay(uID,bEnable)
  228. {
  229. SetDevCtrl(uID,QNV_CTRL_DOPLAY,bEnable,null);
  230. }
  231. function TV_OpenDoPlay(uID)
  232. {
  233. TV_EnableDoPlay(uID,TRUE);
  234. }
  235. function TV_CloseDoPlay(uID)
  236. {
  237. TV_EnableDoPlay(uID,FALSE);
  238. }
  239. //----------------------------------------------
  240. //线路声音到耳机,用耳机通话时
  241. function TV_EnableLine2Spk(uID,bEnable)
  242. {
  243. SetDevCtrl(uID,QNV_CTRL_DOLINETOSPK,bEnable,null);
  244. }
  245. //播放的语音到耳机
  246. function TV_EnableMicSpk(uID,bEnable)
  247. {
  248. SetDevCtrl(uID,QNV_CTRL_DOPLAYTOSPK,bEnable);
  249. }
  250. //----------------------------------------------
  251. function TV_EnablePlay2Spk(uID,bEnable)
  252. {
  253. SetDevCtrl(uID,QNV_CTRL_DOPLAYTOSPK,bEnable);
  254. }
  255. function TV_EnableRingPower(uID,bEnable)
  256. {
  257. GetDevCtrl(uID,QNV_CTRL_DOPHONE,function(nRet){
  258. if(nRet && bEnable)
  259. {
  260. AppendStatusEx(uID,"请先断开电话机");
  261. // alert("请先断开电话机");
  262. }
  263. else{
  264. SetDevCtrl(uID,QNV_CTRL_RINGPOWER,bEnable,null);
  265. }
  266. });
  267. }
  268. function TV_RefuseCallIn(uID)
  269. {
  270. GetDevCtrl(uID,QNV_CTRL_RINGTIMES,function (nRet){
  271. if(nRet<=0)
  272. {
  273. AppendStatusEx(uID,"没有来电,无效的拒接");
  274. // alert("没有来电,无效的拒接");
  275. }
  276. else
  277. {
  278. General(uID,QNV_GENERAL_STARTREFUSE,0,0,null);
  279. }
  280. });
  281. }
  282. function TV_StartFlash(uID)
  283. {
  284. GetDevCtrl(uID,QNV_CTRL_DOHOOK,function(nCon){
  285. GetDevCtrl(uID,QNV_CTRL_PHONE,function(nRet){
  286. if(nCon<=0 && nRet<=0 )
  287. {
  288. // alert("没有摘机状态,无效的拍插簧");
  289. AppendStatusEx(uID,"没有摘机状态,无效的拍插簧");
  290. }
  291. else
  292. {
  293. General(uID,QNV_GENERAL_STARTFLASH,FT_ALL,"",function(nRetCall){
  294. if(nRetCall<=0)
  295. {
  296. AppendStatusEx(uID,"拍插簧失败");
  297. // alert("拍插簧失败");
  298. }
  299. });
  300. }
  301. });
  302. });
  303. }
  304. function TV_EnablePhoneRing(uID,bEnable)
  305. {
  306. if(bEnable)
  307. {
  308. GetDevCtrl(uID,QNV_CTRL_DOPHONE,function(nRet ){
  309. if(nRet)
  310. {
  311. AppendStatusEx(uID,"请先断开电话机");
  312. // alert("请先断开电话机");
  313. }
  314. else
  315. {
  316. var szCallID="1234567890";
  317. SetParam(uID,QNV_PARAM_RINGCALLIDTYPE,DIALTYPE_FSK,function(n){
  318. General(uID,QNV_GENERAL_STARTRING,0,szCallID,function(k){
  319. AppendStatusEx(uID,"开始内线模拟间隔震铃 -> 模拟来电号码:"+szCallID);
  320. });
  321. });//设置送码方式为一声后FSK模式,默认为一声前dtmf模式//DIALTYPE_DTMF
  322. }
  323. });
  324. }else
  325. {
  326. General(uID,QNV_GENERAL_STOPRING,0,0,function(h){
  327. AppendStatusEx(uID,"停止内线震铃");
  328. });
  329. }
  330. }
  331. function TV_StartPlayFile(uID,szFile)
  332. {
  333. // vFilePath ="c:\\test.wav";
  334. vFilePath = "d:\\wyluyin\\20220608191204_13027625915.wav";
  335. // alert("播放文件路径为:"+vFilePath);
  336. if(vFilePath.length > 0)
  337. {
  338. // AppendStatus("选择文件:"+vFilePath);
  339. // TV_StopPlayFile(uID);//先停止上次播放的句柄
  340. var vmask=PLAYFILE_MASK_REPEAT;//循环播放
  341. PlayFile(uID,QNV_PLAY_FILE_START,0,vmask,vFilePath,function(id){
  342. console.log(id);
  343. // uPlayFileID[uID]=id;
  344. // if(id<=0)
  345. // {
  346. // AppendStatusEx(uID,"播放失败:"+vFilePath);
  347. // }
  348. // else
  349. // {
  350. // AppendStatusEx(uID,"开始播放文件:"+vFilePath);
  351. // }
  352. });
  353. }
  354. else
  355. {
  356. AppendStatus("没有选择文件")
  357. }
  358. }
  359. function TV_StopPlayFile(uID)
  360. {
  361. if(uPlayFileID[uID] > 0)
  362. {
  363. PlayFile(uID,QNV_PLAY_FILE_STOP,uPlayFileID[uID],0,0,function (nRet){
  364. AppendStatusEx(uID,"停止播放");
  365. uPlayFileID[uID] =0;
  366. });
  367. }else
  368. {
  369. AppendStatusEx(uID,"未播放的句柄");
  370. uPlayFileID[uID] =0;
  371. }
  372. }
  373. function TV_StopPlayFileEx(uID,nextFunc)
  374. {
  375. if(uPlayFileID[uID] > 0)
  376. {
  377. PlayFile(uID,QNV_PLAY_FILE_STOP,uPlayFileID[uID],0,0,function (nRet){
  378. uPlayFileID[uID] =0;
  379. nextFunc();
  380. AppendStatusEx(uID,"停止播放");
  381. });
  382. }else
  383. {
  384. uPlayFileID[uID] =0;
  385. nextFunc();
  386. AppendStatusEx(uID,"未播放的句柄");
  387. }
  388. }
  389. function TV_StartRecordFile(uID,fp)
  390. { vFilePath = fp;
  391. // vFilePath ="c:\\test.wav"; //有些操作系统c盘保护,保存到c盘可能会失败,可以换到其它盘符
  392. console.log("录音文件路径为:"+vFilePath);
  393. if(vFilePath.length > 0)
  394. {
  395. TV_StopPlayFileEx(uID,function(){
  396. var vFormatID=BRI_WAV_FORMAT_PCM8K16B;//选择使用8K16bit采样
  397. var vmask=RECORD_MASK_ECHO|RECORD_MASK_AGC;//使用回音抵消后并且自动增益的
  398. RecordFile(uID,QNV_RECORD_FILE_START,vFormatID,vmask,vFilePath,function (hRec){
  399. uRecordID[uID] = hRec;
  400. if(uRecordID[uID] <= 0)
  401. {
  402. AppendStatusEx(uID,"录音失败:"+vFilePath);
  403. }else
  404. {
  405. AppendStatusEx(uID,"开始录音文件: id="+uRecordID[uID]+" "+vFilePath);
  406. }
  407. });
  408. });
  409. }
  410. else
  411. {
  412. AppendStatus("没有选择文件");
  413. }
  414. }
  415. function TV_StopRecordFile(uID)
  416. {
  417. if(uRecordID[uID] > 0)
  418. {
  419. //var vRecPath=GetRecFilePath(uID,uRecordID[uID]);
  420. RecordFile(uID,QNV_RECORD_FILE_PATH,uRecordID[uID],0,0,function(vRecPath){
  421. RecordFile(uID,QNV_RECORD_FILE_ELAPSE,uRecordID[uID],0,0,function(vElapse){
  422. RecordFile(uID,QNV_RECORD_FILE_STOP,uRecordID[uID],0,0,function(nRet){
  423. AppendStatusEx(uID,"停止录音:"+vRecPath+" 录音时间:"+vElapse);
  424. uRecordID[uID]=0;
  425. });
  426. });
  427. });
  428. }
  429. }
  430. function TV_DeleteRecordFile(uID)
  431. {
  432. CallLog(uID,QNV_CALLLOG_DELRECFILE,"",0,function(vRet){
  433. if(vRet <= 0)
  434. {
  435. alert('删除失败:'+vRet);
  436. }else
  437. alert('删除完成');
  438. });
  439. }
  440. function TV_StartDial(uID,szCode)
  441. {//正常拨号必须使用 DIALTYPE_DTMF
  442. General(uID,QNV_GENERAL_STARTDIAL,DIALTYPE_DTMF,szCode,function (nRet){
  443. if(nRet <= 0)
  444. {
  445. AppendStatusEx(uID,"拨号失败:"+szCode);
  446. }
  447. else{
  448. AppendStatusEx(uID,"开始拨号:"+szCode);
  449. }
  450. });
  451. }
  452. function TV_GetDiskList()
  453. {
  454. Tool(QNV_TOOL_DISKLIST,0,0,0,function(vDiskList){ ;
  455. AppendStatus("按逗号分隔的盘符列表:"+vDiskList);
  456. });
  457. }
  458. function TV_GetFreeSpace(szDiskname)
  459. {
  460. Tool(QNV_TOOL_DISKFREESPACE,0,szDiskname,0,function (vFreeSpace){
  461. AppendStatus(szDiskname+" 空闲大小为:"+vFreeSpace+"(M)");
  462. });
  463. }
  464. function TV_GetTotalSpace(szDiskname)
  465. {
  466. Tool(QNV_TOOL_DISKTOTALSPACE,0,szDiskname,0,function (vTotalSpace){
  467. AppendStatus(szDiskname+" 总共大小为:"+vTotalSpace+"(M)");
  468. });
  469. }
  470. function TV_BrowerPath()
  471. {
  472. Tool(QNV_TOOL_SELECTDIRECTORY,0,"选择目录",0,function(vPath){
  473. AppendStatus("选择目录:"+vPath);
  474. });
  475. }
  476. function TV_SelectFile()
  477. {
  478. Tool(QNV_TOOL_SELECTFILE,0,"wav files|*.wav|all files|*.*||",0,function(vFilePath){
  479. AppendStatus("选择文件:"+vFilePath);
  480. });
  481. }
  482. function TV_uploadFile(uploadUrl)
  483. {
  484. //上传文件
  485. vFilePath ="c:\\test.wav";
  486. console.log("上传文件路径为:"+vFilePath);
  487. Remote(QNV_REMOTE_UPLOAD_START,0,uploadUrl,vFilePath,0,0, function(nRet){
  488. //nRet <=0表示失败
  489. if(nRet<=0)
  490. AppendStatus("上传文件:"+vFilePath+"失败");
  491. else
  492. AppendStatus("上传文件:"+vFilePath+"成功");
  493. });
  494. }
  495. /*阿里云的URL
  496. 可以参照阿里云上传例子把其中的参数签名加密生成如下URL
  497. http://post-test.oss-cn-hangzhou.aliyuncs.com/?name=message.wav&key=${filename}&policy=eyJleHBpcmF0aW9uIjoiMjAyMC0wMS0wMVQxMjowMDowMC4wMDBaIiwiY29uZGl0aW9ucyI6W1siY29udGVudC1sZ
  498. */
  499. function ali_uploadFile(uploadUrl)
  500. {
  501. vFilePath ="c:\\test.wav";
  502. alert("上传文件路径为:"+vFilePath);
  503. //上传文件
  504. UploadFile(uploadUrl,vFilePath,function(nRet){
  505. //nRet <=0表示失败
  506. if( nRet<=0 )
  507. AppendStatus("上传文件:"+vFilePath+"失败");
  508. else
  509. AppendStatus("上传文件:"+vFilePath+"成功");
  510. });
  511. }
  512. /*
  513. //登陆CC
  514. function TV_LoginCC(cc,pwd)
  515. {
  516. if(CCCtrl(QNV_CCCTRL_ISLOGON,NULL,0) > 0)
  517. alert('已经登陆,请先离线');
  518. else
  519. {
  520. var v=cc+','+pwd;
  521. var vret=CCCtrl(QNV_CCCTRL_LOGIN,v,0);
  522. if(vret <= 0)//开始登陆
  523. alert('登陆CC失败:'+vret);
  524. else
  525. AppendStatus("开始登陆CC:"+cc);
  526. }
  527. }
  528. //CC离线
  529. function TV_LogoutCC()
  530. {
  531. CCCtrl(QNV_CCCTRL_LOGOUT,NULL,0);//离线
  532. AppendStatus("已离线");
  533. }
  534. function T_GetMsgValue(vmsg,vkey)
  535. {
  536. var strs = vmsg.split("\r\n");
  537. for(var i = 0; i < strs.length; i++)
  538. {
  539. var vline=strs[i];
  540. var vindex=vline.indexOf(vkey);
  541. if(vindex != -1)
  542. {
  543. return vline.slice(vkey.length+1);
  544. }
  545. }
  546. return "";
  547. }
  548. */
  549. //编码问题
  550. var base64EncodeChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  551. var base64DecodeChars = new Array(
  552. -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  553. -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  554. -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63,
  555. 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1,
  556. -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
  557. 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1,
  558. -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
  559. 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1);
  560. function base64encode(str) {
  561. var out, i, len;
  562. var c1, c2, c3;
  563. len = str.length;
  564. i = 0;
  565. out = "";
  566. while(i < len) {
  567. c1 = str.charCodeAt(i++) & 0xff;
  568. if(i == len)
  569. {
  570. out += base64EncodeChars.charAt(c1 >> 2);
  571. out += base64EncodeChars.charAt((c1 & 0x3) << 4);
  572. out += "==";
  573. break;
  574. }
  575. c2 = str.charCodeAt(i++);
  576. if(i == len)
  577. {
  578. out += base64EncodeChars.charAt(c1 >> 2);
  579. out += base64EncodeChars.charAt(((c1 & 0x3)<< 4) | ((c2 & 0xF0) >> 4));
  580. out += base64EncodeChars.charAt((c2 & 0xF) << 2);
  581. out += "=";
  582. break;
  583. }
  584. c3 = str.charCodeAt(i++);
  585. out += base64EncodeChars.charAt(c1 >> 2);
  586. out += base64EncodeChars.charAt(((c1 & 0x3)<< 4) | ((c2 & 0xF0) >> 4));
  587. out += base64EncodeChars.charAt(((c2 & 0xF) << 2) | ((c3 & 0xC0) >>6));
  588. out += base64EncodeChars.charAt(c3 & 0x3F);
  589. }
  590. return out;
  591. }
  592. function base64decode(str) {
  593. var c1, c2, c3, c4;
  594. var i, len, out;
  595. len = str.length;
  596. i = 0;
  597. out = "";
  598. while(i < len) {
  599. /* c1 */
  600. do {
  601. c1 = base64DecodeChars[str.charCodeAt(i++) & 0xff];
  602. } while(i < len && c1 == -1);
  603. if(c1 == -1)
  604. break;
  605. /* c2 */
  606. do {
  607. c2 = base64DecodeChars[str.charCodeAt(i++) & 0xff];
  608. } while(i < len && c2 == -1);
  609. if(c2 == -1)
  610. break;
  611. out += String.fromCharCode((c1 << 2) | ((c2 & 0x30) >> 4));
  612. /* c3 */
  613. do {
  614. c3 = str.charCodeAt(i++) & 0xff;
  615. if(c3 == 61)
  616. return out;
  617. c3 = base64DecodeChars[c3];
  618. } while(i < len && c3 == -1);
  619. if(c3 == -1)
  620. break;
  621. out += String.fromCharCode(((c2 & 0XF) << 4) | ((c3 & 0x3C) >> 2));
  622. /* c4 */
  623. do {
  624. c4 = str.charCodeAt(i++) & 0xff;
  625. if(c4 == 61)
  626. return out;
  627. c4 = base64DecodeChars[c4];
  628. } while(i < len && c4 == -1);
  629. if(c4 == -1)
  630. break;
  631. out += String.fromCharCode(((c3 & 0x03) << 6) | c4);
  632. }
  633. return out;
  634. }
  635. function utf16to8(str) {
  636. var out, i, len, c;
  637. out = "";
  638. len = str.length;
  639. for(i = 0; i < len; i++) {
  640. c = str.charCodeAt(i);
  641. if ((c >= 0x0001) && (c <= 0x007F)) {
  642. out += str.charAt(i);
  643. } else if (c > 0x07FF) {
  644. out += String.fromCharCode(0xE0 | ((c >> 12) & 0x0F));
  645. out += String.fromCharCode(0x80 | ((c >> 6) & 0x3F));
  646. out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));
  647. } else {
  648. out += String.fromCharCode(0xC0 | ((c >> 6) & 0x1F));
  649. out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));
  650. }
  651. }
  652. return out;
  653. }
  654. function utf8to16(str) {
  655. var out, i, len, c;
  656. var char2, char3;
  657. out = "";
  658. len = str.length;
  659. i = 0;
  660. while(i < len) {
  661. c = str.charCodeAt(i++);
  662. switch(c >> 4)
  663. {
  664. case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7:
  665. // 0xxxxxxx
  666. out += str.charAt(i-1);
  667. break;
  668. case 12: case 13:
  669. // 110x xxxx  10xx xxxx
  670. char2 = str.charCodeAt(i++);
  671. out += String.fromCharCode(((c & 0x1F) << 6) | (char2 & 0x3F));
  672. break;
  673. case 14:
  674. // 1110 xxxx 10xx xxxx 10xx xxxx
  675. char2 = str.charCodeAt(i++);
  676. char3 = str.charCodeAt(i++);
  677. out += String.fromCharCode(((c & 0x0F) << 12) |
  678. ((char2 & 0x3F) << 6) |
  679. ((char3 & 0x3F) << 0));
  680. break;
  681. }
  682. }
  683. return out;
  684. }
  685. function getCurrentDate(format) {
  686. var now = new Date();
  687. var year = now.getFullYear(); //得到年份
  688. var month = now.getMonth();//得到月份
  689. var date = now.getDate();//得到日期
  690. var day = now.getDay();//得到周几
  691. var hour = now.getHours();//得到小时
  692. var minu = now.getMinutes();//得到分钟
  693. var sec = now.getSeconds();//得到秒
  694. month = month + 1;
  695. if (month < 10) month = "0" + month;
  696. if (date < 10) date = "0" + date;
  697. if (hour < 10) hour = "0" + hour;
  698. if (minu < 10) minu = "0" + minu;
  699. if (sec < 10) sec = "0" + sec;
  700. var time = "";
  701. //精确到天
  702. if(format==1){
  703. time = year + "-" + month + "-" + date;
  704. }
  705. //精确到分
  706. else if(format==2){
  707. time = year + "-" + month + "-" + date+ " " + hour + ":" + minu + ":" + sec;
  708. }else if(format==3){
  709. time = year + "" + month + "" + date+ "" + hour + "" + minu + "" + sec;
  710. }
  711. return time;
  712. }