-
Notifications
You must be signed in to change notification settings - Fork 0
/
unvs-h5-sdk.min.js
1 lines (1 loc) · 10.4 KB
/
unvs-h5-sdk.min.js
1
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.UNVS_H5_SDK=e():t.UNVS_H5_SDK=e()}(self,(function(){return(()=>{"use strict";var t={d:(e,n)=>{for(var o in n)t.o(n,o)&&!t.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:n[o]})}};t.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(t){if("object"==typeof window)return window}}(),t.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),t.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var e={};t.r(e),t.d(e,{LibInfo:()=>s,PhoneNumberAuth:()=>O,PhoneNumberLogin:()=>C});const n="1.0.0";function o(t,e){var n={"M+":t.getMonth()+1,"d+":t.getDate(),"h+":t.getHours(),"m+":t.getMinutes(),"s+":t.getSeconds(),"q+":Math.floor((t.getMonth()+3)/3),"S+":t.getMilliseconds()};for(var o in/(y+)/.test(e)&&(e=e.replace(RegExp.$1,(t.getFullYear()+"").substr(4-RegExp.$1.length))),n)new RegExp("("+o+")").test(e)&&(e=e.replace(RegExp.$1,1==RegExp.$1.length?n[o]:((3==RegExp.$1.length&&"S+"==o?"000":"00")+n[o]).substr((""+n[o]).length)));return e}var r,i,a,s=function(){function t(){}return t.isWifi=function(){return function(){var t=window.navigator;if(t.userAgent.toLowerCase().indexOf("wifi")>-1)return!0;var e=t.connection||t.mozConnection||t.webkitConnection;return"wifi"===(e&&e.type)}()},t.osIsPc=function(){return function(){for(var t=navigator.userAgent,e=["Android","iPhone","SymbianOS","Windows Phone","iPod","iPad"],n=!0,o=0;o<e.length;o++)if(t.indexOf(e[o])>0){n=!1;break}return n}()},t.randomString=function(t){return function(t){void 0===t&&(t=32);for(var e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",n=e.length,o="",r=0;r<t;r++)o+=e.charAt(Math.floor(Math.random()*n));return o}(t)},t.version=n,t}();!function(t){t.StandardPage="0",t.StandardPopup="1",t.CustomPopup="2",t.CustomPage="3"}(r||(r={})),function(t){t[t.Android=1]="Android",t[t.IOS=2]="IOS",t[t.H5=3]="H5"}(i||(i={})),function(t){t.development="development",t.production="production"}(a||(a={}));var p={version:"2.0",appId:"",sign:"",traceId:"",timestamp:"",openType:"1",authPageType:r.StandardPage,businessType:8},u={version:"1.0",appId:"",sign:"",businessType:1,traceId:"",timestamp:"",openType:1,expandParams:""},c={RetCode:2e4,Message:"Get APP Info Error"},f={RetCode:20001,Message:"Sdk must be instantiated"};const l={loginPhoneUrl:"https://www.cmpassport.com/h5/js/jssdk_auth/jssdk-1.0.0.min.js",authPhoneUrl:"https://www.cmpassport.com/NumberAbility/jssdkVlm_yw/jssdk_v1.0.0.min.js",baseUrl:"https://api.nvs.ucloud.cn"};var h=function(t,e){var n=document.createElement("script"),o=e||function(){};n.type="text/javascript",n.readyState?n.onreadystatechange=function(){"loaded"!=n.readyState&&"complete"!=n.readyState||(n.onreadystatechange=null,o())}:n.onload=function(){o()},n.src=t,document.getElementsByTagName("head")[0].appendChild(n)},d=function(){return d=Object.assign||function(t){for(var e,n=1,o=arguments.length;n<o;n++)for(var r in e=arguments[n])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t},d.apply(this,arguments)};function y(t,e){return function(t,e){var n=d({"Content-Type":"application/json;charset=UTF-8"},e),o=t.method,r=t.baseUrl,i=t.data;return new Promise((function(t,e){var a=window.XMLHttpRequest?new XMLHttpRequest:new ActiveXObject("Microsoft.XMLHTTP");if(a.onerror=e,a.onreadystatechange=function(){if(4===a.readyState)if(a.status>=200&&a.status<400){var n=/application\/json/.test(a.getResponseHeader("content-type"))?JSON.parse(a.responseText):a.responseText;t(n)}else e(new Error("POST to "+r+" failed with status: "+a.status))},a.open(o,r),n&&Object.keys(n).length)for(var s=0,p=Object.entries(n);s<p.length;s++){var u=p[s],c=u[0],f=u[1];a.setRequestHeader(c,f)}a.send(JSON.stringify(i))}))}({baseUrl:"".concat(null==l?void 0:l.baseUrl,"?Action=").concat(t.Action),method:"POST",data:t},e)}var g,m=function(t){return y(d({Action:"GetAppInfo"},t))},v=function(t,e,n,o){return new(n||(n=Promise))((function(r,i){function a(t){try{p(o.next(t))}catch(t){i(t)}}function s(t){try{p(o.throw(t))}catch(t){i(t)}}function p(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,s)}p((o=o.apply(t,e||[])).next())}))},b=function(t,e){var n,o,r,i,a={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,o&&(r=2&i[0]?o.return:i[0]?o.throw||((r=o.return)&&r.call(o),0):o.next)&&!(r=r.call(o,i[1])).done)return r;switch(o=0,r&&(i=[2&i[0],r.value]),i[0]){case 0:case 1:r=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,o=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!(r=a.trys,(r=r.length>0&&r[r.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!r||i[1]>r[0]&&i[1]<r[3])){a.label=i[1];break}if(6===i[0]&&a.label<r[1]){a.label=r[1],r=i;break}if(r&&a.label<r[2]){a.label=r[2],a.ops.push(i);break}r[2]&&a.ops.pop(),a.trys.pop();continue}i=e.call(t,a)}catch(t){i=[6,t],o=0}finally{n=r=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,s])}}},P=function(){function t(t){this._UCloudAppInfo={ApplicationId:"",PackageName:""},this._AppInfo={AppId:"",AppKey:""},this._UCloudAppInfo=t,this.cacheAppInfo(t)}return t.prototype.GetTimestamp=function(){return(new Date).getTime()},t.prototype.getAppInfo=function(t){return v(this,void 0,void 0,(function(){var e,n,o,r,a;return b(this,(function(s){switch(s.label){case 0:return e=this.GetTimestamp(),n=t.ApplicationId,o=t.PackageName,n&&o?(r=CryptoJS.MD5(n+o+i.H5+e).toString(),a={Platform:i.H5,ApplicationId:n,PackageName:o,Sign:r,Timestamp:e},[4,m(a)]):[2,Promise.resolve(f)];case 1:return[2,s.sent()]}}))}))},t.prototype.cacheAppInfo=function(t){var e=this;this.getAppInfo(t).then((function(t){0===t.RetCode&&t.Data&&(e._AppInfo=t.Data)})).catch((function(){return c}))},t}(),w=(g=function(t,e){return g=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},g(t,e)},function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=t}g(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}),I=function(){return I=Object.assign||function(t){for(var e,n=1,o=arguments.length;n<o;n++)for(var r in e=arguments[n])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t},I.apply(this,arguments)},A=l.loginPhoneUrl,C=function(e){function n(t){var n=e.call(this,t)||this;return n._RequestParams=p,n.InitGlobalConfig(),n.init(),n}return w(n,e),n.prototype.getGlobal=function(){if("undefined"!=typeof self)return self;if("undefined"!=typeof window)return window;if(void 0!==t.g)return t.g;throw new Error("unable to locate global object")},n.prototype.InitGlobalConfig=function(){this.getGlobal().CryptoJS=CryptoJS},n.prototype.init=function(){var t=this;h(A,(function(){t.PhoneLogin=YDRZAuthLogin}))},n.prototype.GetTokenParams=function(t,e,n,r,i){var a=o(new Date,"yyyyMMddhhmmssSSS"),s=r,u=p.businessType,c=p.version,f=CryptoJS.MD5(t+u+s+a+r+c+e).toString(),l=I(I({},p),{appId:t,sign:f,timestamp:a,authPageType:n,traceId:r,expandParams:i});return this._RequestParams=l,l},n.prototype.customControlsInit=function(t){this.PhoneLogin.CustomControlsInit("ydrzCustomControls",t)},n.prototype.authPageInit=function(t){this.PhoneLogin.authPageInit(t)},n.prototype.authGetTokenByLayer=function(t,e){this.PhoneLogin.authGetTokenByLayer(t,e)},n.prototype.getConnection=function(){var t=this,e=this._AppInfo,n=e.AppId,o=e.AppKey;return n&&o?this.PhoneLogin.getConnection(n):this.getAppInfo(this._UCloudAppInfo).then((function(e){var n=e.RetCode,o=e.Data;return 0===n&&o?t.PhoneLogin.getConnection(o.AppId):e})).catch((function(){return c}))},n.prototype.endGetToken=function(){return this.PhoneLogin.endGetToken()},n.prototype.getTokenInfo=function(t){var e=this,n=t.traceId,o=void 0===n?"":n,i=t.authPageType,a=void 0===i?r.StandardPage:i,s=t.expandParams,p=t.success,u=t.error,f=t.layerCallback,l=this._AppInfo,h=l.AppId,d=l.AppKey;h&&d?this.PhoneLogin.getTokenInfo({data:this.GetTokenParams(h,d,a,o,s),success:p,error:u,layerCallback:f}):this.getAppInfo(this._UCloudAppInfo).then((function(t){var n=t.RetCode,r=t.Data;0===n&&r?e.PhoneLogin.getTokenInfo({data:e.GetTokenParams(r.AppId,r.AppKey,a,o,s),success:p,error:u,layerCallback:f}):u(t)})).catch((function(){u(c)}))},n}(P),S=function(){var t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},t(e,n)};return function(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function o(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(o.prototype=n.prototype,new o)}}(),T=function(){return T=Object.assign||function(t){for(var e,n=1,o=arguments.length;n<o;n++)for(var r in e=arguments[n])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t},T.apply(this,arguments)},_=l.authPhoneUrl,O=function(t){function e(e){var n=t.call(this,e)||this;return n._RequestParams={},n.Init(),n}return S(e,t),e.prototype.Init=function(){var t=this;h(_,(function(){t.PhoneAuthCMCC=YDRZ}))},e.prototype.GetTokenParams=function(t,e,n,r){var i=o(new Date,"yyyyMMddhhmmssSSS"),a=n,s=u.businessType,p=u.version,c=CryptoJS.MD5(t+s+a+i+n+p+e).toString(),f=T(T({},u),{appId:t,sign:c,timestamp:i,traceId:n,expandParams:r});return this._RequestParams=f,f},e.prototype.getConnection=function(t){return this.PhoneAuthCMCC.getConnection(t)},e.prototype.getTokenInfo=function(t){var e=this,n=t.traceId,o=void 0===n?"":n,r=t.expandParams,i=t.success,a=t.error,s=this._AppInfo,p=s.AppId,u=s.AppKey;p&&u?this.PhoneAuthCMCC.getTokenInfo({data:this.GetTokenParams(p,u,o,r),success:i,error:a}):this.getAppInfo(this._UCloudAppInfo).then((function(t){var n=t.RetCode,s=t.Data;0===n&&s?e.PhoneAuthCMCC.getTokenInfo({data:e.GetTokenParams(s.AppId,s.AppKey,o,r),success:i,error:a}):a(t)})).catch((function(){a(c)}))},e}(P);return e})()}));