// import * as compnt from "./compnt.js"; var unicom = window.unicom = { query: {}, product: {}, fesname: {}, user: {}, root: null, init: function () { root = this.getRootPath(); this.parseQueryParms(); $("#useraccount_tt").attr("value", getUrlParam("freeflow_token")); var param = { "fes": this.query.fes, "sou": this.query.sou } var that = this; //return new Promise(function (resolve, reject) { var def = $.Deferred(); $.post(this.root + "-s1api" + "/ini/getstyle", JSON.stringify(param)).then(function (responseText) { var response = JSON.parse(responseText); if (response.resultCode != "0000") { //window.location.href = "/404.html"; def.reject(); return; } that.product = response.product[0]; $("#fog_" + that.product.url).attr("value", that.product.fog); var smslist = that.product.icon.split(","); for (var i = 0; i < smslist.length; i++) { if (i == 0) { $("#sendsms_order_" + that.product.url).attr("value", smslist[i]); } if (i == 1) { $("#sendsms_cancel_" + that.product.url).attr("value", smslist[i]); } if (i == 2) { $("#sendsms_yuyue_" + that.product.url).attr("value", smslist[i]); } } def.resolve(response); }) return def; //}) }, /** * 抖音产品订购 */ orderDouyin: function (token, usermob) { var param = { "fog": getMemoValbyId(this.product.url, "fog"), "usermob": usermob, "useraccount": getMemoValbyId(this.product.url, "useraccount"), "fes": this.getUrlParam("fes"), "sou": this.getUrlParam("sou"), "token": token } return $.post(this.root + "-s1api" + '/com/buyc', JSON.stringify(param)); }, /** * 获取项目根目录 * @returns */ getRootPath: function () { //获取当前网址,如: http://localhost:8080/ems/Pages/Basic/Person.jsp var curWwwPath = window.document.location.href; //获取主机地址之后的目录,如: /ems/Pages/Basic/Person.jsp var pathName = window.document.location.pathname; var pos = curWwwPath.indexOf(pathName); //获取主机地址,如: http://localhost:8080 var localhostPath = curWwwPath.substring(0, pos); //获取带"/"的项目名,如:/ems var projectName = pathName.substring(0, pathName.substr(1).indexOf('/') + 1); this.root = (localhostPath + projectName); return (localhostPath + projectName); }, parseQueryParms: function () { var QUERY_SEPARATOR = '&', VALUE_SEPARATOR = '='; var queryStr = window.location.search.substring(1); var startIndex = 0, vIndex, qIndex; while (queryStr.length > 0) { vIndex = queryStr.indexOf(VALUE_SEPARATOR, startIndex); if (vIndex == -1) { break; } qIndex = queryStr.indexOf(QUERY_SEPARATOR, vIndex + 1); if (qIndex == -1) { qIndex = queryStr.length; } var key = queryStr.substring(startIndex, vIndex); var value = queryStr.substring(vIndex + 1, qIndex); this.query[key] = decodeURIComponent(value); startIndex = qIndex + 1; } }, /** * 获取当前url中参数信息 * @param urlprm url中参数名称 * @returns */ getUrlParam: function (urlprm) { var reg = new RegExp("(^|&)" + urlprm + "=([^&]*)(&|$)"); var r = window.location.search.substr(1).match(reg); if (r != null) { return r[2]; } else { switch (urlprm) { case "con": return "1"; case "freeflow_token": return ""; default: var url = this.getRootPath() + "/404.html"; $(location).attr('href', url); } } }, burypointLogId: function (operid, remark, url) { var uuid = this.getCookie('uuid'); if (uuid == null || uuid.trim() == '') { uuid = this.guid(); this.setCookie('uuid', uuid, 1000 * 60 * 60 * 24); } var param = { operid: operid, uuid: uuid, fog: this.product.fog, userid: this.user.userid, fes: this.query.fes, sou: this.query.sou, url: encodeURIComponent(url || window.location.href), remark: encodeURIComponent(remark || '') } $.post(this.root + "-s1api" + "/burypoint/logid", JSON.stringify(param)).then(function() {}) }, /** * SliderCaptcha */ verifyCaptcha: function (arr) { var that = this; $.post(this.root + "-s1api" + "/sliderCaptcha/verify", JSON.stringify(arr)).then(function (responseText) { var response = JSON.parse(responseText); if (response.resultCode == "0000") { that.product.captchaCode = response.captchaCode; return true; } else { compnt.showAlert(response.errorInfo); return false; } }) }, loadUserInfo: function (duration) { if (this.query.userid) { this.user.userid = this.query.userid; this.user.usermob = this.query.usermob; return; } try { var time = localStorage.getItem('time'); if (time) { var curr = new Date().getTime(); if (curr <= parseFloat(time) + duration || (1000 * 60 * 60)) { var userString = localStorage.getItem("user"); var _user = JSON.parse(userString); this.user.userid = _user.userid; this.user.usermob = _user.usermob; if (_user.usermob == "18674842761") { setTimeout(function(){ alert(time + duration || (1000 * 60 * 60)) }, 100); } } else { localStorage.removeItem("time") localStorage.removeItem("user") } } } catch (e) { } }, saveUserInfo: function (duration) { localStorage.setItem('user', JSON.stringify(this.user)); localStorage.setItem('time', duration || ((new Date().getTime()) + "")); }, generClientSecret: function (fog) { // console.log(product) var param = { "fog": this.product.fog || fog || "", "channel": "" } return $.post(this.root + "-s1api" + "/ini/gensign", JSON.stringify(param)); }, /** * 查询微信支付结果 */ queryWxPay: function (tradeno, tradedate, userid) { var param = { "fes": this.query.fes, "sou": this.query.sou, "fog": this.product.fog, "tradeno": tradeno, "userid": userid || this.user.userid, "tradedate": tradedate, //例子:20190115 } var def = $.Deferred(); if (isEmpty(param.userid)) { /*return new Promise((resolve, reject) => { reject("参数错误"); });*/ def.reject('参数错误') return def; } if (isEmpty(param.tradeno)) { /*return new Promise((resolve, reject) => { reject("参数错误"); });*/ def.reject('参数错误') return def; } return $.post(this.root + "-s1api" + '/backward/stackpkgquerypay', JSON.stringify(param)); }, /** * 订购 */ order: function (userid, token, usermob) { var param = { "fes": this.query.fes, "sou": this.query.sou, "fog": this.product.fog, "token": token, "userid": userid || this.user.userid, "usermob": usermob || this.user.usermob, "useraccount": "" } if (this.query.F) { param.f = this.query.F } // console.log("订购参数:" + param) return $.post(this.root + "-s1api" + '/comm/order', JSON.stringify(param)); }, /** * 退订 */ cancel: function (userid, usermob) { var param = { "fes": this.query.fes, "sou": this.query.sou, "fog": this.product.fog, "userid": userid || this.user.userid, "usermob": usermob || this.user.usermob, "useraccount": "" } return $.post(this.root + "-s1api" + '/comm/cancel', JSON.stringify(param)); }, /** * 查询流量消耗 */ queryFlow: function (userid, usermob) { var param = { "fes": this.query.fes, "sou": this.query.sou, "fog": this.product.fog, "userid": userid || this.user.userid, "usermob": usermob || this.user.usermob, } return $.post(this.root + "-s1api" + '/flow/query', JSON.stringify(param)); }, /** * 查询订购关系 */ queryOrder: function (userid, usermob) { var param = { "fes": this.query.fes, "sou": this.query.sou, "fog": this.product.fog, "userid": userid || this.user.userid, "usermob": usermob || this.user.usermob } return $.post(this.root + "-s1api" + '/comm/queryorder', JSON.stringify(param)); }, queryStock: function (stockcode) { var param = { "fes": this.query.fes, "sou": this.query.sou, "fog": this.product.fog, "stockcode": stockcode } return $.post(this.root + "-s1api" + '/backward/queryStock', JSON.stringify(param)); }, /** * 后向产品订购 */ orderBack: function (stockcode) { var param = { "fes": this.query.fes, "sou": this.query.sou, "fog": this.product.fog, "userid": this.user.userid } if (!!stockcode && stockcode != '') { param.stockcode = stockcode; } return $.post(this.root + "-s1api" + '/backward/order', JSON.stringify(param)); }, /** * 后向产品退款 */ refund: function (stockcode, username, password) { var param = { "fes": this.query.fes, "sou": this.query.sou, "fog": this.product.fog, "stockcode": stockcode, "captchaCode": this.product.captchaCode, "username": username, "password": password } // console.log(param) return $.post(this.root + "-s1api" + '/backward/refund', JSON.stringify(param)); }, /** * 检查用户是否可以订购 */ can: function (uid) { if (!uid) { var def = $.Deferred(); def.reject(); //return new Promise(function (resolve, reject) { // reject() //}) return def; } var param = { "fes": this.query.fes, "sou": this.query.sou, "fog": this.product.fog, "uid": uid || "" } return $.post(this.root + "-s1api" + '/member/can', JSON.stringify(param)); }, /* * 领取会员 */ drawMember: function (uid, screen_name, userid, usermob) { if (uid == null || uid.trim() == "") { compnt.showAlert('获取微博账号信息失败') return; } var param = { "fes": this.query.fes, "sou": this.query.sou, "fog": this.product.fog, "userid": userid || this.user.userid, "usermob": usermob || this.user.usermob, "uid": uid, "screen_name": screen_name || "" } return $.post(this.root + "-s1api" + '/member/draw', JSON.stringify(param)); }, /** * 查询会员领取状态 */ queryMember: function (userid, usermob, uid) { var param = { "fes": this.query.fes, "sou": this.query.sou, "fog": this.product.fog, "userid": userid || this.user.userid, "usermob": usermob || this.user.usermob, "uid": uid || '' } if (isEmpty(param.userid) && isEmpty(param.uid)) { /*return new Promise((resolve, reject) => { reject("参数错误"); });*/ var def = $.Deferred(); def.reject('参数错误') return def; } // alert(JSON.stringify(param)) return $.post(this.root + "-s1api" + '/member/query', JSON.stringify(param)); }, /** * 发送短信验证码 * @param {}} $container */ sendSms: function ($container, smstype) { if ($container.attr('n') != null && $container.attr('n') > 0) { return; } var usermob = $container.find('.usermob').val(); if (usermob == null || usermob.trim() == "") { compnt.showAlert('手机号码不能为空~'); return; } if (!usermob.startsWith("1") || usermob.length != 11) { compnt.showAlert('手机号码格式不正确~'); return; } var param = { "fes": this.query.fes, "sou": this.query.sou, "fog": this.product.fog, "usermob": usermob, "smstype": smstype } this.user.usermob = usermob var count = 60; $container.attr('n', count); $.post(this.root + "-s1api" + '/sms/send', param).then(function (responseText) { var response = JSON.parse(responseText); if (response.resultCode != "0000") { count = 0; $container.attr('n', count); compnt.showAlert(response.errorInfo); return; } var $sendcode = $container.find('.sendcode') var template = '重新发送({}s)' $sendcode.text(template.replace('{}', count)); $sendcode.addClass('sendcode-wait'); var timer = setInterval(function () { count -= 1; $container.attr('n', count); $sendcode.text(template.replace('{}', count)); if (count === 0) { clearInterval(timer); $sendcode.text('获取验证码'); $container.attr('n', count); $sendcode.removeClass('sendcode-wait'); } }, 1000); }) }, /** * 检验短信验证码,并且返回手机号伪代码,有效期10分钟 * @param {*} usermob * @param {*} smscode */ checkCode: function ($container) { var def = $.Deferred(); //return new Promise(function (resolve, reject) { var usermob = $container.find('.usermob').val(); var smscode = $container.find('.smscode').val(); if (usermob == null || usermob.trim() == "") { compnt.showAlert('短信验证码不能为空~'); def.reject() return; } if (smscode.length != 6) { compnt.showAlert('短信验证码不正确~'); def.reject() return; } var param = { "fes": this.query.fes, "sou": this.query.sou, "fog": this.product.fog, "code": smscode, "usermob": usermob, } var that = this; $.post(this.root + "-s1api" + '/checkvercode', param).then(function (responseText) { var response = JSON.parse(responseText); switch (response.resultCode) { case "0000": that.user.userid = response.userid; that.user.usermob = usermob; that.user.usertime = new Date().getTime(); def.resolve(response.userid); break; default: compnt.showAlert(response.errorInfo) def.reject(response); break; } }).fail(function (error) { def.reject('服务调用异常') }) return def; //}) }, /** * 打开统一认证的页面 */ showCapPage: function (fog, productName) { //var $iframe = $(''); var capUrl = "http://800.wo.cn/cap/CAP-AUTH.html"; var baseUrl = "http://800.wo.cn/"; if (window.location.href.indexOf("https") >= 0) { capUrl = "https://800.wo.cn/cap/CAP-AUTH.html"; baseUrl = "https://800.wo.cn/"; } var $iframe = $(''); $iframe.css({ width: "100%", height: "100%", position: "fixed", top: 0, left: 0, margin: 0, padding: 0, "-webkit-overflow-scrolling": "touch", border: "0px", }) var that = this $iframe.on('load', function () { that.generClientSecret(fog).then(function (response) { // var response = JSON.parse(responseText); // console.log(response) response.orderChannel = that.query.fes + "_" + that.query.sou; if (productName != null && productName != '') { response.productName = productName; } $iframe[0].contentWindow.postMessage(JSON.stringify(response), baseUrl) }) }) if (navigator.userAgent.indexOf("MicroMessenger") >= 0) { //微信6.7.4及以后版本 ios12软键盘顶起页面后隐藏不回弹解决方案 //打开嵌入的统一认证取号页面前,让原来的页面上下滚动。 //统一认证的页面关闭以后,删除定时任务 clearInterval(window.capTimer) var currentPosition; var speed = 1; // 页面滚动距离 window.capTimer = setInterval(function () { currentPosition = document.documentElement.scrollTop || document.body.scrollTop; currentPosition -= speed; window.top.scrollTo(0, currentPosition);//页面向上滚动 currentPosition += speed; //speed变量 window.top.scrollTo(0, currentPosition);//页面向下滚动 }, 200); } $('body').append($iframe); //return new Promise(function (resolve, reject) { var def = $.Deferred(); window.addEventListener('message', function (event) { var data = JSON.parse(event.data); switch (data.resultcode) { case "0": //处理成功 $iframe.remove(); $("body").css("overflow", "auto"); clearInterval(window.capTimer) that.user.token = data.token; that.user.userid = decodeURIComponent(data.userid); that.user.userid1 = data.userid1; that.user.usermob = data.usermob; that.user.usertime = new Date().getTime(); def.resolve(that.user); break; case "9001"://关闭H5认证页面 $iframe.remove(); clearInterval(window.capTimer) $("body").css("overflow", "auto"); def.reject(data) break; case "0001"://auth_no无效 case "0003"://client_id不存在 case "0006"://验证码不正确 case "4444"://服务暂时不可用(系统忙/系统队列满) break; default: $iframe.remove(); $("body").css("overflow", "auto"); clearInterval(window.capTimer) compnt.showAlert(data.errorinfo) def.reject(data) break; } }) return def; //}); }, getCookie: function (name) { var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)"); if (arr = document.cookie.match(reg)) return unescape(arr[2]); else return null; }, setCookie: function(name, value, millis) { millis = (millis == undefined ? 0 : millis); var exp = new Date(); exp.setTime(exp.getTime() + millis); document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString(); }, guid: function () { return 'xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx'.replace(/[xy]/g, function (c) { var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8); return v.toString(16); }); }, getNowFormatDate: function (sperator) { if (sperator == null) { sperator = '' } var date = new Date(); var year = date.getFullYear(); var month = date.getMonth() + 1; var strDate = date.getDate(); if (month >= 1 && month <= 9) { month = "0" + month; } if (strDate >= 0 && strDate <= 9) { strDate = "0" + strDate; } var currentdate = year + sperator + month + sperator + strDate; return currentdate; }, setProduct: function (_product) { this.product = _product; }, setFesname: function (_fesname) { this.fesname = _fesname; }, isEmpty: function (str) { if (str == null || str == '') { return true; } return false; }, }