1 |
- !function(e,t){typeof define=="function"&&(define.amd||define.cmd)?define([],function(){return t(e)}):t(e)}(this,function(e){function R(){WebViewJavascriptBridge.callHandler("getLoginNumber",null,function(e){CTK.LoginNumber=e}),WebViewJavascriptBridge.callHandler("getAuthToken",null,function(e){CTK.AuthToken=e}),WebViewJavascriptBridge.callHandler("getApiLevel",null,function(e){CTK.ApiLevel=i=e*1}),WebViewJavascriptBridge.callHandler("getSecret",null,function(e){CTK.Secret=e}),WebViewJavascriptBridge.callHandler("getWXPaySupported",null,function(e){switch(e){case"true":CTK.WXPaySupported=!0;break;case"false":CTK.WXPaySupported=!1}}),WebViewJavascriptBridge.callHandler("getWeixinAppInstalled",null,function(e){switch(e){case"true":CTK.WXAppInstalled=!0;break;case"false":CTK.WXAppInstalled=!1}})}function U(){var e=ot()+"";return e.indexOf("13800000000")!=-1?!0:!1}function z(e,t){if(e+t in window)return;var n=document.createElement(e),r=new XMLHttpRequest;r.onreadystatechange=function(){r.readyState==4&&(r.status>=200&&r.status<300||r.status==304)&&(n.innerHTML=r.responseText,document.head.appendChild(n),window[e+t]=!0)},r.open("GET",t,!1),r.send(null)}function W(){function e(){window.location.hash!="#cashier"&&(O.style.display="none",M.contentWindow&&M.contentWindow.postMessage({status:"close"},"*"))}O=document.createElement("div"),M=document.createElement("iframe"),O.style.cssText="position: fixed; top: 0; left: 0; z-index: 9999; width: 100%; height: 100%; display: none",M.style.cssText="display: block; width: 100%; height: 100%",M.setAttribute("frameborder","0"),M.src=s+"/page_v3/cashier.html?tradeService="+g+"&totalFee="+m,O.appendChild(M),document.body.appendChild(O),window.cashierLink=M,window.removeEventListener("hashchange",e),window.addEventListener("hashchange",e),M.addEventListener("load",function(){window.isIframeLoadCompleted=!0,window.loadQueue&&window.loadQueue()},!1)}function X(){function e(){var e=window.location.hash;e==""&&CTAW.hidden()}var t=vt("native_param_addr");t&&t.length>0&&localStorage.setItem("native_param_addr",t),console.log("ycs call CTAW init"),CTAW.init(),window.addEventListener("hashchange",e)}function V(e){var t=!0,r=!0;P&&i<3?r=!1:!P&&n<19?(n<10&&(t=!1),r=!1):ft()?lt()||(r=!1):r=!1,O.style.display="block",M.contentWindow.postMessage({status:"start",tradeService:g,products:y||[],totalFee:m,token:it(),secret:ut(),ali:t,wei:r,inapp:e||!1},"*"),window.location.hash="#cashier"}function J(e){var t={status:"start"};e&&e.length>5&&(t.curContactId=e);if(P){var n=it();t.token=n,k.contentWindow.postMessage(t,"*"),setTimeout(function(){C.style.display="block",window.location.hash="#address",K(L,!0)},500)}else k.contentWindow.postMessage(t,"*"),setTimeout(function(){C.style.display="block",window.location.hash="#address",K(L,!0)},500)}function K(e,t){if(!P)return;var n=document.body.children;t&&(_=new Array(n.length+2));for(var r=0;r<n.length;++r){var i=n[r];if(i.tagName=="SCRIPT")continue;if(i.getAttribute("id")==e)continue;t?(_[r]=i.style.display,i.style.display="none"):i.style.display=_[r]}}function Q(e){var t="";for(var n=0;n<e.length;n++)t+=String.fromCharCode((e.charCodeAt(n)-33)/3);var r=t.length-parseInt(t.length/4),i=t.substring(0,r),s=t.substring(r,t.length),o=s+i;return r=o.length-parseInt(o.length/7),i=o.substring(0,r),s=o.substring(r,o.length),s+i}function G(e){var t="http://open.cootekservice.com/pay/result?transactionId="+localStorage.getItem("transaction_id")+"&resCode="+e+"&_token="+it(),n=new XMLHttpRequest;n.open("GET",t,!0),n.send(null)}function Y(){E=document.createElement("div"),S=document.createElement("img"),x=document.createElement("p"),E.style.cssText="position: fixed; top: 50%; left: 50%; -webkit-transform: translate(-50%, -50%); display: inline-block; background-color: rgba(0, 0, 0, 0.7); border-radius: 3px; z-index: 10000; white-space: nowrap",S.style.cssText="position: absolute; top: 50%; left: 5px; margin-top: -6px; width: 12px; height: 12px",x.style.cssText="margin-left: 22px; color: #fff; font-size: 1.2rem; height: 3rem; line-height: 3rem; padding-right: 5px",S.src=s+"/res/image/load_circle.png",E.appendChild(S),E.appendChild(x)}function Z(){if(n>=32)var e=t.getAccessToken();else if(P&&i>=20)var e=CTK.AccessToken;if(e&&e.length>5)return e;var r={token:it(),etoken:""};return H.encode(JSON.stringify(r))}function et(e){e&&e.preventDefault(),e&&e.stopPropagation();var t={paymentType:D,authToken:it()};b.length>0&&(t.cards=b),d=null,typeof p=="function"&&(w&&w.removeEventListener("click",et,!1),w&&(w.style.backgroundColor="#abcfe9"),p({tradeStr:H.encode(JSON.stringify(t))}))}function tt(e,s){var o={id:e,name:s,version:0,city:vt("city"),geo_city:vt("native_param_city"),source:window.location.href,trigger_time:+(new Date)};o=JSON.stringify(o),!P&&n>=3?t.appendScenarioNode(o):P&&i>=1?r.callHandler("appendScenarioNode",o,function(e){console.log(e)}):console.log("no appendScenarioNode")}function nt(e){var s=e.url.indexOf("?")===-1;url=s?e.url+"?client=wechat":e.url+"&client=wechat";var o=JSON.stringify({type:"wechat",msg:e.msg,url:url,title:e.title});!P&&n>=9?t.shareMessage(o):P&&i>=4?r.callHandler("shareWXMessage",o,function(e){console.log(e)}):console.log("no share wechat!")}function rt(e){var s=e.url.indexOf("?")===-1;url=s?e.url+"?client=wechat":e.url+"&client=wechat";var o=JSON.stringify({type:"wechat_moment",url:url,title:e.title,wechat_share_image_kind:2,imagePath:"webpages/share_icon",imageName:""});!P&&n>=15?t.shareWechatMoment(o):P&&i>=4?r.callHandler("shareWXMoment",o,function(e){console.log(e)}):console.log("no share moment!")}function it(){return P&&r?CTK.AuthToken:t?t.getAuthToken():localStorage.getItem("auth_token")}function st(){!P&&n>=1?t.backPage():P&&i>=3?r.callHandler("backPage","",function(e){console.log(e)}):history.back()}function ot(){return!P&&n>=10?t.getLoginNumber():P&&r?CTK.LoginNumber:""}function ut(){if(!P&&n>=10)return t.getSecret();if(P&&r){var e=CTK.Secret;return i<=9&&(e=Q(e)),e}return""}function at(e){var t=ot();if(!t||t.length==0)t=it();var n="ct_cache_"+t+"_"+e;return n}function ft(){return!P&&n>=19?t.isWXAppInstalled():P&&i>=3?CTK.WXAppInstalled:!1}function lt(){return!P&&n>=19?t.isWXPaySupported():P&&i>=3?CTK.WXPaySupported:!1}function ct(e){if(!P&&n>=10)return t.alipay(e,"CTKCallBackFuncs.payCallBack");if(P&&r){var i=e.slice(0,-1),s={callback:"CTKCallBackFuncs.alipayHandler",info:e};i.split('"&').forEach(function(e){var t=e.split('="');s[t[0]]=t[1]}),console.log("--------- "+JSON.stringify(s)),r.callHandler("alipay",JSON.stringify(s),function(e){console.log(e)})}}function ht(e){if(!P&&n>=19)return t.weixinpay(e,"CTKCallBackFuncs.payCallBack");if(P&&i>=3){var s=JSON.parse(e);s.callback="CTKCallBackFuncs.weipayHandler",r.callHandler("weixinpay",JSON.stringify(s),function(e){console.log(e)})}}function pt(){!P&&n>=1?t.locate():P&&i>=1&&r.callHandler("locate","CTKCallBackFuncs.locateCallback",function(e){console.log(e)})}function dt(e,t,n){if(r){if(CTK[e]&&!t)return CTK[e];if(e=="LocateCacheTime"&&!t)return CTK.LocateCacheTime||CTK.LocationCacheTime;r.callHandler("get"+e,n,function(t){console.log("respone: "+t);switch(t){case"true":CTK[e]=!0;break;case"false":CTK[e]=!1;break;default:CTK[e]=t}})}}function vt(e,s){if(!P&&n>=1)return t.storageGetItem(e);if(!P)return localStorage.getItem(e);if(!(r&&i<=2))return localStorage.getItem(e);switch(e){case"native_param_location":return dt("Location",s);case"native_param_city":return dt("City",s);case"native_param_addr":return dt("Address",s);case"native_param_locate_cache_time":return dt("LocateCacheTime",s);case"native_param_city_cache_time":return dt("CityCacheTime",s);case"native_param_addr_cache_time":return dt("AddrCacheTime",s);default:return localStorage.getItem(e)}}function mt(e,r){!P&&n>0?t.storageSetItem(e,r):localStorage.setItem(e,r)}function gt(e,t,n){Et.getLocation({success:function(t){e({coords:{city:t.city,address:t.address,latitude:t.latitude,longitude:t.longitude},timestamp:vt("native_param_locate_cache_time")})}})}function yt(){_keyStr="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",this.encode=function(e){var t="",n,r,i,s,o,u,a,f=0;e=_utf8_encode(e);while(f<e.length)n=e.charCodeAt(f++),r=e.charCodeAt(f++),i=e.charCodeAt(f++),s=n>>2,o=(n&3)<<4|r>>4,u=(r&15)<<2|i>>6,a=i&63,isNaN(r)?u=a=64:isNaN(i)&&(a=64),t=t+_keyStr.charAt(s)+_keyStr.charAt(o)+_keyStr.charAt(u)+_keyStr.charAt(a);return t},this.decode=function(e){var t="",n,r,i,s,o,u,a,f=0;e=e.replace(/[^A-Za-z0-9\+\/\=]/g,"");while(f<e.length)s=_keyStr.indexOf(e.charAt(f++)),o=_keyStr.indexOf(e.charAt(f++)),u=_keyStr.indexOf(e.charAt(f++)),a=_keyStr.indexOf(e.charAt(f++)),n=s<<2|o>>4,r=(o&15)<<4|u>>2,i=(u&3)<<6|a,t+=String.fromCharCode(n),u!=64&&(t+=String.fromCharCode(r)),a!=64&&(t+=String.fromCharCode(i));return t=_utf8_decode(t),t},_utf8_encode=function(e){e=e.replace(/\r\n/g,"\n");var t="";for(var n=0;n<e.length;n++){var r=e.charCodeAt(n);r<128?t+=String.fromCharCode(r):r>127&&r<2048?(t+=String.fromCharCode(r>>6|192),t+=String.fromCharCode(r&63|128)):(t+=String.fromCharCode(r>>12|224),t+=String.fromCharCode(r>>6&63|128),t+=String.fromCharCode(r&63|128))}return t},_utf8_decode=function(e){var t="",n=0,r=c1=c2=0;while(n<e.length)r=e.charCodeAt(n),r<128?(t+=String.fromCharCode(r),n++):r>191&&r<224?(c2=e.charCodeAt(n+1),t+=String.fromCharCode((r&31)<<6|c2&63),n+=2):(c2=e.charCodeAt(n+1),c3=e.charCodeAt(n+2),t+=String.fromCharCode((r&15)<<12|(c2&63)<<6|c3&63),n+=3);return t}}var t=e.CTKJavaScriptHandler,n=t&&t.getApiLevel()||0,r,i=0,s="http://121.52.250.37:15080",o="http://121.52.250.37:15080",u=[],a="alipay",f="weipay",l="weipay_oem",c,h,p,d,v,m=0,g="",y=[],b=[],w,E,S,x,T,N,C,k,L="i-ct-op-address",A=!1,O,M,_,D="",P=e.navigator.userAgent.toLowerCase().indexOf("iphone")!=-1,H=new yt,B={ready:{ios:0,and:0},logged:{ios:1,and:10},login:{ios:1,and:10},select:{ios:0,and:0},pay:{alipay:{ios:1,and:10},weipay:{ios:3,and:19}},show:{ios:0,and:0},dismiss:{ios:0,and:0},getLocation:{ios:1,and:0}},j=arguments.callee;j.NET_URL=s,j.TOUCHLIFE_URL=o,j.pageBack=st,j.getToken=it,j.getSecret=ut,j.collectScenarioParams=tt,j.andApiLevel=n,j.isIOS=P,j.shareToWechat=nt,j.shareToMoment=rt,j.loadFile=z,j.getItemFromStorage=vt,z("style",s+"/res/css/lib/ctk_ui.css"),z("script",s+"/res/js/lib/ctk_ui.js");try{$}catch(F){try{window.$=Zepto}catch(I){try{window.$=jQuery}catch(q){z("script",s+"/res/js/lib/zepto.v2.js")}}}P?function(t){e.WebViewJavascriptBridge?t(WebViewJavascriptBridge):document.addEventListener("WebViewJavascriptBridgeReady",function(){t(WebViewJavascriptBridge)},!1)}(function(t){t._messageHandler||t.init(function(e,t){}),console.log=function(e){WebViewJavascriptBridge.callHandler("log",e,function(e){})},e.onerror=function(e,t,n){return console.log("sMsg: "+e+"; sUrl: "+t+"; sLine: "+n),!1};try{document.readyState=="complete"&&R()}catch(n){console.log("------------- init ctk error")}console.log("------------- init callback"),e.CTK=e.CTK||{dispatchEvent:function(){console.log("------------- init dispatchEvent");var e=this;r=window.WebViewJavascriptBridge,i=e.ApiLevel,j.iosApiLevel=i,console.log(r),console.log(i),i>=3&&(history.back=st),i>=1&&navigator.geolocation&&(navigator.geolocation.getCurrentPosition=gt),u.forEach(function(e){typeof e=="function"&&e()}),showTarget(j)}};var s=setInterval(function(){window.WebViewJavascriptBridge&&(r?clearInterval(s):(r=window.WebViewJavascriptBridge,i=CTK.ApiLevel,i>=3&&(history.back=st),i>=1&&navigator.geolocation&&(navigator.geolocation.getCurrentPosition=gt),u.forEach(function(e){typeof e=="function"&&e()}),j.iosApiLevel=i,showTarget(j)))},100)}):(n>0&&(history.back=st),n>=20&&t.setOpenOrCloseXinGePush(!0),showTarget(j)),window.addEventListener("message",function(e){if(e.origin==s&&e.data.type=="tradeStr"){var t=e.data.tradeStr;D=e.data.payType,t?typeof p=="function"&&p({tradeStr:e.data.tradeStr}):typeof d=="function"&&d({})}else if(e.origin==s&&e.data.type=="getDefaultAddress"){var n={name:e.data.name,phone:e.data.phone,province:e.data.province,city:e.data.city,country:e.data.country,addr:e.data.addr,contact_id:e.data.contact_id};typeof N=="function"&&setTimeout(function(){var t=e.data.action;t?t=="del"&&(n.action="del",N(n)):(e.data.noBack||window.location.hash=="#address"&&(K(L,!1),st()),N(n))},200)}else e.origin==s&&e.data.type=="log"&&console.log(e.data.log)});var bt={shareCallback:function(e){console.log("share"+e)},queryCallback:function(e,t){console.log("params is "+e+" reference "+t)}},wt={loginCallBack:function(e){if(e){var t=ot();typeof c=="function"&&c({accessToken:Z()})}else typeof h=="function"&&h({})},iosLoginCallBack:function(e){var t=this;CTK.AuthToken=e.token,CTK.Secret=e.secret,CTK.LoginNumber=e.loginnumber;switch(e.isLogged){case"true":CTK.Logged=!0;break;case"false":CTK.Logged=!1}t.loginCallBack(CTK.Logged)},payCallBack:function(e){console.log("-------------- "+e);var o,u=!1;if(D==a)o=e.slice(14,18)*1;else if(D==f||D==l)o=e+"";switch(o){case 9e3:case"0":o=4102,u=!0;break;case 8e3:o=4105;break;case 6001:case"-2":o=4107;break;case 6002:case"-1":o=4108;break;default:o=4106}G(o),console.log("-------------- "+o),webShare=!1;if(u){var c={scene_limit:"AFTER_TRADE",service:g,transaction_id:localStorage.getItem("transaction_id")};console.log(c),console.log("---------------------- "+i);if(P&&i>=7){var h={params:JSON.stringify(c)};r.callHandler("tryShareWithParams",h,null)}else!P&&n>=29?t.tryShare(JSON.stringify(c),"ShareCallbacks.shareCallback"):(console.log("no native share"),webShare=!0)}setTimeout(function(){window.location.hash=="#cashier"&&st(),setTimeout(function(){v(o)},300),webShare&&(z("style",s+"/res/css/lib/ctk_ui.css"),z("script",s+"/res/js/lib/ctk_ui.js"),j.ctk=Et,Et.ready(function(){setTimeout(function(){getShare(j,g)},500)}))},100)},alipayHandler:function(e){console.log("------------- ret : "+JSON.stringify(e));var t=this,n="resultStatus={"+e.resultStatus+"};memo={"+e.memo+"};result={"+e.result+"}";t.payCallBack(n)},weipayHandler:function(e){var t=this;t.payCallBack(e)},locateCallback:function(e){vt("native_param_location",!0),vt("native_param_city",!0),vt("native_param_addr",!0),vt("native_param_locate_cache_time",!0),vt("native_param_city_cache_time",!0),vt("native_param_addr_cache_time",!0)},setPayType:function(e){D=e},getPayType:function(){return D}},Et={ready:function(e){P&&!r?u.push(e):typeof e=="function"&&e()},logged:function(e){var i;!P&&n>=10?i=t.isLogged():P&&r?i=!!CTK.LoginNumber:i=!1,i?e.yes({accessToken:Z()}):e.no({})},login:function(e){c=e.success,h=e.fail;if(!P&&n>=10)t.login("获取验证码",e.phone||"","CTKCallBackFuncs.loginCallBack");else if(P&&r){var i={title:"获取验证码",phone:e.phone||"",callback:"CTKCallBackFuncs.iosLoginCallBack"};r.callHandler("login",JSON.stringify(i),function(e){console.log(e)})}},select:function(e){p=e.success,d=e.fail,m=(e.totalFee/100).toFixed(2),g=e.tradeService,y=e.products||[],window.isIframeLoadCompleted?V(e.inapp):window.loadQueue=function(){V(e.inapp)},tt(173,"payment_popup_show")},selectCootek:function(e){p=e.success,d=e.fail,m=(e.totalFee/100).toFixed(2),g=e.tradeService,y=e.products||[],et()},pay:function(e){console.log("---------- pay start"),console.log(JSON.stringify(e));var t=JSON.parse(H.decode(e.payStr));console.log("---------- pay data: "+H.decode(e.payStr)),v=e.finish;if(t.paymentType==a)console.log("---------- alipay"),ct(t.paymentData);else if(t.paymentType==f||t.paymentType==l)console.log("---------- weipay"),ht(t.paymentData);localStorage.setItem("transaction_id",t.transactionId)},show:function(){function t(){e<360?e+=15:e=15,S.style.webkitTransform="rotate("+e+"deg)"}!E&&Y();var e=0;x.innerHTML=D=="alipay"?"正在跳转支付宝支付":"正在跳转微信支付",T=setInterval(t,20),document.body.appendChild(E)},dismiss:function(){if(!T)return;clearInterval(T),T=null,document.body.removeChild(E)},checkJsApi:function(e){var t={},r=!1;e.jsApiList.forEach(function(e,s){e in B?e=="pay"?(r=!0,t.pay={alipay:P&&i>=B.pay.alipay.ios||!P&&n>=B.pay.alipay.and,weipay:P&&i>=B.pay.weipay.ios||!P&&n>=B.pay.weipay.and}):t[e]=P&&i>=B[e].ios||!P&&n>=B[e].and:console.log("txm: api name error! error name: "+e)}),typeof e.success=="function"?e.success({errMsg:r?"check success!":"no correct api name!",result:t}):console.log("success callback type error!")},getLocation:function(e){function i(){cacheTime=vt("native_param_locate_cache_time");if(cacheTime!=t){var i=vt("native_param_location");i=i?JSON.parse(i):{},clearInterval(n),typeof e.success=="function"&&e.success({city:vt("native_param_city")||"",address:vt("native_param_addr")||"",latitude:i[0]||"",longitude:i[1]||""})}r++,r>100&&(clearInterval(n),typeof e.success=="function"&&e.success({city:"",address:"",latitude:"",longitude:""}))}var t=vt("native_param_locate_cache_time");pt();var n=setInterval(i,100),r=0},config:function(e,t,n,r,i,s,o,u){g=t;for(var a=0;a<o.length;++a){var f=o[a];f=="getDefaultAddress"&&X()}},getDefaultAddress:function(e){function t(t){typeof e.success=="function"?(e.success(t),window.location.hash=="#address"&&st()):alert("未知错误,没有接收地址的函数")}if(e.showAddressPage)window.location.hash="#address",CTAW.show(e.curContactId,t);else{var n=at("default_addr"),r=vt(n);if(r&&r.length>5){var i=JSON.parse(r);e.success(i)}else e.success(null)}},processAjaxError:function(e,t,n){var r=this;r.dismiss(),t=="timeout"?window.alert("服务器超时,请稍后再试!"):t=="abort"?(window.alert("请求出现错误,请检查您的网络!"),window.cashierLink.contentWindow.postMessage({status:"active"},"*")):t==500&&window.alert("您访问太过频繁,请稍后再试!"),n=n!==null&&JSON.parse(n);switch(n.result_code){case 4002:alert("本地时间错误,请求失败,请校准时间后再试!")}}};return document.readyState=="complete"?W():e.addEventListener("load",W,!1),n>1&&navigator.geolocation&&(navigator.geolocation.getCurrentPosition=gt),e.CTKCallBackFuncs=wt,e.ShareCallbacks=bt,e.ctk=Et});
|