;(function ($) { // 初始化函数 var init = function () { // 通过域名判断环境 $.API_URL = 'https://dlapi.daoqijuyou77.cn/Index.php'; $.RETURN_URL = 'https://dlapi.daoqijuyou77.cn/web2/notify.html'; }; $.extend( { API_URL: '', RETURN_URL: '', // 微信支付成功后的跳转地址 AVATAR_URL: 'https://dlwebv3.tscce.cn/images/noavatar.png', // 没有头像的默认地址 // ts已修改2021 // SID_SCODE_URL: 'https://api.tscce.cn/source/login/login.php', // 获取sid和scode的地址 // WX_INFO_URL: 'https://api.tscce.cn/api/user', // 获取微信用户信息地址 // PAY_URL: 'https://api.tscce.cn/source/pay/pay_1.php', // 微信支付地址 // NOTICE_URL: 'https://api.tscce.cn/source/pay/notify.php?v=', // 支付成功后的异步通知地址 // SHARE_LINK: 'https://api.tscce.cn/api/weixin/wx_share_info', SID_SCODE_URL: 'https://api2.tscce.cn/source/login/login.php', // 获取sid和scode的地址 WX_INFO_URL: 'https://api2.tscce.cn/api/user', // 获取微信用户信息地址 PAY_URL: 'https://api2.tscce.cn/source/pay/pay_1.php', // 微信支付地址 NOTICE_URL: 'https://api2.tscce.cn/source/pay/notify.php?v=', // 支付成功后的异步通知地址 SHARE_LINK: 'https://api2.tscce.cn/api/weixin/wx_share_info', wxInfo: {}, // 微信信息 userInfo: {}, // 用户信息 cache: {}, // 缓存 loadingLayerIndex: null, whichSystem: function () { if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) { return true; } else if (/(Android)/i.test(navigator.userAgent)) { return false; } return false; }, isWeiXin: function () { if(typeof this.cache.isWeiXin !== 'undefined') return this.cache.isWeiXin; var ua = navigator.userAgent.toLowerCase(); if (ua.match(/MicroMessenger/i) == "micromessenger") { this.cache.isWeiXin = true; return true; } this.cache.isWeiXin = false; return false; }, isRightId: function (playerId) { return /^\d{6,11}$/.test(playerId); }, isMobile: function (tel) { return /^1[0-9]{10}$/.test(tel); }, getQueryString: function (name) { var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); var r = window.location.search.substr(1).match(reg); if (r !== null) return r[2]; return null; }, getQueryObj: function () { if(this.cache.querys) return this.cache.querys; var tmp = window.location.search.substr(1).split('&'); var res = {}; for (var i = 0; i < tmp.length; i++) { var arr = tmp[i].split('='); res[arr[0]] = arr[1]; } this.cache.querys = res; return res; }, getPageName: function () { var name = window.location.pathname.split('/').pop(); return name; }, storage: function (name, obj) { try { if (typeof obj !== 'undefined') { var tmp = (typeof obj === 'object') ? JSON.stringify(obj) : obj; sessionStorage.setItem(name, tmp); } else { var res = sessionStorage.getItem(name); res = JSON.parse(res); return res; } } catch (e) { alert("如果此页面无法正常显示,请关闭浏览器的隐身模式,再打开此页面。"); console.log("如果此页面无法正常显示,请关闭浏览器的隐身模式,再打开此页面。", e); } }, convertCanvasToImage: function (canvas) { var image = new Image(); image.src = canvas.toDataURL("image/png"); return image; }, invite: function (name, url) { $("#" + name).qrcode({width: 200, height: 200, text: url}); var canvas = document.getElementById(name).getElementsByTagName('canvas')[0]; canvas = this.convertCanvasToImage(canvas); $("#" + name).html(canvas); }, api: function (methods, params, func, isAsync) { //console.log('params', params) var token = sessionStorage.getItem("token"); var apiDate = { method: methods, format: "json", charset: "utf-8", version: "1.0", user_auth_token: token, biz_content: params }; isAsync = isAsync || false; if (isAsync === 1) $.loading(); var that = this; $.ajax( { url: this.API_URL, type: 'POST', //dataType: 'json', async: !!isAsync, data: apiDate, timeout: 20000, success: function (r) { r = ('string' == typeof r) ? eval("(" + decodeURIComponent(r) + ")") : r; if (!r) throw "服务器端有错误发生,请联系管理员!"; console.log(methods, r); if (r.user_auth_token ) { try { sessionStorage.setItem('token', r.user_auth_token); } catch (e) { alert("如果此页面无法正常显示,请关闭浏览器的隐身模式,再打开此页面。"); } } try { if (r.retcode !== 0) throw {'code': r.retcode, 'info': r.retinfo}; if (r.biz_content.state && parseInt(r.biz_content.state) !== 0) throw {'code': r.biz_content.state, 'info': r.biz_content.error}; func && func(r.biz_content); } catch (e) { if(e.code === 266 || e.code === 267) { layer.open({ content: '你的登入状态已过期,请重新登入', btn: '重新登入', shadeClose: false, yes: function (i) { sessionStorage.setItem('fromUrl', window.location.href); var querys = $.getQueryObj(); window.location.href='manage.html?agentid='+querys.agentid+'&channelid='+querys.channelid; } }); } else { $.alert(e.info); } } }, complete: function (r) { if ((typeof isAsync === 'boolean' && typeof that.loadingLayerIndex === 'number') || isAsync === 1) layer.close(that.loadingLayerIndex); }, error: function (xhr, textStatus) { $.alert('网络异常'); } } ); }, apiv2: function (methods, params, func, errFunc, isAsync) { //console.log('params', params) var token = sessionStorage.getItem("token"); var apiDate = { method: methods, format: "json", charset: "utf-8", version: "1.0", user_auth_token: token, biz_content: params }; isAsync = isAsync || false; if (isAsync === 1) $.loading(); var that = this; $.ajax( { url: this.API_URL, type: 'POST', //dataType: 'json', async: !!isAsync, data: apiDate, timeout: 10000, success: function (r) { r = ('string' == typeof r) ? eval("(" + decodeURIComponent(r) + ")") : r; if (!r) throw "服务器端有错误发生,请联系管理员!"; console.log(methods, r); if (r.user_auth_token) sessionStorage.setItem('token', r.user_auth_token); try { if (r.retcode !== 0) { if(r.retcode === 266) throw {code: 266, info: ''}; errFunc && errFunc(r.retcode, r.retinfo); return; } if (r.biz_content.state && parseInt(r.biz_content.state) !== 0) { errFunc && errFunc(r.biz_content.state, r.biz_content.error); return; } func && func(r.biz_content); } catch (e) { if(e.code === 266 || e.code === 267) { layer.open({ content: '你的登入状态已过期,请重新登入', btn: '重新登入', shadeClose: false, yes: function (i) { sessionStorage.setItem('fromUrl', window.location.href); var querys = $.getQueryObj(); window.location.href='manage.html?agentid='+querys.agentid+'&channelid='+querys.channelid; } }); } else { $.alert(e.info); } } }, complete: function (r) { if ((typeof isAsync === 'boolean' && typeof that.loadingLayerIndex === 'number') || isAsync === 1) layer.close(that.loadingLayerIndex); }, error: function (xhr, textStatus) { $.alert('网络较慢!') } } ); }, getAgentInfo: function (func) { var p = this.getQueryObj(); if (!p.agentid || !p.channelid) { alert('没有agentid和channelid,请重新进入页面'); return; } var agentInfo = sessionStorage.getItem('agentInfo'); if (agentInfo) { agentInfo = JSON.parse(agentInfo); //console.log('agentinfo from session', agentInfo); func && func(agentInfo); } else { var that = this; this.api( "Youle.Youle.channelConfig", {agentid: p.agentid, channelid: p.channelid}, function (res) { try { sessionStorage.setItem('agentInfo', JSON.stringify(res)); } catch (e) { alert("如果此页面无法正常显示,请关闭浏览器的隐身模式,再打开此页面。"); } func && func(res); }, true ); } }, getSidScode: function (func) { var that = this; this.getAgentInfo(function (agentInfo) { var p = that.getQueryObj(); var sid = p.sid; var scode = sessionStorage.getItem('scode'); var result; if (!sid || !scode) { sid = sessionStorage.getItem('sid'); //scode = sessionStorage.getItem('scode'); if (!sid || !scode) { var currentUrl = window.location.href.replace(/sid=\w+&/, "").replace(/scode=\w+&/, ""); var appid = agentInfo.youle_appid; var devkey = agentInfo.youle_devkey; var busiid = agentInfo.youle_busiid; var randomStr = $.randomString(32); sessionStorage.setItem('scode', randomStr); var urlSidScode = that.SID_SCODE_URL + "?scode="+randomStr+"&appid="+appid+"&dev_key=" + devkey + "&market_key=" + busiid + "&redirect_uri=" + currentUrl; window.location.href = urlSidScode; return; } else { result = $.extend({}, {sid: sid, scode: scode}, agentInfo) func && func(result); } } else { sessionStorage.setItem('sid', sid); //sessionStorage.setItem('scode', scode); result = $.extend({}, {sid: sid, scode: scode}, agentInfo) func && func(result); } }) }, getWxInfo: function (func) { // 如果缓存中有微信信息,直接返回 if(this.wxInfo.openid) { console.log('getWxInfo from cache(wxInfo)', this.wxInfo); func && func(this.wxInfo); return; } var wxInfo = sessionStorage.getItem('wxInfo'); // 如果不在微信环境 if(!$.isWeiXin()/* && (pageName === 'player_buy.html' || pageName === 'become_sales_free.html' || pageName === 'become_sales.html' || pageName === 'notify.html')*/) { if(wxInfo) { wxInfo = JSON.parse(wxInfo); //console.log('getWxInfo from session(phone)', wxInfo); func && func(wxInfo); } else { func && func({ "id": "", "uid": "", "nickname": "", "sex": "0", "province": "", "city": "", "country": "", "headimgurl": "", "privilege": "[]", "subscribe": "1", "subscribe_time": "", "unionid": "", "openid": "" }); } return; } if (wxInfo) { wxInfo = JSON.parse(wxInfo); // 将信息存到缓存中 this.wxInfo = wxInfo; console.log('getWxInfo from session', wxInfo); func && func(wxInfo); } else { var that = this; this.getSidScode(function (r) { var data = {sid: r.sid, scode: r.scode, appid: r.youle_appid, market_key: r.youle_busiid, devkey: r.youle_devkey}; $.ajax( { url: that.WX_INFO_URL, type: 'POST', dataType: 'json', async: false, data: data, success: function (res) { try { if (res.error && parseInt(res.error) !== 0) throw {code: res.error, msg: res.msg}; console.log('getWxInfo', res); if (res.dataContent.headimgurl.length < 20 || !res.dataContent.headimgurl) res.dataContent.headimgurl = that.AVATAR_URL; res.dataContent.headimgurl = res.dataContent.headimgurl.replace(/132132/, "132"); sessionStorage.setItem('wxInfo', JSON.stringify(res.dataContent)); that.wxInfo = res.dataContent; func && func(res.dataContent); } catch (e) { $.alert(e.msg); if(e.code && parseInt(e.code) === 1) { sessionStorage.removeItem('sid'); sessionStorage.removeItem('scode'); } var tmp = $.extend({}, data, e); $.log(tmp); } }, error: function (xhr, textStatus) { console.log('error', xhr, textStatus) $.alert('网络异常!') } } ) }); } }, getUserInfo: function (func) { var that = this; if(!$.isWeiXin() && $.getPageName() === 'player_buy.html') { func && func({}); return; } this.getWxInfo(function (r) { var userInfo = sessionStorage.getItem('userInfo'); // 如果sessionStorage中有用户信息,直接返回,否则返回登录页面 if (userInfo) { userInfo = JSON.parse(userInfo); //console.log('getUserInfo from sessionStorage', userInfo); func && func(userInfo); } else { layer.open({ content: '你的登入状态已过期,请重新登入', btn: '重新登入', shadeClose: false, yes: function (i) { sessionStorage.setItem('fromUrl', window.location.href); var querys = $.getQueryObj(); window.location.href='manage.html?agentid='+querys.agentid+'&channelid='+querys.channelid; } }); } }) }, getUserInfoNoCache: function (func) { var that = this; this.getWxInfo(function (r) { var p = that.getQueryObj(); var salesid = sessionStorage.getItem('salesid'); if (salesid) { var password = sessionStorage.getItem('password'); if (!password) throw 'no password'; that.api( 'agent.user.login', { agentid: p.agentid, channelid: p.channelid, salesid: salesid, password: password, type: 1 }, function (userInfo) { try { if (userInfo.sausstatus && parseInt(userInfo.sausstatus) !== 0) throw '对不起,你的账号已被冻结'; if (userInfo.salesman && parseInt(userInfo.salesman) !== 1) { window.location.href = './manage.html?agentid=' + p.agentid + '&channelid=' + p.channelid; return; } if (userInfo.salesman && parseInt(userInfo.salesman) === 1) { that.userInfo = userInfo; func && func(userInfo); } else { throw '获取用户信息错误'; } } catch (e) { $.alert(e) } } ) } else { that.api ( 'agent.user.login', { agentid: p.agentid, channelid: p.channelid, openid: r.openid, unionid: r.unionid, nickname: r.nickname, avatar: r.headimgurl, sex: r.sex, province: r.province, type: 0 }, function (res) { try { if (res.sausstatus && parseInt(res.sausstatus) !== 0) throw '对不起,你的账号已被冻结'; var salesman = parseInt(res.salesman); if (res.salesman && salesman !== 1) { window.location.href = './manage.html?agentid=' + p.agentid + '&channelid=' + p.channelid; return; } if (res.salesman && salesman === 1) { that.userInfo = res; func && func(res); } else { throw '获取用户信息错误'; } } catch (e) { $.alert(e) } } ); } }); }, // 给新用户第一次登录用 getUserInfoFirst: function (func, isAsync) { var that = this; if(!$.isWeiXin()) { func && func({"agentid":"","channelid":"","openid":"","unionid":"","nickname":"","headimgurl":"https://dlwebv3.tscce.cn/images/noavatar.png","sex":"1","province":"","city":"","salesman":"1","salesid":"","level":"0","salestype":"11","roomcard":"1105","bean":"1007","salespower":"2222","agentmode":"2","sausstatus":"0","html_applysales":"0","global_power":"1","tel":"15621212323","wechat":"sd56465456","user_id":"","is_bind":"1","logintype":"0"}); return; } this.getWxInfo(function (r) { var p = that.getQueryObj(); var isLog = sessionStorage.getItem('isLog'); that.apiv2 ( 'agent.user.login', { agentid: p.agentid, channelid: p.channelid, openid: r.openid, unionid: r.unionid, nickname: r.nickname, avatar: r.headimgurl, sex: r.sex, province: r.province, islog: (isLog ? 0: 1) }, function (res) { sessionStorage.setItem('isLog', 1); func && func(res); }, function (code, info) { if(code === 4254) $.alert('未获取到你的用户信息,如果你是新用户,请先进入游戏后再登录'); else $.alert(info); }, isAsync ); }) }, payLogin: function (agentInfo, func) { if($.isWeiXin()) { func && func({sid: '', scode: ''}); return; } var code = $.randomString(32); var tmp = { appid: agentInfo.youle_appid_pay, devkey: agentInfo.youle_devkey_pay, market_key: agentInfo.youle_busiid_pay, scode: code, agent_key: agentInfo.agentid, game_key: 'asdf', user_key: 'uaser', }; $.ajax( { // ts已修改2021 // url: 'https://api.tscce.cn/api/login/ylnn', url: 'https://api2.tscce.cn/api/login/ylnn', type: 'POST', dataType: 'json', async: false, data: tmp, success: function (res) { res = res.data; res.scode = code; console.log('paylog',res); func && func(res); }, error: function (xhr, textStatus) { $.alert('网络异常!') } } ) }, // 微信支付 toPay: function (params, agentInfo, wxInfo, billInfo, index, uid, state) { uid = uid || ''; state = state || ''; var that = this; var frmPost = document.createElement('form'); frmPost.id = '____frmPost____'; frmPost.name = '____frmPost____'; frmPost.method = 'post'; frmPost.action = that.PAY_URL; //var fff={}; var add_formchild = function (name, value) { //fff[name] = value; var edt = document.createElement('input'); edt.type = 'text'; edt.id = name; edt.name = name; edt.value = value; frmPost.appendChild(edt); } $.payLogin(agentInfo, function (loginSidScode) { var method; var type; if (index === 'star') { if($.isWeiXin()) { method = 'agent.order.starPaySuccess'; } else { method = 'agent.order.starPaySuccessH5'; } type = 1; } else { if($.isWeiXin()) { method = 'agent.order.paySuccess'; } else { if(state === 'become') method = 'agent.order.paySuccess'; else method = 'agent.order.paySuccess'; } type = 0; } var noticeUrl = { url: that.API_URL, params: { method: method, format: 'json', charset: 'utf-8', version: '1.0', user_auth_token: '', biz_content: { 'agentid': params.agentid, 'channelid': params.channelid, 'openid': wxInfo.openid, 'unionid': wxInfo.unionid, 'orderno': billInfo.billcode, 'money': billInfo.productmoney, 'player': billInfo.plyerid, 'playerid': (state !== 'become' ? uid : ''), 'salesid': (state === 'become' ? uid : ''), 'signkey': '0t3xm3w1foyhcmhlux31mwrmybqh4cgd' } } }; var noticeUrlParams = that.NOTICE_URL + JSON.stringify(noticeUrl); var returnUrlParams = that.RETURN_URL; add_formchild("app_id", agentInfo.youle_appid_pay); add_formchild("dev_key", agentInfo.youle_devkey_pay); add_formchild("market_key", agentInfo.youle_busiid_pay); add_formchild("fee", billInfo.productmoney * 100); add_formchild("order_id", billInfo.billcode); add_formchild("title", billInfo.productname); add_formchild("notice_url", noticeUrlParams); add_formchild("return_url", returnUrlParams); add_formchild("agentid", params.agentid); add_formchild("channelid", params.channelid); add_formchild("paytype", '9'); add_formchild("type", type); add_formchild("is_qrcode", 'n'); add_formchild("sign_key", ''); add_formchild("state", state); if(!$.isWeiXin()) { add_formchild("sid", loginSidScode.sid); add_formchild("scode", loginSidScode.scode); } //console.log('pay_params', noticeUrlParams); document.body.appendChild(frmPost); frmPost.submit(); frmPost.remove(); }); }, shareLink: function (fengxiang, func) { $.ajax( { type: "post", url: this.SHARE_LINK, dataType: 'json', async: false, data: fengxiang, timeout: 1000 * 7, success: function (data, textStatus) { console.log('获取微信分享签名成功', data); if (data.error == 0) { func && func(data.data); } else { var code = parseInt(data.error_code); if (code === 10008 || code === 10001 || code === 10011) { sessionStorage.removeItem('sid'); sessionStorage.removeItem('scode'); $.getSidScode(); } else { $.alert(data.error_code + ': ' + data.msg); } } }, complete: function (res) {}, error: function (XMLHttpRequest, textStatus, errorThrown) { console.log('error', XMLHttpRequest, textStatus, errorThrown); $.alert("分享失败:网络异常"); } }); }, setShareLink: function (data, param) { var js = { debug: false, appId: data.appId, timestamp: data.timestamp, nonceStr: data.nonceStr, signature: data.signature, jsApiList: [ 'onMenuShareTimeline', 'onMenuShareAppMessage' ] } wx.config(js); wx.ready(function () { wx.onMenuShareTimeline( { //分享到朋友圈 title: param.title, link: param.link, imgUrl: param.imgUrl, success: function () { $.alert('分享成功'); }, cancel: function () { } }); wx.onMenuShareAppMessage( { //分享到好友 title: param.title, desc: param.desc, link: param.link, imgUrl: param.imgUrl, type: 'link', success: function () { $.alert('分享成功'); }, cancel: function () { } }); }); wx.error(function (res) { console.log('wx.error', res); $.alert('配置微信分享链接失败,请使用图片二维码分享!'); $.log(res); }); }, alert: function (msg, func) { if(typeof layer === 'object') { var $obj = { content: msg, btn: '我知道了', yes: function (i) { layer.close(i); func && func(); }, no: function (i) { layer.close(i); func && func(); } }; layer.open($obj); } else alert(msg); }, confirm: function (func) { var $obj = { content: "确认操作?", btn: ['确认', '取消'], yes: function (i) { layer.close(i); $.loading(); func(); } }; layer.open($obj); }, loading: function (func) { this.loadingLayerIndex = layer.open( { type: 2, content: '加载中', shadeClose: false, success: function (e) { func && func(e); } }); }, close: function () { layer.closeAll(); }, randomString: function (len, charSet) { charSet = charSet || 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; var randomString = ''; var randomPoz = 0; for (var i = 0; i < len; i++) { randomPoz = Math.floor(Math.random() * charSet.length); randomString += charSet.substring(randomPoz,randomPoz+1); } return randomString; }, log: function (data) { var apiDate = { method: "Youle.Youle.webLog", format: "json", charset: "utf-8", version: "1.0", user_auth_token: "", biz_content: data }; $.ajax( { url: this.API_URL, type: 'POST', //dataType: 'json', data: apiDate, timeout: 10000, success: function (r) {} } ); } }); init(); })(jQuery)