import HttpMgr from "../base/HttpMgr"; import SoundMgr from "../base/SoundMgr"; import UserInfoMgr from "../base/user/UserInfoMgr"; import LoginMgr from "../models/LoginMgr"; import UIMgr from "../base/UIMgr"; cc.Class({ extends: cc.Component, properties: { accountNode: cc.Node, editName: cc.EditBox, editPwd: cc.EditBox, wxNode: cc.Node, }, // LIFE-CYCLE CALLBACKS: // onLoad () {}, start () { }, // update (dt) {}, initData(){ //账号登录: 1. http注册-->登录获取玩家信息. 2. webSocket连接 // TODO 自动登录 // cc.director.loadScene('hallScene'); // return; //主动登录 this.setLoginType(); }, //选择登录方式 setLoginType(){ this.accountNode.active = true; //账号密码登录 this.wxNode.active = false; //微信登录 if(this.accountNode.active){ let str = cc.sys.localStorage.getItem('localAccount'); if(str){ //有值则读取本地数据. let obj = JSON.parse(str); this.editName.string = obj.username; this.editPwd.string = obj.password; } } if(this.wxNode.active){ // TODO.. } }, //账号注册 onClickRegister(){ SoundMgr.playClick(); // let url = 'https://portal.2022nishang.com//user/simpleRegister?source=1302&imei=1715327472&oaid=0'; let url=`${AppSettings.PLATFORM_ADDRESS}user/simpleRegister?source=${1302}&imei=${1715327472}&oaid=${0}`; HttpMgr.httpRequest('GET', url, null, (code, responseText)=>{ if(code === ''){ //成功 let tData = JSON.parse(responseText); console.log('注册返回: ', tData); if(tData.code == 200){ this.editName.string = tData.data.username; this.editPwd.string = tData.data.password; let str = cc.sys.localStorage.getItem('localAccount'); let obj = {}; if (str) { obj = JSON.parse(str); } obj.username = tData.data.username; obj.password = tData.data.password; cc.sys.localStorage.setItem('localAccount', JSON.stringify(obj)); }else{ //失败 UIMgr.openUI('prefabs/TipsLayer', (pf)=>{ pf.getComponent('TipsLayer').setCon(tData.message); }); } } }); }, //账号登录 onClickAccountLogin(){ SoundMgr.playClick(); // this.editName.string = '18018971160'; // this.editPwd.string = '2185a179ffb34c49a89b0247cea09067'; // let url = 'https://portal.2022nishang.com//user/loginOnly?username=18018971160&password=2185a179ffb34c49a89b0247cea09067&source=1302&imei=1715330157&serverId=1&oaid=0'; let url = `${AppSettings.PLATFORM_ADDRESS}user/loginOnly?username=${this.editName.string}&password=${this.editPwd.string}&source=${1302}&imei=${1715330157}&serverId=${1}&oaid=${0}`; HttpMgr.httpRequest('GET', url, null, (code, responseText)=>{ if(code === ''){ //成功 let tData = JSON.parse(responseText); console.log('账号登录返回: ', tData); if(tData.code == 200){ //成功登录 cc.sys.localStorage.setItem('token', tData.data.token); //存储token AppSettings.TOKEN = tData.data.token; GameModel.token = tData.data.token; GameModel.idVerified = tData.data.userInfo.isRealName; GameModel.isUseWxPay = tData.data.userInfo.isUseWxPay; GameModel.updateSign = tData.data.userInfo.updateSign; GameModel.phone = tData.data.userInfo.bindPhone; GameModel.userInfo = tData.data.userInfo; GameModel.idcard = tData.data.userInfo.idcard; GameModel.bindAlipay = tData.data.userInfo.bindAlipay; GameModel.bindAlipayName = tData.data.userInfo.bindAlipayName; // UserInfoMgr.setPlayerData(tData.data.userInfo); //保存玩家信息 this.ReqCheckInfo(); }else{ //失败 UIMgr.openUI('prefabs/TipsLayer', (pf)=>{ pf.getComponent('TipsLayer').setCon(tData.message); }); } } }); }, ReqCheckInfo(){ let data = 'UserID=10911&UseVPN=false&TimeZone=-480&PackageName=h5_luckyPot&Channel=0&VersionCode=0&debug=0'; let url = 'https://gg.hnzhenxi.com/Gapi/check'; HttpMgr.httpRequest('POST', url, data, (code, responseText)=>{ if(code === ''){ //成功 let tData = JSON.parse(responseText); console.log('ReqCheckInfo: ', JSON.parse(responseText)); AppSettings.IP = '223.4.30.191';//tData.IP; AppSettings.Port = '11117';//tData.Port; LoginMgr.login(); } }); } });