index.js 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220
  1. var douyinProductId = "2018072301";
  2. var douyinPreProductId = "2020031101";
  3. var baiduProductId = "2020021201";
  4. var baiduPreProductId = "2020071301";
  5. var query = {};
  6. var product = {};
  7. var products = {};
  8. var fesname = {};
  9. var user = {};
  10. var root = null;
  11. var productsr = {};
  12. $(function() {
  13. var isPageHide = false;
  14. window.addEventListener('pageshow', function() {
  15. if (isPageHide) {
  16. window.location.reload();
  17. }
  18. });
  19. window.addEventListener('pagehide', function() {
  20. isPageHide = true;
  21. });
  22. if (window.location.href.indexOf('draw.html') >= 0) {
  23. var user = JSON.parse(localStorage.getItem('user'));
  24. if (user != null) {
  25. $('.usermob').val(user.usermob);
  26. }
  27. }
  28. })
  29. init();
  30. function init() {
  31. var message = localStorage.getItem('message');
  32. if (message != null && message != '') {
  33. showDialogMessage(message);
  34. localStorage.removeItem('message');
  35. }
  36. showLoading();
  37. inits().then(function(response) {
  38. hideLoading();
  39. product = douyinProductId;
  40. fesname = response.festival;
  41. loadUserInfo();
  42. if (location.href.indexOf("index.html") >= 0) {
  43. showOrderPage();
  44. } else {
  45. openPage();
  46. }
  47. if (location.href.indexOf('/cancel') >= 0) {
  48. burypointLogIds('110002');
  49. } else if (location.href.indexOf('/draw') >= 0) {
  50. burypointLogId('110003');
  51. } else if (location.href.indexOf('/flow') >= 0) {
  52. burypointLogId('110004');
  53. } else if (location.href.indexOf('/active') >= 0) {
  54. burypointLogId('110005');
  55. } else if (location.href.indexOf('/refund') >= 0) {
  56. burypointLogId('110006');
  57. } else {
  58. burypointLogId('110001'); // pv去重得到uv
  59. }
  60. })
  61. // WoAnalytics.addPoint({ ad: $('#nanyanad').val(), ett: 'open', ea: 'order_open' + $('#nanyanlabel').val(), ct: 'web', pm: parseInt(unicom.query.sou, 32) })
  62. }
  63. var $douyinItem = $($('.products').find('.item')[0]);
  64. var $baiduItem = $($('.products').find('.item')[1]);
  65. $douyinItem.unbind('click').on('click', function(e) {
  66. $douyinItem.addClass('active');
  67. $baiduItem.removeClass('active');
  68. product = douyinProductId;
  69. })
  70. $baiduItem.unbind('click').on('click', function() {
  71. $douyinItem.removeClass('active');
  72. $baiduItem.addClass('active');
  73. product = baiduProductId;
  74. })
  75. function inits() {
  76. getRootPath();
  77. parseQueryParms();
  78. $("#useraccount_tt").attr("value", getUrlParam("freeflow_token"));
  79. var param = {
  80. "fes": query.fes,
  81. "sou": query.sou,
  82. "orderId": query.orderId,
  83. }
  84. var def = $.Deferred();
  85. $.ajax({
  86. url: root + "-s1api" + "/ini/getstyle",
  87. type: "POST",
  88. contentType: "application/json",
  89. data: JSON.stringify(param),
  90. timeout: 10000
  91. })
  92. .then(function(responseText) {
  93. var response = JSON.parse(responseText);
  94. if (response.resultCode != "0000") {
  95. def.reject();
  96. return def;
  97. }
  98. product = response.product[0];
  99. var abt = ''
  100. for (i = 0; i < response.product.length; i++) {
  101. products[response.product[i].productid] = response.product[i]
  102. abt += response.product[i].fog + ','
  103. }
  104. if ($douyinItem.hasClass('active')) {
  105. productsr = douyinProductId;
  106. } else {
  107. productsr = baiduProductId;
  108. }
  109. if (productsr == 2018072301) {
  110. window.localStorage.setItem('kye', abt)
  111. }
  112. $("#fog_" + product.url).attr("value", product.fog);
  113. var smslist = product.icon.split(",");
  114. for (var i = 0; i < smslist.length; i++) {
  115. if (i == 0) {
  116. $("#sendsms_order_" + product.url).attr("value", smslist[i]);
  117. }
  118. if (i == 1) {
  119. $("#sendsms_cancel_" + product.url).attr("value", smslist[i]);
  120. }
  121. if (i == 2) {
  122. $("#sendsms_yuyue_" + product.url).attr("value", smslist[i]);
  123. }
  124. }
  125. def.resolve(response);
  126. }, function(jqXHR, textStatus, errorThrown) {
  127. if (textStatus === "timeout") {
  128. window.location.href = getRootPath() + "/hot.html?cb=" + encodeURIComponent(window.location.href);
  129. }
  130. })
  131. return def;
  132. }
  133. $('.more .text').unbind('click').on('click', function() {
  134. showDialogAgr()
  135. })
  136. function showDialogAgr() {
  137. var $overlay = $('<div class="overlay"></div>')
  138. var $dialog = $(
  139. '<div class="dialog-agr">' +
  140. ' <div class="head">' +
  141. ' <div class="title"></div>' +
  142. ' <div class="close"></div>' +
  143. ' </div>' +
  144. ' <ul>' +
  145. ' <li>1)此产品包含9元10G今日头条定向流量包、9元8GB百度定向流量包两款服务,任选一款产品订购、使用业务以本机实际使用号码为准。资费9元/月,按自然月收费,下月自动续订;退订次月生效,当月仍享受免流权益,次月不再享受免流服务;</li>' +
  146. ' <li>2)本产品立即预约,次月生效,预约成功后将退订当前订购的产品;例如:如果用户当月订购的是今日头条定向流量包,点击预约变更,预约成功后,退订当前的头条包,次月生效百度包,且头条包免流可使用到月底,反之一样;</li>' +
  147. ' <li>3)预约成功后,当月不能再次预约变更产品,且不支持取消已预约的产品;</li>' +
  148. ' <li>4)本产品支持3G/4G用户使用,但4G套餐中的共享类套餐不共享该月包,需单独预约订购,给您带来的不便敬请谅解;</li>' +
  149. ' <li>5)建议使用最新版本今日头条、百度系列手机客户端,如果您更换其他系统手机或使用较低版本客户端,请谨慎使用您的流量;</li>' +
  150. ' <li>6)今日头条定向流量包的免流范围包括:抖音APP、今日头条、西瓜视频、火山小视频、多闪、懂车帝、图虫、皮皮虾APP;</li>' +
  151. ' <li>百度定向流量包产品的免流范围包括:百度后视镜、百度 APP 、好看视频、 全民小视频、 百度贴吧、 百度地图、百度网盘(会员);</li>' +
  152. ' <li>7)订购今日头条包的用户,如您为头条相关免流卡用户,如蚂蚁宝卡、阿里宝卡、钉钉宝卡或工商银行e卡等其他免头条系产品卡类,将优先使用免流卡产品的流量,免流卡流量用罄后将消耗今日头条定向流量包的流量;</li>' +
  153. ' <li>8)订购成功后,请在对应视频客户端内登录使用,联通3G/4G网络下观看,免流内容不包含第三方提供的广告、视频、图片及直播类视频上传/下载/缓存第三方视频所产生的流量;</li>' +
  154. ' <li>9)请务必使用3GNET接入点访问本产品,使用其他接入点观看视频会照常收取流量费用。请不要安装和使用任何流量监控、上网代理及VPN类软件和插件,可能会引起免流量策略失效而产生高额流量费用;</li>' +
  155. ' <li>10)以下地区暂不支持产品订购及免流业务:港、澳、台及国际漫游;</li>' +
  156. ' <li>11)如果遇到困难,请拨打10010联系联通客服解决。</li>' +
  157. ' </ul>' +
  158. '</div>');
  159. $overlay.appendTo($(document.body))
  160. $dialog.appendTo($(document.body))
  161. $dialog.find('.btn').on('click', function() {
  162. $overlay.remove();
  163. $dialog.remove();
  164. $dialog = null;
  165. })
  166. $dialog.find('.close').on('click', function() {
  167. $overlay.remove();
  168. $dialog.remove();
  169. $dialog = null;
  170. })
  171. $dialog.close = function() {
  172. $overlay.remove();
  173. $dialog.remove();
  174. $dialog = null;
  175. }
  176. return $dialog;
  177. }
  178. $('#gotoCancel').unbind('click').on('click', function() {
  179. if ($douyinItem.hasClass('active')) {
  180. product = douyinProductId;
  181. } else {
  182. product = baiduProductId;
  183. }
  184. showCancelPage(product);
  185. })
  186. function showCancelPage(productid) {
  187. if (location.href.indexOf("cancel.html") < 0) {
  188. window.location.href = "cancel.html?fes=" + query.fes + "&sou=" + query.sou + "&productid=" + productid;
  189. return;
  190. }
  191. product = products[query.productid]
  192. var $container = $('.sms-form').find('.form-group');
  193. $container.find('.sendcode').unbind('click').on('click', function() {
  194. sendSms($container, 'cancellogin');
  195. })
  196. $container.find('.login').unbind('click').on('click', function() {
  197. showLoading();
  198. checkCode($container).done(function() {
  199. choiceCancel().done(function(response) {
  200. hideLoading();
  201. switch (response.resultCode) {
  202. case "0000":
  203. showDialogMessage('退订成功');
  204. break;
  205. case "7605": //应该是已经退订了吧,因此不需要在重复退订啦
  206. showDialogMessage(response.errorInfo);
  207. break;
  208. default:
  209. var prefix = '';
  210. if (response.errorInfo.indexOf('退订失败') < 0) {
  211. prefix = '退订失败,';
  212. }
  213. showDialogMessage(prefix + response.errorInfo);
  214. break;
  215. }
  216. }).fail(function(data) {
  217. hideLoading();
  218. })
  219. }).fail(function(data) {
  220. hideLoading();
  221. })
  222. })
  223. window.scrollTo(0, 0)
  224. }
  225. function unlockClick(element) {
  226. $(element || document.body).data('use', '0');
  227. }
  228. function lockClick(element) {
  229. if ($(element || document.body).data('use') == '1') {
  230. return false;
  231. }
  232. $(element || document.body).data('use', '1');
  233. return true;
  234. }
  235. var historyBackExecuted = true;
  236. function showCapPage(fog, productName, scrollable, hasNetNumber, decryptUsermob, capTemplet) {
  237. historyBackExecuted = false;
  238. if (!scrollable) {
  239. $("body").css("overflow", "hidden");
  240. }
  241. var capUrl;
  242. var baseUrl;
  243. if (window.location.href.indexOf("https://800.wo.cn/orderchannel") >= 0) {
  244. capUrl = "https://800.wo.cn/cap/CAP-AUTH.html";
  245. baseUrl = "https://800.wo.cn/";
  246. } else if (window.location.href.indexOf("https://800.wo.cn/festivalchannel") >= 0) {
  247. capUrl = "https://800.wo.cn/festivalcap/CAP-AUTH.html";
  248. baseUrl = "https://800.wo.cn/";
  249. } else if (window.location.href.indexOf("http://localhost") >= 0) {
  250. capUrl = "http://localhost:8088/cap/CAP-AUTH.html";
  251. baseUrl = "http://localhost:8088/";
  252. } else if (window.location.href.indexOf("http://127.0.0.1") >= 0) {
  253. capUrl = "http://127.0.0.1:8088/cap/CAP-AUTH.html";
  254. baseUrl = "http://127.0.0.1:8088/";
  255. } else if (window.location.href.indexOf("http://100.0.4.69:3344") >= 0) {
  256. capUrl = "http://100.0.4.69:3344/cap/CAP-AUTH.html";
  257. baseUrl = "http://100.0.4.69:3344/";
  258. } else if (window.location.href.indexOf("http://100.0.4.69:8282") >= 0) {
  259. capUrl = "http://100.0.4.69:8282/cap/CAP-AUTH.html";
  260. baseUrl = "http://100.0.4.69:8282/";
  261. } else {
  262. capUrl = "https://800.wo.cn/festivalcap/CAP-AUTH.html";
  263. baseUrl = "https://800.wo.cn/";
  264. }
  265. if ($("#nanyanad").val() != null) {
  266. capUrl += '?ad=' + $("#nanyanad").val()
  267. }
  268. var $iframe;
  269. if ($('#uniauthframe').length >= 1) {
  270. $iframe = $('#uniauthframe').attr('src', capUrl);
  271. } else {
  272. $iframe = $('<iframe id="uniauthframe" src="' + capUrl + '"></iframe>');
  273. }
  274. $iframe.css({
  275. width: "100%",
  276. height: "100%",
  277. position: "fixed",
  278. top: 0,
  279. left: 0,
  280. margin: 0,
  281. padding: 0,
  282. "-webkit-overflow-scrolling": "touch",
  283. border: "0px",
  284. })
  285. showLoading();
  286. $iframe.on('load', function() {
  287. $capoverlay.remove();
  288. generClientSecret(fog).then(function(response) {
  289. hideLoading();
  290. response.orderChannel = query.fes + "_" + query.sou;
  291. if (productName != null && productName != '') {
  292. response.productName = productName;
  293. }
  294. if (capTemplet != null && capTemplet != '') {
  295. response.capTemplet = capTemplet
  296. }
  297. try {
  298. } catch (e) {
  299. }
  300. try {
  301. $iframe[0].contentWindow.postMessage(JSON.stringify(response), baseUrl)
  302. } catch (e) {}
  303. })
  304. })
  305. if (navigator.userAgent.indexOf("MicroMessenger") >= 0) {
  306. var currentPosition;
  307. var speed = 1;
  308. window.capTimer = setInterval(function() {
  309. currentPosition = document.documentElement.scrollTop || document.body.scrollTop;
  310. currentPosition -= speed;
  311. window.top.scrollTo(0, currentPosition);
  312. currentPosition += speed;
  313. window.top.scrollTo(0, currentPosition);
  314. }, 200);
  315. }
  316. window.$capoverlay = $('<div class="overlay" style="z-index: 0"></div>');
  317. $capoverlay.appendTo($(document.body));
  318. if ($('#uniauthframe').length == 0) {
  319. $('body').append($iframe);
  320. } else {
  321. $iframe.css('position', 'unset')
  322. .css('min-height', '10rem')
  323. }
  324. var def = $.Deferred();
  325. function messageListener(event) {
  326. var data = JSON.parse(event.data);
  327. switch (data.resultcode) {
  328. case "0": //处理成功
  329. $iframe.remove();
  330. $capoverlay.remove();
  331. window.removeEventListener('message', messageListener);
  332. $("body").css("overflow", "auto");
  333. clearInterval(window.capTimer)
  334. user.token = data.token;
  335. user.userid = decodeURIComponent(data.userid);
  336. user.userid1 = data.userid1;
  337. user.usermob = data.usermob;
  338. user.usertime = new Date().getTime();
  339. var poc = window.localStorage.getItem('kye').split(',')
  340. if (!!decryptUsermob && fog == poc[1] || fog == poc[0]) {
  341. decodeUsermob()
  342. } else if (!!decryptUsermob && fog == poc[2] || fog == poc[3]) {
  343. decodeUsermoob(null, fog)
  344. }
  345. def.resolve(user);
  346. break;
  347. case "9001": //关闭页面
  348. $iframe.remove();
  349. $capoverlay.remove();
  350. window.removeEventListener('message', messageListener);
  351. clearInterval(window.capTimer);
  352. $("body").css("overflow", "auto");
  353. def.reject(data);
  354. if (hasNetNumber != null && !!hasNetNumber && !historyBackExecuted) {
  355. if (query.test == '1') {
  356. alert(navigator.userAgent);
  357. }
  358. //火狐浏览器
  359. if (isChromeKernelBrowser()) {
  360. historyBackExecuted = true;
  361. history.back();
  362. }
  363. }
  364. break;
  365. case "0001": //auth_no无效
  366. case "0003": //client_id不存在
  367. case "0006": //验证码不正确
  368. case "4444": //服务暂时不可用(系统忙/系统队列满)
  369. break;
  370. case "99999": // 埋点信号
  371. if (data.operid) {
  372. burypointLogId(data.operid);
  373. }
  374. if (data.ea) {
  375. //埋点的东西吧不注销报错 WoAnalytics不存在
  376. // WoAnalytics.addPoint({ ad: $("#nanyanad").val(), ett: 'open', ea: data.ea + $("#nanyanlabel").val(), ct: 'web', pm: parseInt(getUrlParam("sou"), 32) })
  377. }
  378. try {
  379. window.WoAnalytics && window.WoAnalytics.setMp(data.usermob);
  380. } catch (e) {}
  381. break;
  382. default:
  383. $iframe.remove();
  384. $capoverlay.remove();
  385. window.removeEventListener('message', messageListener);
  386. $("body").css("overflow", "auto");
  387. clearInterval(window.capTimer)
  388. showAlert(data.errorinfo)
  389. def.reject(data)
  390. break;
  391. }
  392. }
  393. window.addEventListener('message', messageListener);
  394. return def;
  395. }
  396. function showLoading(message) {
  397. if (window.$loading) {
  398. window.$loading.trigger('close');
  399. }
  400. $("body").css('overflow', 'hidden');
  401. var msg = (message || '处理中,请稍后...');
  402. var $overlay = $('<div class="overlay overlay-loading"></div>');
  403. var $loading = $(
  404. '<div class="loading">' +
  405. ' <div class="content">' + msg + '</div>' +
  406. '</div>');
  407. $overlay.appendTo($(document.body))
  408. $loading.appendTo($(document.body))
  409. $loading.on('close', function() {
  410. $("body").css('overflow', 'auto');
  411. $overlay.remove();
  412. $loading.remove();
  413. $loading = null;
  414. })
  415. window.$loading = $loading;
  416. return $loading;
  417. }
  418. function generClientSecret(fog) {
  419. var pog = window.localStorage.getItem('kye').split(',')
  420. if (product == 2018072301) {
  421. var pog_fog = pog[2]
  422. } else if (product == 2020021201) {
  423. var pog_fog = pog[3]
  424. }
  425. var param = {
  426. "fog": pog_fog || fog || "",
  427. "channel": ""
  428. }
  429. return $.ajax({
  430. url: root + "-s1api" + '/ini/gensign',
  431. type: "POST",
  432. contentType: "application/json",
  433. data: JSON.stringify(param)
  434. })
  435. }!(function() {
  436. Date.remainMillis = function() {
  437. var now = new Date();
  438. return (23 - now.getHours()) * 60 * 60 * 1000 +
  439. (59 - now.getMinutes()) * 60 * 1000 +
  440. (59 - now.getSeconds()) * 1000;
  441. }
  442. Date.remainMillisMonth = function() {
  443. var curDate = new Date();
  444. var curMonth = curDate.getMonth(); //当前月份 需要加1
  445. curDate.setMonth(curMonth + 1);
  446. curDate.setDate(0) // 关键
  447. curDate.getDate(); // 计算的当月总天数
  448. return curDate.getDate() - new Date().getDate()
  449. }
  450. /**
  451. * 将字符串转换为Date对象
  452. */
  453. Date.from = function(dateString) {
  454. var pattern = /(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/
  455. var str = dateString.replace(/-/g, '/');
  456. str = str.replace(pattern, '$1/$2/$3 $4:$5:$6')
  457. return new Date(str)
  458. }
  459. Date.prototype.format = function(fmt) {
  460. var o = {
  461. "M+": this.getMonth() + 1,
  462. "d+": this.getDate(),
  463. "h+": this.getHours(),
  464. "m+": this.getMinutes(),
  465. "s+": this.getSeconds(),
  466. "q+": Math.floor((this.getMonth() + 3) / 3),
  467. "S": this.getMilliseconds()
  468. };
  469. if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
  470. for (var k in o)
  471. if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
  472. return fmt;
  473. }
  474. })();
  475. function burypointLogId(operid, remark, url, productid) {
  476. var uuid = getCookie('uuid'); // uv
  477. var vvid = getCookie('vvid'); // vv
  478. if (uuid == null || uuid.trim() == '') {
  479. uuid = guid();
  480. setCookie('uuid', uuid, Date.remainMillis());
  481. }
  482. if (vvid == null || vvid.trim() == '') {
  483. vvid = guid();
  484. setCookie('vvid', vvid, -1);
  485. }
  486. if (operid == null || operid == '') {
  487. // 页面的埋点通过通过文件日志入库方式
  488. return;
  489. }
  490. var pog = window.localStorage.getItem('kye').split(',')
  491. if (product == 2018072301) {
  492. var pog_fog = pog[0]
  493. } else if (product == 2020021201) {
  494. var pog_fog = pog[1]
  495. }
  496. var param = {
  497. operid: operid,
  498. uuid: uuid,
  499. vvid: vvid,
  500. fog: pog_fog,
  501. userid: user.userid,
  502. fes: query.fes,
  503. sou: query.sou,
  504. url: encodeURIComponent(url || window.location.href),
  505. remark: encodeURIComponent(remark || '')
  506. }
  507. $.ajax({
  508. url: root + "-s1api" + '/burypoint/logid',
  509. type: "POST",
  510. contentType: "application/json",
  511. data: JSON.stringify(param)
  512. }).then(function(responseText) {
  513. })
  514. }
  515. function burypointLogIds(operid, remark, url, productid) {
  516. var uuid = getCookie('uuid'); // uv
  517. var vvid = getCookie('vvid'); // vv
  518. if (uuid == null || uuid.trim() == '') {
  519. uuid = guid();
  520. setCookie('uuid', uuid, Date.remainMillis());
  521. }
  522. if (vvid == null || vvid.trim() == '') {
  523. vvid = guid();
  524. setCookie('vvid', vvid, -1);
  525. }
  526. if (operid == null || operid == '') {
  527. // 页面的埋点通过通过文件日志入库方式
  528. return;
  529. }
  530. var param = {
  531. operid: operid,
  532. uuid: uuid,
  533. vvid: vvid,
  534. fog: product.fog,
  535. userid: user.userid,
  536. fes: query.fes,
  537. sou: query.sou,
  538. url: encodeURIComponent(url || window.location.href),
  539. remark: encodeURIComponent(remark || '')
  540. }
  541. $.ajax({
  542. url: root + "-s1api" + '/burypoint/logid',
  543. type: "POST",
  544. contentType: "application/json",
  545. data: JSON.stringify(param)
  546. }).then(function(responseText) {
  547. })
  548. }
  549. function getRootPath() {
  550. //获取当前网址,如: http://localhost:8080/ems/Pages/Basic/Person.jsp
  551. var curWwwPath = window.document.location.href;
  552. //获取主机地址之后的目录,如: /ems/Pages/Basic/Person.jsp
  553. var pathName = window.document.location.pathname;
  554. var pos = curWwwPath.indexOf(pathName);
  555. //获取主机地址,如: http://localhost:8080
  556. var localhostPath = curWwwPath.substring(0, pos);
  557. //获取带"/"的项目名,如:/ems
  558. var projectName = pathName.substring(0, pathName.substr(1).indexOf('/') + 1);
  559. root = (localhostPath + projectName);
  560. return (localhostPath + projectName);
  561. }
  562. function parseQueryParms() {
  563. var QUERY_SEPARATOR = '&',
  564. VALUE_SEPARATOR = '=';
  565. var queryStr = window.location.search.substring(1);
  566. var startIndex = 0,
  567. vIndex, qIndex;
  568. while (queryStr.length > 0) {
  569. vIndex = queryStr.indexOf(VALUE_SEPARATOR, startIndex);
  570. if (vIndex == -1) {
  571. break;
  572. }
  573. qIndex = queryStr.indexOf(QUERY_SEPARATOR, vIndex + 1);
  574. if (qIndex == -1) {
  575. qIndex = queryStr.length;
  576. }
  577. var key = queryStr.substring(startIndex, vIndex);
  578. var value = queryStr.substring(vIndex + 1, qIndex);
  579. query[key] = decodeURIComponent(value);
  580. startIndex = qIndex + 1;
  581. }
  582. }
  583. function getUrlParam(urlprm) {
  584. if (window.location.href.indexOf('jiangtao') >= 0) {
  585. alert(window.location.href);
  586. }
  587. var reg = new RegExp("(^|&)" + urlprm + "=([^&]*)(&|$)");
  588. var r = window.location.search.substr(1).match(reg);
  589. if (r != null) {
  590. return r[2];
  591. } else {
  592. switch (urlprm) {
  593. case "con":
  594. return "1";
  595. case "freeflow_token":
  596. return "";
  597. default:
  598. var url = getRootPath() + "/404.html";
  599. $(location).attr('href', url);
  600. }
  601. }
  602. }
  603. function hideLoading($loading) {
  604. if ($loading) {
  605. $loading.trigger('close');
  606. return;
  607. } else if (window.$loading) {
  608. window.$loading.trigger('close');
  609. return;
  610. }
  611. }
  612. function loadUserInfo(duration) {
  613. if (query.userid) {
  614. user.userid = query.userid;
  615. user.usermob = query.usermob;
  616. return;
  617. }
  618. try {
  619. var time = localStorage.getItem('time' + product.productid);
  620. if (time) {
  621. var curr = new Date().getTime();
  622. // 默认有效期是1小时
  623. if (curr <= parseFloat(time) + (duration || (1000 * 60 * 60))) {
  624. var userString = localStorage.getItem("user" + product.productid);
  625. if (userString != null) {
  626. user = JSON.parse(userString);
  627. user.userid = user.userid;
  628. user.usermob = user.usermob;
  629. }
  630. } else {
  631. // 超过1小时删除缓存数据
  632. localStorage.removeItem("time" + product.productid)
  633. localStorage.removeItem("user" + product.productid)
  634. }
  635. return user;
  636. } else {
  637. localStorage.removeItem("time" + product.productid)
  638. localStorage.removeItem("user" + product.productid)
  639. }
  640. } catch (e) {
  641. }
  642. }
  643. function showOrderPage(backPage) {
  644. if (location.href.indexOf('index.html') < 0 && location.href.indexOf('15/20200') < 0) {
  645. if (backPage == null || backPage == '') {
  646. backPage = 'index.html';
  647. }
  648. window.location.href = backPage + "?fes=" + query.fes + "&sou=" + query.sou;
  649. return;
  650. }
  651. $('#btn-order').unbind('click').on('click', function(event) {
  652. if (!lockClick()) {
  653. return;
  654. }
  655. if ($douyinItem.hasClass('active')) {
  656. product = douyinProductId;
  657. } else {
  658. product = baiduProductId;
  659. }
  660. var product_fog = window.localStorage.getItem('kye').split(',')
  661. var fog_a = product_fog
  662. if (product == 2018072301) {
  663. showCapPage(fog_a[0], null, false, false, true, null).then(function(data) {
  664. unlockClick();
  665. order(data.userid, data.token, data.usermob);
  666. WoAnalytics.setMp(data.usermob)
  667. }).fail(function(response) {
  668. unlockClick();
  669. })
  670. } else if (product == 2020021201) {
  671. showCapPage(fog_a[1], null, false, false, true, null).then(function(data) {
  672. unlockClick();
  673. order(data.userid, data.token, data.usermob);
  674. }).fail(function(response) {
  675. unlockClick();
  676. })
  677. }
  678. })
  679. $('.modify').unbind('click').on('click', function(event) {
  680. if (!lockClick()) {
  681. return;
  682. }
  683. if ($douyinItem.hasClass('active')) {
  684. product = douyinPreProductId;
  685. } else {
  686. product = baiduPreProductId;
  687. }
  688. var product_fag = window.localStorage.getItem('kye').split(',')
  689. var fog_b = product_fag
  690. if (product == 2020031101) {
  691. showCapPage(fog_b[2], null, false, false, true, null).then(function(data) {
  692. unlockClick();
  693. order(data.userid, data.token, data.usermob);
  694. }).fail(function(response) {
  695. unlockClick();
  696. })
  697. } else if (product == 2020071301) {
  698. showCapPage(fog_b[3], null, false, false, true, null).then(function(data) {
  699. unlockClick();
  700. order(data.userid, data.token, data.usermob);
  701. }).fail(function(response) {
  702. unlockClick();
  703. })
  704. }
  705. })
  706. }
  707. function getCookie(name) {
  708. var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
  709. if (arr = document.cookie.match(reg))
  710. return unescape(arr[2]);
  711. else
  712. return null;
  713. }
  714. function guid() {
  715. return 'xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
  716. var r = Math.random() * 16 | 0,
  717. v = c == 'x' ? r : (r & 0x3 | 0x8);
  718. return v.toString(16);
  719. });
  720. }
  721. function setCookie(name, value, millis) {
  722. millis = (millis == undefined ? 0 : millis);
  723. var exp = new Date();
  724. if (millis < 0) {
  725. document.cookie = name + "=" + escape(value);
  726. } else {
  727. exp.setTime(exp.getTime() + millis);
  728. document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString();
  729. }
  730. }
  731. function showAlert(message, hideButton, buttonLabel, hideTitle) {
  732. var title = '';
  733. if (hideTitle == undefined || hideTitle == false) {
  734. title = '温馨提示';
  735. }
  736. var $overlay = $('<div class="overlay overlay-alert"></div>');
  737. var $dialog = $(
  738. '<div class="dialog-alert">' +
  739. '<h1>' + title + '</h1>' +
  740. '<div class="content">' + message + '</div>' +
  741. '<div class="actions">' +
  742. ' <div class="btn">' + (buttonLabel == null || buttonLabel == "" ? "关闭" : buttonLabel) + '</div>' +
  743. '</div>' +
  744. '</div>');
  745. $("body").css("overflow", "hidden");
  746. $overlay.appendTo($(document.body));
  747. $dialog.appendTo($(document.body));
  748. if (hideButton == true) {
  749. $dialog.find('.btn').remove();
  750. }
  751. $dialog.close = function() {
  752. $("body").css("overflow", "auto");
  753. $overlay.remove();
  754. $dialog.remove();
  755. $dialog = null;
  756. }
  757. var def = $.Deferred();
  758. $dialog.find('.btn').on('click', function() {
  759. $dialog.close()
  760. def.resolve($dialog);
  761. })
  762. return def;
  763. }
  764. // 验证码
  765. function sendSms($container, smstype, currentProduct) {
  766. var def = $.Deferred();
  767. if ($container.attr('n') != null && $container.attr('n') > 0) {
  768. return;
  769. }
  770. var usermob = $container.find('.usermob').val();
  771. if (usermob == null || usermob.trim() == "") {
  772. showAlert('请输入联通手机号码');
  773. def.reject();
  774. return def;
  775. }
  776. if (!usermob.startsWith("1") || usermob.length != 11) {
  777. showAlert('手机号码格式不正确');
  778. def.reject();
  779. return def;
  780. }
  781. console.log(usermob)
  782. var param = {
  783. "fes": query.fes,
  784. "sou": query.sou,
  785. "fog": product.fog,
  786. "usermob": usermob,
  787. "smstype": smstype
  788. }
  789. user.usermob = usermob
  790. var count = 60;
  791. $container.attr('n', count);
  792. $.ajax({
  793. url: root + "-s1api" + '/sms/send',
  794. type: "POST",
  795. contentType: "application/json",
  796. data: JSON.stringify(param)
  797. }).then(function(response) {
  798. if (response.resultCode != "0000") {
  799. count = 0;
  800. $container.attr('n', count);
  801. showAlert(response.errorInfo);
  802. return;
  803. }
  804. var $sendcode = $container.find('.sendcode')
  805. var template = '{}s'
  806. if ($sendcode.is('input')) {
  807. $sendcode.val(template.replace('{}', count));
  808. } else {
  809. $sendcode.text(template.replace('{}', count));
  810. }
  811. $sendcode.addClass('sendcode-wait');
  812. var timer = setInterval(function() {
  813. count -= 1;
  814. $container.attr('n', count);
  815. if ($sendcode.is('input')) {
  816. $sendcode.val(template.replace('{}', count));
  817. } else {
  818. $sendcode.text(template.replace('{}', count));
  819. }
  820. if (count === 0) {
  821. clearInterval(timer);
  822. if ($sendcode.is('input')) {
  823. $sendcode.val('获取验证码');
  824. } else {
  825. $sendcode.text('获取验证码');
  826. }
  827. $container.attr('n', count);
  828. $sendcode.removeClass('sendcode-wait');
  829. }
  830. }, 1000);
  831. })
  832. try {
  833. window.WoAnalytics && window.WoAnalytics.setMp(usermob);
  834. } catch (e) {}
  835. }
  836. function openPage(pageName) {
  837. if (pageName == null) {
  838. if (location.href.indexOf("index.html") >= 0) pageName = "order";
  839. if (location.href.indexOf("cancel.html") >= 0) pageName = "cancel";
  840. }
  841. switch (pageName) {
  842. case "cancel":
  843. showCancelPage();
  844. break;
  845. default:
  846. showOrderPage();
  847. break;
  848. }
  849. }
  850. function checkCode($container, keepUserInfo) {
  851. var def = $.Deferred();
  852. var usermob = $container.find('.usermob').val();
  853. var smscode = $container.find('.smscode').val();
  854. if (keepUserInfo == null) keepUserInfo = false;
  855. if (usermob == null || usermob.trim() == "") {
  856. showAlert('请输入联通手机号码');
  857. def.reject()
  858. return def;
  859. }
  860. if (smscode == null || smscode.trim() == "") {
  861. showAlert('请输入验证码');
  862. def.reject()
  863. return def;
  864. }
  865. if (smscode.length != 6) {
  866. showAlert('短信验证码不正确');
  867. def.reject()
  868. return def;
  869. }
  870. var param = {
  871. "fes": query.fes,
  872. "sou": query.sou,
  873. "fog": product.fog,
  874. "code": smscode,
  875. "usermob": usermob,
  876. }
  877. $.ajax({
  878. url: root + "-s1api" + '/checkvercode',
  879. type: "POST",
  880. contentType: "application/json",
  881. data: JSON.stringify(param)
  882. }).then(function(response) {
  883. $container.find('.smscode').val('')
  884. switch (response.resultCode) {
  885. case "0000":
  886. user.userid = response.userid;
  887. user.usermob = usermob;
  888. user.usertime = new Date().getTime();
  889. if (!keepUserInfo) {
  890. $container.find('.usermob').val('')
  891. $container.find('.usermob').val('')
  892. }
  893. def.resolve(response.userid);
  894. break;
  895. default:
  896. showAlert(response.errorInfo)
  897. def.reject(response);
  898. break;
  899. }
  900. }).fail(function(error) {
  901. def.reject('服务调用异常')
  902. })
  903. return def;
  904. }
  905. function order(userid, token, usermob) {
  906. showLoading('处理中,请稍后...');
  907. choiceOrder(userid, token, usermob).done(function(response) {
  908. hideLoading();
  909. switch (response.resultCode) {
  910. case "0000": //订购成功!跳转到领取会员页面
  911. saveUserInfo();
  912. showDialogMessage('订购成功');
  913. return;
  914. case "0013":
  915. showDialogMessage('该号码归属省分2/3G暂未开通此产品!');
  916. break;
  917. case "6611":
  918. showDialogMessage('错误代码(6611),订购失败,请重试!');
  919. break;
  920. case "6615":
  921. showDialogMessage('订购失败,请确定用户套餐!');
  922. break;
  923. case "6622": // 用户已订购过此产品!跳转到流量查页面
  924. saveUserInfo('用户已订购过此产品!跳转到流量查页面');
  925. break;
  926. // case "1078": //{"resultCode":"1078","errorInfo":"预约失败,请直接订购此产品!"}
  927. // showDialogMessage('预约变更失败,请先订购本产品!');
  928. // showDialogMessage('预约变更失败,请先订购本产品!');
  929. break;
  930. // case "1077": //{"resultCode":"1077","errorInfo":"订购失败,您已订购过二选一产品,请预约订购!"}
  931. // showDialogMessage('订购失败,您已订购过二选一产品,请预约变更!');
  932. // break;
  933. // case "1079": // {"resultCode":"1079","errorInfo":"预约失败,请先订购百度产品!"}
  934. // showDialogMessage('预约变更失败,与当前生效的专属流量流量相同!');
  935. // break;
  936. default:
  937. showDialogMessage(response.errorInfo);
  938. break;
  939. }
  940. }).fail(function(error) {
  941. hideLoading();
  942. });
  943. }
  944. function choiceOrder(userid, token, usermob) {
  945. var product_fog = window.localStorage.getItem('kye').split(',')
  946. if (product == 2018072301) {
  947. var bat = product_fog[0]
  948. } else if (product == 2020021201) {
  949. var bat = product_fog[1]
  950. } else if (product == 2020031101) {
  951. var bat = product_fog[2]
  952. } else if (product == 2020071301) {
  953. var bat = product_fog[3]
  954. }
  955. var param = {
  956. "fes": query.fes,
  957. "sou": query.sou,
  958. "fog": bat,
  959. "token": token,
  960. "userid": userid || user.userid,
  961. "usermob": usermob || user.usermob,
  962. "useraccount": ""
  963. }
  964. return $.ajax({
  965. url: root + "-s1api" + '/choiceorder/order',
  966. type: "POST",
  967. contentType: "application/json",
  968. data: JSON.stringify(param)
  969. });
  970. }
  971. function saveUserInfo(duration) {
  972. localStorage.setItem('user' + product.productid, JSON.stringify(user));
  973. localStorage.setItem('time' + product.productid, duration || ((new Date().getTime()) + ""));
  974. }
  975. function choiceCancel(userid, usermob, canceltype, cancelmsg) {
  976. var param = {
  977. "fes": query.fes,
  978. "sou": query.sou,
  979. "fog": product.fog,
  980. "userid": userid || user.userid,
  981. "usermob": usermob || user.usermob,
  982. "canceltype": encodeURIComponent(canceltype),
  983. "cancelmsg": encodeURIComponent(cancelmsg),
  984. "useraccount": ""
  985. }
  986. return $.ajax({
  987. url: root + "-s1api" + '/choiceorder/cancel',
  988. type: "POST",
  989. contentType: "application/json",
  990. data: JSON.stringify(param)
  991. });
  992. }
  993. function showDialogMessage(message) {
  994. var replaceString = '';
  995. if (product.productid == baiduPreProductId ||
  996. product.productid == douyinPreProductId) {
  997. message = message.replace('订购失败', '预约变更失败')
  998. .replace('订购成功', '预约变更成功');
  999. }
  1000. var $overlay = $('<div class="overlay"></div>')
  1001. var $dialog = $(
  1002. '<div class="dialog-meesage">' +
  1003. ' <div class="content">' + message + '</div>' +
  1004. ' <div class="actions">' +
  1005. ' <div class="btn"></div>' +
  1006. ' </div>' +
  1007. '</div>');
  1008. $overlay.appendTo($(document.body))
  1009. $dialog.appendTo($(document.body))
  1010. $dialog.find('.btn').on('click', function() {
  1011. $overlay.remove();
  1012. $dialog.remove();
  1013. $dialog = null;
  1014. })
  1015. $dialog.close = function() {
  1016. $overlay.remove();
  1017. $dialog.remove();
  1018. $dialog = null;
  1019. }
  1020. return $dialog;
  1021. }
  1022. // 订购
  1023. function decodeUsermob(userid) {
  1024. var poa = window.localStorage.getItem('kye').split(',')
  1025. if (product == 2018072301) {
  1026. var pog_foa = poa[0]
  1027. } else if (product == 2020021201) {
  1028. var pog_foa = poa[1]
  1029. }
  1030. var param = {
  1031. "fog": pog_foa || fog || "",
  1032. "userid": userid || user.userid
  1033. }
  1034. $.ajax({
  1035. url: root + "-s1api" + '/decodeUserid',
  1036. type: "POST",
  1037. contentType: "application/json",
  1038. data: JSON.stringify(param)
  1039. }).then(function(data) {
  1040. if (data.resultCode == '0') {
  1041. user.usermob = data.usermob;
  1042. }
  1043. });
  1044. }
  1045. //预约变更:
  1046. function decodeUsermoob(userid, aug) {
  1047. var psa = window.localStorage.getItem('kye').split(',')
  1048. if (aug == psa[2]) {
  1049. var pog_foa = psa[2]
  1050. } else if (aug == psa[3]) {
  1051. var pog_foa = psa[3]
  1052. }
  1053. var param = {
  1054. "fog": pog_foa || fog || "",
  1055. "userid": userid || user.userid
  1056. }
  1057. $.ajax({
  1058. url: root + "-s1api" + '/decodeUserid',
  1059. type: "POST",
  1060. contentType: "application/json",
  1061. data: JSON.stringify(param)
  1062. }).then(function(data) {
  1063. if (data.resultCode == '0') {
  1064. user.usermob = data.usermob;
  1065. }
  1066. });
  1067. }