UNPKG

yizun-sdk

Version:

易尊前端SDK - 用于集成前端埋点追踪的JavaScript库

197 lines (169 loc) 7.05 kB
var _pagecode = {}; var PhoneCodeUtil = {}; (function() { try{ //声明pagecode-agent.js文件位置 var agentUrl = "./pagecode-agent.js";//本次测试位置 var agentUrl = "https://static.ejcop.com/static_file/yizun-jssdk/assets/strategies/shanxi/pagecode-agent.js";//渠道生产环境位置 var s2=document.getElementsByTagName("script")[0]; var s5=document.createElement("script"); s5.async=true; s5.src=agentUrl; s2.parentNode.insertBefore(s5,s2); //此处可以声明要推送插码数据的接口 // var apiUrl = "http://localhost:8080/chama/pushData";//本地测试接口 var apiUrl = "https://sn.ac.10086.cn/ecmp/openable/provider/inlineCode/add";//线上生产接口 //appId统一默认格式: 公司简称小写首字母 + "wbhzpt" 例如:冰蓝 blwbhzpt var appId = "yzwbhzpt"; //token使用以下默认值 var appToken = "jnAtApp82F1657022572187"; _pagecode = { /* appId: appId, appToken: appToken,*/ apiUrl: apiUrl, init: function (option) { if (window._vops) { window._vops.init(option); } else { console.log(" _vops not exit or is not a function."); } }, /** * ?????????? */ reportData: function (){ if (window._vops) { window._vops.reportData(); } else { console.log(" _vops not exit or is not a function."); } }, push: function (option) { if (window._vops) { window._vops.push(option); } else { console.log(" _vops not exit or is not a function."); } }, pushSyn: function (option) { if (window._vops) { window._vops.pushSyn(option); } else { console.log(" _vops not exit or is not a function."); } }, } PhoneCodeUtil = { // 验证手机号码是否合法 isMobile(mobile) { if (mobile && mobile.length >= 11) { if (mobile.length > 11) { mobile = mobile.substring(mobile.length - 11); } return pattern.test(mobile); } return false; }, // 加密手机号码 encodeMobile(mobile) { try { if (this.isMobile(mobile)) { if (mobile.length > 11) { mobile = mobile.substring(mobile.length - 11); } const fregList = []; const builder = []; builder.push(mobile.substring(0, 2)); builder.push(this.randomNumber()); builder.push(this.randomNumber()); fregList.push(builder.join('')); builder.length = 0; builder.push(mobile.substring(2, 5)); builder.push(this.randomNumber()); fregList.push(builder.join('')); builder.length = 0; builder.push(this.randomNumber()); builder.push(mobile.substring(5, 8)); fregList.push(builder.join('')); builder.length = 0; builder.push(this.randomNumber()); builder.push(mobile.substring(8, 11)); fregList.push(builder.join('')); builder.length = 0; for (let i = 0; i < fregList.length; ++i) { builder.push(parseInt(fregList[i], 16) ^ parseInt(this.genKey(), 16)); if (i !== fregList.length - 1) { builder.push('-'); } } return builder.join(''); } else { return mobile; } } catch (e) { return mobile; } }, // 解密手机号码 decodeMobile(encryptMobile) { if (!encryptMobile) { return ''; } const frags = encryptMobile.split('-'); const builder = []; try { let str4; if (frags.length > 0) { str4 = (parseInt(frags[0]) ^ parseInt(this.genKey(), 16)).toString(16); str4 = this.preFixZero(str4); builder.push(str4.substring(0, 2)); } if (frags.length > 1) { str4 = (parseInt(frags[1]) ^ parseInt(this.genKey(), 16)).toString(16); str4 = this.preFixZero(str4); builder.push(str4.substring(0, 3)); } if (frags.length > 2) { str4 = (parseInt(frags[2]) ^ parseInt(this.genKey(), 16)).toString(16); str4 = this.preFixZero(str4); builder.push(str4.substring(1)); } if (frags.length > 3) { str4 = (parseInt(frags[3]) ^ parseInt(this.genKey(), 16)).toString(16); str4 = this.preFixZero(str4); builder.push(str4.substring(1)); } } catch (e) { return null; } return builder.join(''); }, // 生成随机十六进制数 randomNumber() { const numbers = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f']; const randomKey = Math.floor(Math.random() * 16); return numbers[randomKey]; }, // 生成随机十进制数 randomNumber10() { const numbers = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']; const randomKey = Math.floor(Math.random() * 10); return numbers[randomKey]; }, // 补零操作 preFixZero(str) { str = '000' + str; return str.substring(str.length - 4); }, // 生成密钥 genKey() { return '1abc'; } } // document.write(unescape("%3Cspan id='vops_stat_icon_1254131450'%3E%3C/span%3E%3Cscript src='" // +agentUrl+"' type='text/javascript' crossorigin%3E%3C/script%3E")); } catch (e) { console.log(e) } })();