LoginLayer.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. import HttpMgr from "../base/HttpMgr";
  2. import SoundMgr from "../base/SoundMgr";
  3. import UserInfoMgr from "../base/user/UserInfoMgr";
  4. import LoginMgr from "../models/LoginMgr";
  5. import UIMgr from "../base/UIMgr";
  6. cc.Class({
  7. extends: cc.Component,
  8. properties: {
  9. accountNode: cc.Node,
  10. editName: cc.EditBox,
  11. editPwd: cc.EditBox,
  12. wxNode: cc.Node,
  13. },
  14. // LIFE-CYCLE CALLBACKS:
  15. // onLoad () {},
  16. start () {
  17. },
  18. // update (dt) {},
  19. initData(){
  20. //账号登录: 1. http注册-->登录获取玩家信息. 2. webSocket连接
  21. // TODO 自动登录
  22. // cc.director.loadScene('hallScene');
  23. // return;
  24. //主动登录
  25. this.setLoginType();
  26. },
  27. //选择登录方式
  28. setLoginType(){
  29. this.accountNode.active = true; //账号密码登录
  30. this.wxNode.active = false; //微信登录
  31. if(this.accountNode.active){
  32. let str = cc.sys.localStorage.getItem('localAccount');
  33. if(str){ //有值则读取本地数据.
  34. let obj = JSON.parse(str);
  35. this.editName.string = obj.username;
  36. this.editPwd.string = obj.password;
  37. }
  38. }
  39. if(this.wxNode.active){
  40. // TODO..
  41. }
  42. },
  43. //账号注册
  44. onClickRegister(){
  45. SoundMgr.playClick();
  46. // let url = 'https://portal.2022nishang.com//user/simpleRegister?source=1302&imei=1715327472&oaid=0';
  47. let url=`${AppSettings.PLATFORM_ADDRESS}user/simpleRegister?source=${1302}&imei=${1715327472}&oaid=${0}`;
  48. HttpMgr.httpRequest('GET', url, null, (code, responseText)=>{
  49. if(code === ''){ //成功
  50. let tData = JSON.parse(responseText);
  51. console.log('注册返回: ', tData);
  52. if(tData.code == 200){
  53. this.editName.string = tData.data.username;
  54. this.editPwd.string = tData.data.password;
  55. let str = cc.sys.localStorage.getItem('localAccount');
  56. let obj = {};
  57. if (str) {
  58. obj = JSON.parse(str);
  59. }
  60. obj.username = tData.data.username;
  61. obj.password = tData.data.password;
  62. cc.sys.localStorage.setItem('localAccount', JSON.stringify(obj));
  63. }else{ //失败
  64. UIMgr.openUI('prefabs/TipsLayer', (pf)=>{
  65. pf.getComponent('TipsLayer').setCon(tData.message);
  66. });
  67. }
  68. }
  69. });
  70. },
  71. //账号登录
  72. onClickAccountLogin(){
  73. SoundMgr.playClick();
  74. // this.editName.string = '18018971160';
  75. // this.editPwd.string = '2185a179ffb34c49a89b0247cea09067';
  76. // let url = 'https://portal.2022nishang.com//user/loginOnly?username=18018971160&password=2185a179ffb34c49a89b0247cea09067&source=1302&imei=1715330157&serverId=1&oaid=0';
  77. let url = `${AppSettings.PLATFORM_ADDRESS}user/loginOnly?username=${this.editName.string}&password=${this.editPwd.string}&source=${1302}&imei=${1715330157}&serverId=${1}&oaid=${0}`;
  78. HttpMgr.httpRequest('GET', url, null, (code, responseText)=>{
  79. if(code === ''){ //成功
  80. let tData = JSON.parse(responseText);
  81. console.log('账号登录返回: ', tData);
  82. if(tData.code == 200){ //成功登录
  83. cc.sys.localStorage.setItem('token', tData.data.token); //存储token
  84. AppSettings.TOKEN = tData.data.token;
  85. GameModel.token = tData.data.token;
  86. GameModel.idVerified = tData.data.userInfo.isRealName;
  87. GameModel.isUseWxPay = tData.data.userInfo.isUseWxPay;
  88. GameModel.updateSign = tData.data.userInfo.updateSign;
  89. GameModel.phone = tData.data.userInfo.bindPhone;
  90. GameModel.userInfo = tData.data.userInfo;
  91. GameModel.idcard = tData.data.userInfo.idcard;
  92. GameModel.bindAlipay = tData.data.userInfo.bindAlipay;
  93. GameModel.bindAlipayName = tData.data.userInfo.bindAlipayName;
  94. // UserInfoMgr.setPlayerData(tData.data.userInfo); //保存玩家信息
  95. this.ReqCheckInfo();
  96. }else{ //失败
  97. UIMgr.openUI('prefabs/TipsLayer', (pf)=>{
  98. pf.getComponent('TipsLayer').setCon(tData.message);
  99. });
  100. }
  101. }
  102. });
  103. },
  104. ReqCheckInfo(){
  105. let data = 'UserID=10911&UseVPN=false&TimeZone=-480&PackageName=h5_luckyPot&Channel=0&VersionCode=0&debug=0';
  106. let url = 'https://gg.hnzhenxi.com/Gapi/check';
  107. HttpMgr.httpRequest('POST', url, data, (code, responseText)=>{
  108. if(code === ''){ //成功
  109. let tData = JSON.parse(responseText);
  110. console.log('ReqCheckInfo: ', JSON.parse(responseText));
  111. AppSettings.IP = '223.4.30.191';//tData.IP;
  112. AppSettings.Port = '11117';//tData.Port;
  113. LoginMgr.login();
  114. }
  115. });
  116. }
  117. });