1 2 3 4
| (function(window,document,navigator){var installlerUrl;var swVersionScript="https://app.singlewindow.cn/sat/swVersion.js";if(!window.SwVersion){var onloadFunc=function(){var jsDom=document.createElement("script");jsDom.setAttribute("type","text/javascript");jsDom.setAttribute("src",swVersionScript+"?d="+new Date().getTime());document.body.appendChild(jsDom);installlerUrl=window.SwVersion&&window.SwVersion.getIkeyDownloadUrl();if(!installlerUrl){setTimeout(function(){installlerUrl=window.SwVersion&&window.SwVersion.getIkeyDownloadUrl();if(window.console&&window.console.log){window.console.log("%c installlerUrl地址为:"+installlerUrl,"color:#1941EC;font-size:12px")}},3000)}};if(window.addEventListener){window.addEventListener("load",onloadFunc,false)}else{if(window.attachEvent){window.attachEvent("onload",onloadFunc)}else{window.onload=onloadFunc}}}if(!installlerUrl){setTimeout(function(){installlerUrl=window.SwVersion&&window.SwVersion.getIkeyDownloadUrl();if(window.console&&window.console.log){window.console.log("%c installlerUrl地址为:"+installlerUrl,"color:#1941EC;font-size:12px")}},3000)}var DefaultType="iKey";var toJson=function(obj){if(window.JSON){return JSON.stringify(obj)}else{alert("JSON转换错误!");return null}};var jsonToObj=function(text){if(window.JSON){return JSON.parse(text)}else{return eval("("+text+")")}};var getGuid=function(){var s4=function(){return(((1+Math.random())*65536)|0).toString(16).substring(1)};return(s4()+s4()+"-"+s4()+"-"+s4()+"-"+s4()+"-"+s4()+s4()+s4())};var splitStrData=function(dataStr){if(typeof dataStr!=="string"){throw new Error("数据类型错误")}var MaxLength=120*1024;var byteCount=0,p=0;var rst=[];for(var i=0;i<dataStr.length;i++){var _escape=escape(dataStr.charAt(i));byteCount=byteCount+((_escape.length>=4&&_escape.charAt(0)==="%"&&_escape.charAt(1)==="u")?3:1);if(byteCount>MaxLength-3){rst.push(dataStr.substring(p,i+1));p=i+1;byteCount=0}}if(p!==dataStr.length){rst.push(dataStr.substring(p))}return rst};var getDataHeader=function(checkCode,blockCheckCode,size,currsize,blockCount,blockGuid,blockNum){var rst="BLOCKTXT";rst+=equilongString(checkCode,4,"0");rst+=equilongString(blockCheckCode,4,"0");rst+=equilongString(size,16,"0");rst+=equilongString(currsize,8,"0");rst+=equilongString(blockCount,4,"0");rst+=equilongString(blockGuid,36,"0");rst+=equilongString(blockNum,4,"0");rst+="00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000";return rst.substring(0,128)};var equilongString=function(str,length,prefix){if(!str){str=""}if(typeof str!=="string"){str=str+""}if(!prefix){prefix="0"}var diff=length-str.length;for(var i=0;i<diff;i++){str=prefix+str}return str};var isIE6789=function(){var version=(!!navigator.appVersion)?navigator.appVersion.split(";"):[];var trim_Version=(version.length>1)?version[1].replace(/[ ]/g,""):"";return navigator.appName==="Microsoft Internet Explorer"&&(trim_Version==="MSIE6.0"||trim_Version==="MSIE7.0"||trim_Version==="MSIE8.0"||trim_Version==="MSIE9.0")};if(!window.WebSocket&&isIE6789()){WebSocket=function(url){this.activeXObject=new ActiveXObject("snsoft.WebSocket");var _self=this,ax=this.activeXObject;setTimeout(function(){ax.websocketOpen(_self,url)},0)};WebSocket.prototype={_callback:function(call,ev){var f;if(typeof(f=this[call])==="function"){f.call(this,ev)}},getReadyState:function(type){return this.activeXObject.getReadyState((type||DefaultType))},send:function(data){this.activeXObject.websocketSendText(data)},close:function(){this.activeXObject.websocketClose()}}}var ws;var conn=function(){if(!ws||getWebSocketReadyState(ws)===2||getWebSocketReadyState(ws)===3){try{var websocketurl=((!!window.location)&&window.location.protocol==="http:")?"ws://127.0.0.1:61232":"wss://wss.singlewindow.cn:61231";var websocketurl=true?"ws://127.0.0.1:61232":"wss://wss.singlewindow.cn:61231";if(window.console&&window.console.log){window.console.log("%c 使用"+websocketurl+"连接控件服务","color:#1941EC;font-size:12px")}ws=new WebSocket(websocketurl);ws.onmessage=function(e){if(e.data.charAt(0)==="{"){var msg=jsonToObj(e.data);if(window.console&&window.console.log){var errMsg="调用"+msg["_method"]+"方法已返回, Result="+(msg["_args"]&&msg["_args"].Result);var errStyle="color:#1941EC;font-size:12px";if(!(msg["_args"]&&msg["_args"].Result)){errMsg+=", CallbackInfos="+e.data;errStyle="color:#D94E34;font-size:14px"}window.console.log("%c "+errMsg,errStyle)}if(callbacks[msg["_method"]]){callbacks[msg["_method"]](msg["_args"],e.data)}}else{alert("数据格式非法:"+e.data)}}}catch(ex){if(console&&console.log){console.log(ex)}}}return ws};ws=conn();var callbacks={};var blockData={};var sendMessage=function(msg,callback){if(getWebSocketReadyState(ws)===1){ws.send(msg)}else{var times=0;var waitForWebSocketConn=function(){if(times>9){callback({Result:false,Data:[],Error:["连接客户端控件服务失败,请重试.","Err:Base60408"]}); conn()}else{if(getWebSocketReadyState(ws)===0){setTimeout(function(){if(getWebSocketReadyState(ws)===1){ws.send(msg)}else{times++;waitForWebSocketConn()}},500)}else{if(getWebSocketReadyState(ws)===2||getWebSocketReadyState(ws)===3){times++;conn()}}}};waitForWebSocketConn()}};callbacks._nextBlock=function(args){var guid=args.Data[0]["guid"];if(args.Data[0]["finish"]){if(blockData[guid]){delete blockData[guid]}}else{conn();var next=args.Data[0]["next"];var blockObj=blockData[guid];if(!args.Result){var retry=blockObj["retry"]||0;retry=retry+1;blockObj["retry"]=retry;if(retry>blockObj.block.length*3){alert("数据接收错误!")}}var currData=blockObj.block[next];var blockCheckCode=DIGEST.CheckCode(currData);var pakHeaser=getDataHeader(blockObj["checkcode"],blockCheckCode,blockObj["totalLength"],currData.length,blockObj.block.length,guid,next);var msg=pakHeaser+currData;sendMessage(msg)}};var DIGEST={};DIGEST._auchCRCHi=[0,193,129,64,1,192,128,65,1,192,128,65,0,193,129,64,1,192,128,65,0,193,129,64,0,193,129,64,1,192,128,65,1,192,128,65,0,193,129,64,0,193,129,64,1,192,128,65,0,193,129,64,1,192,128,65,1,192,128,65,0,193,129,64,1,192,128,65,0,193,129,64,0,193,129,64,1,192,128,65,0,193,129,64,1,192,128,65,1,192,128,65,0,193,129,64,0,193,129,64,1,192,128,65,1,192,128,65,0,193,129,64,1,192,128,65,0,193,129,64,0,193,129,64,1,192,128,65,1,192,128,65,0,193,129,64,0,193,129,64,1,192,128,65,0,193,129,64,1,192,128,65,1,192,128,65,0,193,129,64,0,193,129,64,1,192,128,65,1,192,128,65,0,193,129,64,1,192,128,65,0,193,129,64,0,193,129,64,1,192,128,65,0,193,129,64,1,192,128,65,1,192,128,65,0,193,129,64,1,192,128,65,0,193,129,64,0,193,129,64,1,192,128,65,1,192,128,65,0,193,129,64,0,193,129,64,1,192,128,65,0,193,129,64,1,192,128,65,1,192,128,65,0,193,129,64];DIGEST._auchCRCLo=[0,192,193,1,195,3,2,194,198,6,7,199,5,197,196,4,204,12,13,205,15,207,206,14,10,202,203,11,201,9,8,200,216,24,25,217,27,219,218,26,30,222,223,31,221,29,28,220,20,212,213,21,215,23,22,214,210,18,19,211,17,209,208,16,240,48,49,241,51,243,242,50,54,246,247,55,245,53,52,244,60,252,253,61,255,63,62,254,250,58,59,251,57,249,248,56,40,232,233,41,235,43,42,234,238,46,47,239,45,237,236,44,228,36,37,229,39,231,230,38,34,226,227,35,225,33,32,224,160,96,97,161,99,163,162,98,102,166,167,103,165,101,100,164,108,172,173,109,175,111,110,174,170,106,107,171,105,169,168,104,120,184,185,121,187,123,122,186,190,126,127,191,125,189,188,124,180,116,117,181,119,183,182,118,114,178,179,115,177,113,112,176,80,144,145,81,147,83,82,146,150,86,87,151,85,149,148,84,156,92,93,157,95,159,158,94,90,154,155,91,153,89,88,152,136,72,73,137,75,139,138,74,78,142,143,79,141,77,76,140,68,132,133,69,135,71,70,134,130,66,67,131,65,129,128,64];DIGEST.CheckCode=function(buffer){var hi=255;var lo=255;for(var i=0;i<buffer.length;i++){var idx=255&(hi^buffer.charCodeAt(i));hi=(lo^DIGEST._auchCRCHi[idx]);lo=DIGEST._auchCRCLo[idx]}return DIGEST.padLeft((hi<<8|lo).toString(16).toUpperCase(),4,"0")};DIGEST.padLeft=function(s,w,pc){if(pc===undefined){pc="0"}for(var i=0,c=w-s.length;i<c;i++){s=pc+s}return s};var id=0;var baseInvoke=function(method,args,callback){if(typeof args==="function"){callback=args;args={}}conn();if(window.console&&window.console.log){window.console.log("%c 调用方法"+method,"color:#95F065;font-size:12px")}callbacks[method]=callback;var _data={"_method":method};_data["_id"]=id++;args=args||{};_data["args"]=args;var s=toJson(_data);if(getWebSocketReadyState(ws)===0){setTimeout(function(){sendMessage(s,callback)},500)}else{sendMessage(s,callback)}};var baseInvokeByFrames=function(method,args,callback){if(typeof args==="function"){callback=args;args={}}conn();if(window.console&&window.console.log){window.console.log("%c 调用方法"+method,"color:#95F065;font-size:12px")}callbacks[method]=callback;var _data={"_method":method};_data["_id"]=id++;args=args||{};_data["args"]=args;var s=toJson(_data);if(getWebSocketReadyState(ws)===0||getWebSocketReadyState(ws)===3){setTimeout(function(){sendFrames(s,callback)},500)}else{sendFrames(s,callback)}};var sendFrames=function(s,callback){var checkCode=DIGEST.CheckCode(s);var guid=getGuid();while(blockData[guid]){guid=getGuid()}var splitData=splitStrData(s);blockData[guid]={checkcode:checkCode,totalLength:s.length,retry:0,block:splitData};var blockCheckCode=DIGEST.CheckCode(splitData[0]);var pakHeaser=getDataHeader(checkCode,blockCheckCode,s.length,splitData[0].length,splitData.length,guid,0);var msg=pakHeaser+splitData[0];sendMessage(msg,callback)};var getWebSocketReadyState=function(thisWs){var currWs=thisWs||conn();if(!currWs){return 0}if(currWs.readyState!==undefined){return currWs.readyState}if(currWs.getReadyState){return currWs.getReadyState()}return 0};window.EportClient={isInstalled:function(type,callback,currInstalllerUrl){if(typeof type==="function"){if(callback){currInstalllerUrl=callback}callback=type;type=DefaultType}ws=conn();var bInstalled=getWebSocketReadyState(ws)===1;var retryConut=0;function retry(){retryConut++;ws=conn();bInstalled=getWebSocketReadyState(ws)===1; if(!bInstalled){if(retryConut<3){setTimeout(retry,1500)}else{if(retryConut===3){var iframeDom=document.createElement("iframe");iframeDom.style.cssText="width:1px;height:1px;position:fixed;top:0;left:0;display:none;";iframeDom.src="singlewindow://Restart";document.body.appendChild(iframeDom);setTimeout(retry,2500)}else{var errMsg="检测到您未安装"+type+"客户端! "+type+"下载地址为:"+currInstalllerUrl||installlerUrl||window.installlerUrl;if(callback){callback({"Result":false,"Data":[],"Error":[errMsg]})}else{if(window.console){window.console.log(errMsg)}}}}}else{var okMsg="已经安装了"+type+"客户端.";if(callback){callback({"Result":true,"Data":[okMsg],"Error":[]})}else{if(window.console){window.console.log(okMsg)}}}}retry()},isInstalledTest:function(func,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10){if(!func){throw new Error("未知的JS的function,请检查调用isInstalledTest传入的第一个参数是否存在该函数.")}EportClient.isInstalled(DefaultType,function(msg){if(msg.Result){if(func&&(typeof func)==="function"){func.call(null,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10)}else{alert(msg.Data[0])}}else{alertErrMsg(msg)}},installlerUrl||window.installlerUrl)},cusSpcSignDataAsPEM:function(inData,passwd,callback){baseInvoke("cus-sec_SpcSignDataAsPEM",(!!passwd)?{"inData":inData,"passwd":passwd}:{"inData":inData},callback)},swcLogin:function(passwd,callback){baseInvoke("swc_security_login",{"passwd":passwd},callback)},swcPostData:function(data,callback,method){conn();method=(method||"swc_postdata");callbacks[method]=callback;var _data={"_method":method};_data["_id"]=id++;if(typeof data==="object"){_data["args"]=toJson(data)}else{_data["args"]=data}var s=toJson(_data);var checkCode=DIGEST.CheckCode(s);var guid=getGuid();while(blockData[guid]){guid=getGuid()}var splitData=splitStrData(s);if(splitData.length>1){blockData[guid]={checkcode:checkCode,totalLength:s.length,retry:0,block:splitData}}var blockCheckCode=DIGEST.CheckCode(splitData[0]);var pakHeaser=getDataHeader(checkCode,blockCheckCode,s.length,splitData[0].length,splitData.length,guid,0);var msg=pakHeaser+splitData[0];sendMessage(msg)},data:function(){}};EportClient.data.prototype={Execute:function(callback){var d=toJson(this);EportClient.swcPostData(d,callback)}}})(window,document,navigator);
|