// var uid = localStorage.getItem('uid'); // var token = localStorage.getItem('token'); const openId = localStorage.getItem('openId'); /*线上全局配置变量*/ const config = { baseUrl: '/wxkf', //本项目域名 projectUrl: "/sims-api", // projectUrl: "/ysy1", wxscanUrl: "/wxscaninvoice", //销项基础服务 simsBaseUrl: "/sims-api", //接口域名以及项目名称 interfaceUrl: "/ele-myinvoice", //发票列表票夹 myinvoiceUrl: "/my-invoice", //微信服务地址 wxservicePath: "http://wdfp.5ifapiao.com/wxservice", wxserviceTestPath: '/wxservice', //发票名片接口地址 invoiceCardUrl: "/myinvoice-invoice-card", //账号相关接口地址 accountUrl: "/myinvoice-account", //企业logo获取地址 logoUrl: "/myinvoice-data" }; // /*测试全局配置变量*/ // var config = { // baseUrl: 'http://sims.ele-cloud.com.com', // //本项目域名 // projectUrl: "http://test.5ifapiao.com:8888/order-api", // // projectUrl:"https://sims.ele-cloud.com.com/wxscaninvoice", // // // wxscanUrl: "http://test.5ifapiao.com:8888/wxscaninvoice", // // //接口域名以及项目名称 // // interfaceUrl: "https://sims.ele-cloud.com.com/ele-myinvoice", // interfaceUrl: "http://test.5ifapiao.com:8888/ele-myinvoice", // // //发票列表票夹 // // myinvoiceUrl:"http://sims.ele-cloud.com.com/my-invoice-lyang", // myinvoiceUrl: "http://sims.ele-cloud.com.com/my-invoice", // // //微信服务地址 // // wxservicePath: "https://wdfp.5ifapiao.com/wxservice", // wxservicePath: "http://wdfp.5ifapiao.com/wxservice", // // //发票名片接口地址 // // invoiceCardUrl: "https://sims.ele-cloud.com.com/myinvoice-invoice-card", // invoiceCardUrl: "http://test.5ifapiao.com:8888/myinvoice-invoice-card", // // //账号相关接口地址 // // accountUrl: "https://sims.ele-cloud.com.com/myinvoice-account", // accountUrl: "http://test.5ifapiao.com:8888/myinvoice-account", // // //企业logo获取地址 // // logoUrl: "https://sims.ele-cloud.com.com/myinvoice-data" // logoUrl: "http://test.5ifapiao.com:8888/myinvoice-data" // // // }; //请求头类型 function getProtocol() { return window.location.protocol + "//"; } //域名:端口 function getHost() { return window.location.host; //localhost:8080 } //跳转页面 function toPage(page) { window.location.href = getPreUrl() + page; } function getPreUrl() { return getProtocol() + getHost() + '/' + getProjectName(); } function getProjectName() { const relativePath = location.pathname; const tmp = relativePath.split("/"); if (tmp[1].length === 0) { return tmp[2]; } else { return tmp[1]; } } function updateUrlParam(num) { const params = new URLSearchParams(location.search.slice(1)); params.set('type', ''); window.history.replaceState({}, '', `${location.pathname}?${params + location.hash}`); } //获取url参数的value getUrlArgumentValue(参数名称) function getUrlArgumentValue(name) { const hash = window.location.hash; if (hash !== "" && name === 'code') { //路径中有锚点 不能直接获取到 参数 if (hash.indexOf('&') > 0) { return hash.split('&')[1].split('=')[1]; } else { return hash.split('?')[1].split('=')[1]; } } if (hash !== "" && name === 'path') { return window.location.search.substr(6).split("?")[0] + hash.split('&')[0]; } const reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); const r = window.location.search.substr(1).match(reg); if (r != null) { return unescape(r[2]) + hash; } else { return null; } } //获取url参数列表 数组 function getUrlArgumentArr() { let name, value; let str = location.href; //取得整个地址栏 let num = str.indexOf("?"); str = str.substr(num + 1); //取得所有参数 stringvar.substr(start [, length ] const arr = str.split("&"); //各个参数放到数组里 for (let i = 0; i < arr.length; i++) { num = arr[i].indexOf("="); if (num > 0) { name = arr[i].substring(0, num); value = arr[i].substr(num + 1); this[name] = value; } } return arr; } //获取微信code 重定向返回当前页面 重定向回来后 有code 通过code获取openid 和 token function getOpenidOrToken() { const pathCode = encodeURIComponent(window.location.href); if (pathCode.indexOf("%26code%3D") < 0 || pathCode.indexOf("%3fcode%3D") < 0) { window.location.href = config.wxservicePath + '/api/toGetUserInfo?type=1&path=' + pathCode; } //basejs中获取地址参数值 const code = getUrlArgumentValue("code"); //掉后台接口 通过code获取oppentId-->token if (code != null && code !== '') { $.ajax({ type: 'POST', data: { "code": code }, dataType: 'JSON', url: config.accountUrl + '/account/wx/getOpenId', async: false, header: { 'content-type': 'application/x-www-form-urlencoded' }, // 设置请求的 header success: function (data) { info = data.data; localStorage.setItem('openId', info.user); localStorage.setItem("token", info.token); } }) } } function getUnionIdAndOpenId() { const pathCode = encodeURIComponent(window.location.href); if (pathCode.indexOf("%26code%3D") < 0 || pathCode.indexOf("%3fcode%3D") < 0) { window.location.href = config.wxservicePath + '/api/toGetUserInfo?type=1&path=' + pathCode; } //basejs中获取地址参数值 const code = getUrlArgumentValue("code"); if (code != null && code !== '') { $.ajax({ type: "get", url: config.accountUrl + '/account/wx/getOpenId?code=' + code, async: false, success: function (data) { return data; } }); } } //获取code并获取用户信息 function getUserInfoCode(appid) { let code = ""; const pathCode = encodeURIComponent(window.location.href); if (pathCode.indexOf("%26code%3D") >= 0 || pathCode.indexOf("%3fcode%3D") >= 0) { code = getUrlArgumentValue("code"); } else { if (appid == null) { window.location.href = config.wxservicePath + '/api/toGetUserInfo?type=1&path=' + pathCode; } else { window.location.href = config.wxservicePath + '/api/toGetUserInfo?type=1&path=' + pathCode + "&appid=" + appid; } } //获取用户信息 if (code != null && code !== '') { $.ajax({ type: "post", url: config.wxserviceTestPath + "/api/getUserInfo", data: JSON.stringify({ "code": code, "type": "1", "gzh_appid": appid }), contentType: "application/json;charset=utf-8", dataType: "json", async: false, success: function (data) { }, complete: function (xml) { const responseText = JSON.parse(xml.responseText); if (xml.status === 200) { const subscribe = responseText.subscribe; const openId = responseText.openid; const unionId = responseText.unionid; window.localStorage.setItem('openId', openId); window.localStorage.setItem('subscribe', subscribe); window.localStorage.setItem('unionId', unionId); //登陆成功调jsp列表 // pathCode1 = decodeURIComponent(pathCode); // pathCode = getUrlArgumentValue("path"); // if (pathCode != null) { // window.location.replace(pathCode); // } else { // window.location.replace(pathCode1); // } } else { alert_timing_open(getCodeInfo(responseText.code)); } }, error: function (XMLHttpRequest, textStatus, errorThrown) { alert_loading_close(); alert_timing_open('登录失败请重新登录'); }, }) } } //弹框 title:标题, description:描述, type:1显示确认 2显示确认取消 function alert_prompt_open(title, description, type) { const body = document.getElementsByTagName('body')[0]; const sub = (type === "1" ? '