commonH5Utils.js 9.02 KB
var n=require("./commonMd5.js");export default class t{constructor(){this.checkConfigListener="";this.checkOrderListener="";this.statisticsListenerProxy="";this.location="";this.configInfoReturn;this.gzyasjhInfo={};this.configCheckUrl="https://static.public.sdk.guangkatf.com/config";this.sdkInfo={gameSimpleName:"",sdkSimpleName:"",sdkVersionCode:"",sdkClientVersion:"",loginCheckUrl:"",payOrderUrl:"",payCheckUrl:"",logReportUrl:"",statisticsUrl:"",channelParameter1:"",channelParameter2:"",channelId:"",custom:""};this.loginInfo={gameSimpleName:"",sdkSimpleName:"",sdkVersionCode:"",result:"",userType:"",openId:"",userName:"",sign:"",timestamp:"",other:"",serverSign:"",custom:"",custom2:"",di:"",nt:"",gv:"",ot:navigator.platform,imei:"",rl:"",c1:"",c2:""};this.payInfo={serverId:"",serverName:"",playerId:"",playerName:"",playerLevel:"",postAmount:"",productId:"",productName:"",productDesc:"",custom:"",exchange:"",otherInfo:"",timestamp:"",tsign:"",userId:"",di:"",nt:"",gv:"",ot:navigator.platform,imei:"",rl:"",c1:"",c2:"",coinName:"",coinNum:""};this.orderInfo={queryID:"",serverID:"",roleId:"",postTime:"",postAmount:"",productID:"",currency:"",other:"",products:"",danjiConfig:""};this.roleInfo={roleId:"",roleName:"",roleLevel:"",roleSex:"",serverId:"",serverName:"",roleCTime:"",partyName:"",roleType:"",roleChangeTime:"",vipLevel:"",diamond:"",moneyType:"",custom:""}}static getInstance(){return t.instance||(t.instance=new t),t.instance}connection(n,t,i){var u=this,r=new XMLHttpRequest,f,e;r.onreadystatechange=function(){if(r.readyState==4)if(r.status>=200&&r.status<300||r==304){u.sdkLog("H5SDKLog||"+n+"||Connect server successful:"+r.responseText);try{u.sdkLog(typeof r.responseText);u.responseListener(n,JSON.parse(r.responseText),r.status)}catch(t){u.sdkLog(t)}}else u.noResponse(n),u.sdkLog("H5SDKLog||"+n+"||Fail to connect server!");u.sdkLog("readyState: "+r.readyState)};n=="login"?(r.open("post",t,!1),f="data="+JSON.stringify(this.loginInfo),u.sdkLog("login url: "+t),u.sdkLog("login data: "+f),r.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),r.send(f)):n=="submitInfo"?(f=this.addUrlParam("",i),r.open("post",t,!1),r.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),r.send(f.substring(1))):n=="statistics"?(r.open("post",t,!1),r.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8"),f=JSON.stringify(i),r.send(f)):(n=="configInfo"?(t=t+"/"+this.sdkInfo.gameSimpleName+"/"+this.sdkInfo.sdkSimpleName+"/"+this.sdkInfo.sdkVersionCode+"/config.json",u.sdkLog("configInfo url:"+t)):n=="location"||(n=="payCheck"?(e=JSON.stringify(i),window.conch||(e=encodeURIComponent(e)),t=t+"/"+this.sdkInfo.gameSimpleName+"/"+this.sdkInfo.sdkSimpleName+"/"+this.sdkInfo.sdkVersionCode+"?data="+e):(t=t+"/"+this.sdkInfo.gameSimpleName+"/"+this.sdkInfo.sdkSimpleName+"/"+this.sdkInfo.sdkVersionCode,t=this.addUrlParam(t,i))),u.sdkLog(t),r.open("get",t,!1),r.send(null))}configCheck(n,t){typeof n=="string"&&(n=JSON.parse(n));for(var i in n)this.sdkInfo[i]=n[i],i==="otherInfo"&&this.setGzyasjhInfo(n[i]),this.sdkLog(this.sdkInfo[i]);this.checkConfigListener=t;this.sdkLog("H5SDKLog||Ask configCheck to server with sdkInfo:"+JSON.stringify(this.sdkInfo));this.connection("configInfo",this.configCheckUrl,this.sdkInfo)}loginCheck(n){for(var t in n)this.loginInfo[t]=n[t];this.loginInfo.sign=n.token;this.loginInfo.custom=commonH5SDK.h5Proxy.loginExt;this.loginInfo=this._addDataToTable(this.loginInfo);this.sdkLog("H5SDKLog||Ask loginCheck to server with loginInfo:"+JSON.stringify(this.loginInfo));this.connection("login",this.sdkInfo.loginCheckUrl,this.loginInfo)}payCheck(t,i){for(var r in t)this.payInfo[r]=t[r];t.openId!=undefined&&t.openId.length>0&&(this.payInfo.userId=t.openId);this.payInfo.tsign=n(this.payInfo.timestamp+"12*&#**@321");this.checkOrderListener=i;this.payInfo=this._addDataToTable(this.payInfo);this.sdkLog("H5SDKLog||Ask payCheck to server with payInfo:"+JSON.stringify(this.payInfo));this.connection("payCheck",this.sdkInfo.payOrderUrl,this.payInfo)}submitInfo(t,i){var f,e,u,r,s;if(i!=null)for(f in i)this.roleInfo[f]=i[f];e="";t.indexOf(":")!=-1&&(e=t.substring(t.indexOf(":")+1));u={pid:this.roleInfo.roleId,pn:this.roleInfo.roleName,sid:this.roleInfo.serverId,sn:this.roleInfo.serverName,lv:this.roleInfo.roleLevel,openId:this.loginInfo.openId,gameSimpleName:this.sdkInfo.gameSimpleName,sdkSimpleName:this.sdkInfo.sdkSimpleName,sdkVersionCode:this.sdkInfo.sdkVersionCode,di:"",nt:"",gv:"",ot:navigator.platform,imei:"",rl:"",c1:this.sdkInfo.channelParameter1,c2:this.sdkInfo.channelParameter2,eventName:e};u=this._addDataToTable(u);r=(new Date).getTime().toString();r=r.substring(0,r.length-3);this.sdkLog(JSON.stringify(u));var h="action="+t+"jssdk=yt="+r+"12909asdask23",o={action:t,data:JSON.stringify(u),jssdk:"y",t:r,ta:"default",test:"test",sign:n(h)};this.sdkLog("H5SDKLog||Submit to server with roleCheckInfo:"+JSON.stringify(o));s=this.sdkInfo.logReportUrl+"?ya_game="+this.sdkInfo.gameSimpleName+"&ya_sn="+this.sdkInfo.sdkSimpleName+"&ya_ssv="+this.sdkInfo.sdkVersionCode;this.connection("submitInfo",s,o)}statistics(n,t){this.statisticsListenerProxy=t;this.connection("statistics",this.sdkInfo.statisticsUrl,n)}addUrlParam(n,t){for(var i in t)n+=n.indexOf("?")==-1?"?":"&",n=n+i+"="+t[i];return n}responseListener(n,t,i){var f,u,e,r;if(n=="configInfo")t.code==1?(this.sdkInfo.payCheckUrl=t.data.payCheckUrl,this.sdkInfo.payOrderUrl=t.data.payOrderUrl,this.sdkInfo.loginCheckUrl=t.data.loginCheckUrl,this.sdkInfo.logReportUrl=t.data.logReportUrl,this.sdkInfo.channelParameter1=t.data.channelParameter1,this.sdkInfo.custom=t.data.custom,this.sdkInfo.channelId=t.data.channelSimpleName,this.loginInfo.c1=t.data.channelParameter1,this.payInfo.c1=t.data.channelParameter1,this.sdkInfo.channelParameter2=t.data.channelParameter2,this.loginInfo.c2=t.data.channelParameter2,this.payInfo.c2=t.data.channelParameter2,this.sdkLog("H5SDKLog||ConfigCheck successful with configInfo:"+JSON.parse(t.data.clientConfig)),this.configInfoReturn=JSON.parse(t.data.clientConfig),this.checkConfigListener.onCheckConfigSuccess()):(this.sdkLog("H5SDKLog||No configs!Please check whether the sdkInfo is matching or not!"),this.checkConfigListener.onCheckConfigFail());else if(n=="login")t.code==1?(this.sdkLog("H5SDKLog||LoginCheck successful with loginInfo:"+JSON.stringify(t)),this.loginInfo.openId=t.openId,this.payInfo.userId=t.openId,this.loginInfo.custom=commonH5SDK.h5Proxy.loginExt,t.custom=commonH5SDK.h5Proxy.loginExt,t.custom2=this.loginInfo.custom2,commonH5SDK.callback(commonH5SDK.code.LOGIN_SUCCESS,t)):(this.sdkLog("H5SDKLog||LoginCheck fail with message:"+t.message),commonH5SDK.callback(commonH5SDK.code.LOGIN_FAIL,"login error"));else if(n=="payCheck"){for(r in t)r=="code"?f=t[r]:r=="data"?u=t[r]:r=="message"&&(e=t[r]);if(this.sdkLog(f),this.sdkLog(u),this.sdkLog(e),f==1){this.sdkLog("H5SDKLog||PayCheck successful with orderInfo:"+JSON.stringify(u));this.checkOrderListener.onSuccess(u)}else this.sdkLog("H5SDKLog||PayCheck fail with message:"+e),this.checkOrderListener.onFail()}else n=="roleInfo"?this.sdkLog("H5SDKLog||Submit roleInfo result:"+t):n=="statistics"?i==200?(this.sdkLog("H5SDKLog||Statistics result:"+i),this.statisticsListenerProxy.onStatisticsSuccess()):(this.sdkLog("H5SDKLog||Statistics result:"+i),this.statisticsListenerProxy.onStatisticsFail()):n=="location"&&(t.code==0?(this.location=t.data,this.sdkLog("Location:"+t.data)):this.sdkLog("Location:Fail!"))}noResponse(n){n=="configInfo"?this.checkConfigListener.onCheckConfigFail():n=="login"?commonH5SDK.callback(commonH5SDK.code.LOGIN_FAIL,"login check network error"):n=="payCheck"?this.checkOrderListener.onFail():n=="roleInfo"||(n=="statistics"?this.statisticsListenerProxy.onStatisticsFail():n=="location"&&this.sdkLog("Location:Fail!"))}setGzyasjhInfo(n){if(n&&n.length>0){var t=JSON.parse(decodeURIComponent(n));t&&(this.gzyasjhInfo=t)}typeof this.gzyasjhInfo!="object"&&(this.gzyasjhInfo={})}_addDataToTable(n){if(typeof n=="object"){var t=navigator.platform;this.gzyasjhInfo.ot==null&&navigator.userAgent&&(t=t+"|"+JSON.stringify(this.allinfo()));n.di=this.gzyasjhInfo.di||"";n.nt=this.gzyasjhInfo.nt||"";n.gv=this.gzyasjhInfo.gv||"";n.ot=(this.gzyasjhInfo.ot||"")+"|"+t;n.imei=this.gzyasjhInfo.imei||"";n.rl=this.gzyasjhInfo.rl||""}return n}allinfo(){return{userAgent:(navigator.userAgent||"").replace(/[;/]/g," "),appName:navigator.appName||"",appVersion:(navigator.appVersion||"").replace(/[;/]/g," "),cookieEnabled:navigator.cookieEnabled||"",cpuClass:navigator.cpuClass||"",mimeType:navigator.mimeTypes||"",platform:navigator.platform||"",userLanguage:navigator.userLanguage||"",systemLanguage:navigator.systemLanguage||"",oscpu:navigator.oscpu||"",product:navigator.product||"",productSub:navigator.productSub||"",vender:navigator.vender||"",vendorSub:navigator.vendorSub||"",webkitPersistentStorage:navigator.webkitPersistentStorage||"",language:navigator.language||"",appCodeName:navigator.appCodeName||""}}getPayUrlCallBack(){return this.sdkInfo.payCheckUrl+"/"+this.sdkInfo.gameSimpleName+"/"+this.sdkInfo.sdkSimpleName+"/"+this.sdkInfo.sdkVersionCode}sdkLog(n){commonH5SDK.sdk_isShowLog&&console.log("commonH5SDK:"+n)}}