123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716 |
- // 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 = $('<iframe id="uniauthframe" src="http://127.0.0.1:8090/cap/CAP-AUTH.html"></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 id="uniauthframe" src="' + capUrl + '"></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;
- },
- }
|