Login.js 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822
  1. cc.Class({
  2. // extends: cc.BaseClass,
  3. // properties: {},
  4. // ctor: function () {
  5. // this.m_szWXCode = "";
  6. // //'resources/Audio/'
  7. // this.m_BasicSound = new Array(
  8. // ['BGM0', 'BGM0'],
  9. // ['BGM1', 'BGM1'],
  10. // ['Button', 'button'],
  11. // ['Jet', 'Jet'],
  12. // ['SendCard', 'sendcard'],
  13. // );
  14. // },
  15. extends: cc.BaseClass, // 继承自框架基础类(提供基础功能如事件管理)
  16. properties: {}, // 属性声明区块(当前为空,可在子类中添加编辑器可配置属性)
  17. ctor: function () { // 构造函数
  18. // 微信授权码存储(可能用于登录/支付流程)
  19. this.m_szWXCode = "";
  20. this.isLogining = false;
  21. // 基础音效资源配置(已注释的根路径可能在实际加载时拼接)
  22. /* 数据结构说明:
  23. [
  24. [资源标识符, 文件名(无扩展名)],
  25. ...
  26. ]
  27. 示例:['BGM0', 'BGM0'] 表示:
  28. - 标识符为BGM0的音效
  29. - 对应文件路径可能是 resources/Audio/BGM0.mp3
  30. */
  31. this.m_BasicSound = new Array(
  32. ['BGM0', 'BGM0'], // 主背景音乐
  33. ['BGM1', 'BGM1'], // 备用背景音乐
  34. ['Button', 'button'], // 按钮点击音效
  35. ['Jet', 'Jet'], // 喷射音效(可能用于特效)
  36. ['SendCard', 'sendcard'] // 发牌音效
  37. );
  38. },
  39. // onLoad: function () {
  40. // this.node.setContentSize(cc.winSize.width, cc.winSize.height);
  41. // this.InitView();
  42. // this.m_BtWXLogin.active = !cc.share.IsH5_WX();
  43. // this.m_BtPhoneLogin.active = !cc.share.IsH5_WX();
  44. // this.m_AgreeToggle.node.active = !cc.share.IsH5_WX();
  45. // //this.m_BtLogin.active = false;
  46. // cc.gSoundRes.LoadSoundArr(this.m_BasicSound, 'PublicAudio');
  47. // },
  48. // start: function () {
  49. // cc.audioEngine.stopAll();
  50. // this.InitView();
  51. // },
  52. onLoad: function () {
  53. let str = "0123456789";
  54. //console.log("str-------", str.slice(0,3))
  55. //console.log("str-------", str)
  56. // while (str.length != 0) {
  57. // str = str.slice(2);
  58. // setTimeout((s)=>{
  59. // console.log("s--: ",s)
  60. // },50,str)
  61. // }
  62. // 节点初始化:设置为全屏尺寸
  63. this.node.setContentSize(cc.winSize.width, cc.winSize.height);
  64. // 初始化界面元素
  65. this.InitView();
  66. // 微信H5环境判断(隐藏特定登录方式)
  67. this.m_BtWXLogin.active = !cc.share.IsH5_WX(); // 微信登录按钮
  68. this.m_BtPhoneLogin.active = !cc.share.IsH5_WX(); // 手机登录按钮
  69. this.m_AgreeToggle.node.active = !cc.share.IsH5_WX(); // 协议勾选框
  70. // 加载基础音频资源(预加载公共音效)
  71. cc.gSoundRes.LoadSoundArr(
  72. this.m_BasicSound, // 音频配置数组
  73. 'PublicAudio' // 资源目录/分类标识
  74. );
  75. console.log("登录--", window.location.search)
  76. if (window.location.search) {
  77. this.h5LoginCb(window.location.search)
  78. }
  79. },
  80. start: function () {
  81. // 停止所有背景音乐(防止多场景音乐叠加)
  82. cc.audioEngine.stopAll();
  83. // 再次初始化界面(防止数据不同步)
  84. this.InitView();
  85. this.isShowOther = false;
  86. },
  87. // InitView: function () {
  88. // if (!this.m_BtWXLogin) this.m_BtWXLogin = this.$('BtWXLogin');
  89. // if (!this.m_BtPhoneLogin) this.m_BtPhoneLogin = this.$('BtPhoneLogin');
  90. // if (!this.m_AgreeNode) this.m_AgreeNode = this.$('AgreeNode');
  91. // if (!this.m_AgreeToggle) this.m_AgreeToggle = this.$('AgreeToggle@Toggle');
  92. // if (!this.m_LabVersion) this.m_LabVersion = this.$('LabVersion@Label');
  93. // if (!this.m_BtLogin) this.m_BtLogin = this.$('BtLogin');
  94. // },
  95. InitView: function () {
  96. // 初始化UI元素引用(延迟加载模式)
  97. // 平台登录按钮
  98. if (!this.m_BtPlatformLogin)
  99. this.m_BtPlatformLogin = this.$('BtPlatformLogin'); // ios/google
  100. // 通用登录按钮:可能用于游客登录等备用登录方式
  101. if (!this.m_BtLogin)
  102. this.m_BtLogin = this.$('BtLogin');
  103. // 其他登录按钮
  104. if (!this.m_BtOtherLogin)
  105. this.m_BtOtherLogin = this.$('BtOtherLogin');
  106. // 协议条款容器节点:可能包含文本链接/勾选框等元素
  107. if (!this.m_AgreeNode)
  108. this.m_AgreeNode = this.$('AgreeNode'); // 协议条款父节点
  109. // 协议勾选框:用户需同意服务条款的Toggle组件
  110. if (!this.m_AgreeToggle)
  111. this.m_AgreeToggle = this.$('AgreeToggle@Toggle');
  112. // 版本号标签:显示当前应用版本信息的文本组件
  113. if (!this.m_LabVersion)
  114. this.m_LabVersion = this.$('LabVersion@Label');
  115. // other
  116. if (!this.m_otherNode)
  117. this.m_otherNode = this.$('otherNode');
  118. // 微信登录按钮:通过选择器获取节点并绑定Button组件
  119. // 选择器格式:"节点名@组件类型"
  120. if (!this.m_BtWXLogin)
  121. this.m_BtWXLogin = this.$('BtWXLogin'); // 微信授权登录按钮
  122. // Line登录按钮
  123. if (!this.m_BtLINELogin)
  124. this.m_BtLINELogin = this.$('BtLINELogin'); // Line授权登录按钮
  125. // google登录按钮
  126. if (!this.m_BtGOOGLELogin)
  127. this.m_BtGOOGLELogin = this.$('BtGOOGLELogin'); // googl授权登录按钮
  128. // ios登录按钮
  129. if (!this.m_BtIOSLogin)
  130. this.m_BtIOSLogin = this.$('BtIOSLogin'); // ios授权登录按钮
  131. // 手机登录按钮:获取手机号登录方式的交互按钮
  132. if (!this.m_BtPhoneLogin)
  133. this.m_BtPhoneLogin = this.$('BtPhoneLogin');
  134. },
  135. // OnShowView: function () {
  136. // ShowO2I(this.node);
  137. // this.InitView();
  138. // this.BindButtonInit();
  139. // this.OnEnter();
  140. // CLUB_SCORE_LOGON_PSW = 0;
  141. // if(window.gClubClientKernel) window.gClubClientKernel.shutdown();
  142. // },
  143. OnShowView: function () {
  144. // 视图显示时的统一入口方法
  145. // 1. 播放入场动画(假设为从Out到In的过渡效果)
  146. ShowO2I(this.node); // 可能需要传入动画时长参数
  147. // 2. 初始化界面元素引用(确保节点正确获取)
  148. this.InitView(); // 防御性初始化,防止动态修改布局导致引用丢失
  149. // 3. 绑定按钮事件监听(如点击/长按等交互)
  150. this.BindButtonInit(); // 通常包含类似 this.m_BtLogin.node.on('click', ...)
  151. // 4. 执行进入视图的业务逻辑(数据加载、状态更新等)
  152. this.OnEnter(); // 可能包含:加载用户数据、请求服务器状态等
  153. // 5. 重置俱乐部登录密码状态(根据业务需求)
  154. CLUB_SCORE_LOGON_PSW = 0; // 可能表示:0-需要重新验证密码
  155. // 6. 安全关闭俱乐部内核(如果存在)
  156. if (window.gClubClientKernel)
  157. window.gClubClientKernel.shutdown(); // 释放资源,防止多实例冲突
  158. },
  159. // OnHideView: function () {
  160. // HideI2O(this.node);
  161. // },
  162. OnHideView: function () {
  163. // 视图隐藏时触发生命周期方法
  164. // 执行退出动画(假设为In到Out的过渡效果)
  165. HideI2O(this.node);
  166. },
  167. /* 代码逻辑说明:
  168. 1. 核心功能:
  169. - 触发视图隐藏动画,通常用于场景切换时的过渡效果
  170. - 与OnShowView的ShowO2I形成对称动画逻辑(进场/离场)
  171. 2. 参数说明:
  172. - this.node: 当前组件挂载的节点,一般为整个视图的根节点
  173. - HideI2O可能接收的额外参数(动画时长、缓动函数等需查看具体实现)
  174. 3. 动画特性:
  175. ▸ 可能包含透明度渐变、位移动画等视觉效果
  176. ▸ 可能自动处理节点active状态(建议验证实现)
  177. ▸ 可能是异步动画(需要回调时应在HideI2O中添加完成事件)
  178. 4. 典型应用场景:
  179. - 用户点击返回按钮
  180. - 执行场景切换操作时
  181. - 收到系统事件强制关闭视图(如网络断开)
  182. 5. 注意事项:
  183. - 如动画结束后需要禁用节点,需在HideI2O回调中设置:
  184. this.node.active = false;
  185. - 若视图包含音频/粒子等后台资源,需在此方法中额外停止
  186. - 多层级视图需确保父级动画不影响子视图独立控制*/
  187. // OnEnter: function () {
  188. // if (cc.sys.isBrowser) {
  189. // if (window.LOG_NET_DATA) console.log("cc.sys.isBrowser");
  190. // var AutoLogonAcc = getQueryString("AAcc");
  191. // if (AutoLogonAcc) {
  192. // window.g_PhpUserName = AutoLogonAcc;
  193. // window.g_PhpPassword = getQueryString("APsw");
  194. // }
  195. // if (window.g_PhpUserName == '') window.g_PhpUserName = null;
  196. // }
  197. // getLinkInfo();
  198. // // this.StopLoading();
  199. // // 加载声音
  200. // // cc.gSoundRes.LoadSoundArr(this.m_BasicSound)
  201. // if (cc.sys.isBrowser) {
  202. // if (window.g_PhpUserName != null && !gReLogin) this.LoginAccount(window.g_PhpUserName, hex_md5(window.g_PhpPassword));
  203. // } else {
  204. // //自动登录
  205. // if (!gReLogin && cc.sys.localStorage.getItem('LoginPsw') != null) this.LoginAccount(cc.sys.localStorage.getItem('LoginAcc'), cc.sys.localStorage.getItem('LoginPsw'));
  206. // }
  207. // g_Login = this;
  208. // },
  209. OnEnter: function () {
  210. // 视图进入时的核心初始化方法
  211. // 浏览器环境处理(Web端逻辑)
  212. if (cc.sys.isBrowser) {
  213. //if (window.LOG_NET_DATA) console.log(cc.sys); // 调试日志
  214. // 从URL参数获取自动登录凭证(示例URL:?AAcc=user&APsw=123)
  215. var AutoLogonAcc = getQueryString("AAcc");
  216. if (AutoLogonAcc) {
  217. window.g_PhpUserName = AutoLogonAcc; // 存储全局用户名
  218. window.g_PhpPassword = getQueryString("APsw"); // 明文密码(存在安全隐患)
  219. }
  220. if (window.g_PhpUserName == '') window.g_PhpUserName = null; // 空值处理
  221. }
  222. //getLinkInfo(); // 获取推广链接信息(如渠道号、邀请码等)
  223. // 浏览器环境自动登录逻辑
  224. if (cc.sys.isBrowser) {
  225. // 存在预置账号且不需要重新登录时触发自动登录
  226. if (window.g_PhpUserName != null && !gReLogin) {
  227. this.LoginAccount(
  228. window.g_PhpUserName,
  229. hex_md5(window.g_PhpPassword) // 使用MD5加密传输(需改进为更安全方案)
  230. );
  231. }
  232. }
  233. // 原生环境处理(APP端逻辑)
  234. else {
  235. // 通过本地存储获取持久化登录凭证
  236. if (!gReLogin && cc.sys.localStorage.getItem('LoginPsw') != null) {
  237. this.LoginAccount(
  238. cc.sys.localStorage.getItem('LoginAcc'), // 本地存储的用户名
  239. cc.sys.localStorage.getItem('LoginPsw') // 本地存储的密码(建议加密存储)
  240. );
  241. }
  242. }
  243. g_Login = this; // 暴露当前实例给全局访问(需谨慎)
  244. // new
  245. this._updateBtns();
  246. },
  247. _updateBtns() {
  248. let isNative = !!cc.sys.isNative;
  249. this.m_BtPlatformLogin.active = isNative;
  250. if (isNative) {
  251. this.m_BtPlatformLogin.x = -360;
  252. this.m_BtPlatformLogin.getChildByName("ios").active = cc.sys.OS_IOS == cc.sys.os;
  253. this.m_BtPlatformLogin.getChildByName("google").active = cc.sys.OS_ANDROID == cc.sys.os;
  254. }
  255. this.m_BtLogin.x = isNative ? 0 : -180;
  256. this.m_BtOtherLogin.x = isNative ? 360 : 180;
  257. //other
  258. this._updateOtherView();
  259. },
  260. _updateOtherView() {
  261. this.m_otherNode.active = this.isShowOther;
  262. this.m_BtLINELogin.active = this.isShowOther;
  263. this.m_BtWXLogin.active = this.isShowOther && false;
  264. this.m_BtGOOGLELogin.active = this.isShowOther && !(cc.sys.isNative && cc.sys.OS_ANDROID == cc.sys.os);
  265. let btnsNode = [this.m_BtGOOGLELogin, this.m_BtIOSLogin, this.m_BtLINELogin, this.m_BtWXLogin];
  266. let posIndex = 0;
  267. let posArr = [{ x: -160, y: 120 }, { x: 160, y: 120 }, { x: -160, y: 0 }, { x: 160, y: 0 }, { x: -160, y: -120 }, { x: 160, y: -120 },];
  268. for (let btnNode of btnsNode) {
  269. if (!btnNode.active) {
  270. continue;
  271. }
  272. let posInfo = posArr[posIndex++];
  273. btnNode.x = posInfo.x;
  274. btnNode.y = posInfo.y;
  275. }
  276. },
  277. //微信账号登录按钮点击事件
  278. OnClick_BtWXLogin: function () {
  279. // cc.gSoundRes.PlaySound('Button');
  280. if (!this.CheckToggle()) return;
  281. if (this.isLogining) return;
  282. this.ShowLoading(null, '登入中');
  283. if (cc.sys.isNative) {
  284. ThirdPartyWXLogin();
  285. } else if (cc.sys.isBrowser) {
  286. window.location.href = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=2007057599&redirect_uri=${window.PHP_HOME}/h5/web-mobile&state=12345abcde&scope=profile%20openid&nonce=09876xyz`;
  287. }
  288. },
  289. //Line账号登录按钮点击事件
  290. OnClick_BtLINELogin: function () {
  291. // cc.gSoundRes.PlaySound('Button');
  292. if (!this.CheckToggle()) return;
  293. if (this.isLogining) return;
  294. this.ShowLoading(null, '登入中');
  295. if (cc.sys.isNative) {
  296. ThirdPartyLINELogin();
  297. } else if (cc.sys.isBrowser) {
  298. window.location.href = `https://access.line.me/oauth2/v2.1/authorize?response_type=code&client_id=2007057599&redirect_uri=${window.PHP_HOME}/h5/web-mobile&state=12345abcde&scope=profile%20openid&nonce=09876xyz`;
  299. }
  300. },
  301. //苹果账号登录按钮点击事件
  302. OnClick_BtIOSLogin: function () {
  303. // cc.gSoundRes.PlaySound('Button');
  304. if (!this.CheckToggle()) return;
  305. if (this.isLogining) return;
  306. if (cc.sys.OS_IOS != cc.sys.os) {
  307. return;
  308. }
  309. this.ShowLoading(null, '登入中');
  310. if (cc.sys.isNative) {
  311. ThirdPartyIOSLogin();
  312. } else if (cc.sys.isBrowser) {
  313. window.location.href = `https://access.line.me/oauth2/v2.1/authorize?response_type=code&client_id=2007057599&redirect_uri=${window.PHP_HOME}/h5/web-mobile&state=12345abcde&scope=profile%20openid&nonce=09876xyz`;
  314. }
  315. },
  316. //谷歌账号登录按钮点击事件
  317. OnClick_BtGOOGLELogin: function () {
  318. // cc.gSoundRes.PlaySound('Button');
  319. if (!this.CheckToggle()) return;
  320. if (this.isLogining) return;
  321. this.ShowLoading(null, '登入中');
  322. if (cc.sys.isNative) {
  323. ThirdPartyGoogleLogin();
  324. } else if (cc.sys.isBrowser) {
  325. window.location.href = `https://access.line.me/oauth2/v2.1/authorize?response_type=code&client_id=2007057599&redirect_uri=${window.PHP_HOME}/h5/web-mobile&state=12345abcde&scope=profile%20openid&nonce=09876xyz`;
  326. }
  327. },
  328. //平台登录按钮点击事件
  329. OnClick_BtPlatformLogin: function () {
  330. // cc.gSoundRes.PlaySound('Button');
  331. if (!this.CheckToggle()) return;
  332. if (this.isLogining) return;
  333. this.ShowLoading(null, '登入中');
  334. if (cc.sys.isNative) {
  335. if (cc.sys.OS_IOS == cc.sys.os) {
  336. ThirdPartyIOSLogin();
  337. } else if (cc.sys.OS_ANDROID == cc.sys.os) {
  338. ThirdPartyGoogleLogin();
  339. }
  340. } else if (cc.sys.isBrowser) {
  341. window.location.href = `https://access.line.me/oauth2/v2.1/authorize?response_type=code&client_id=2007057599&redirect_uri=${window.PHP_HOME}/h5/web-mobile&state=12345abcde&scope=profile%20openid&nonce=09876xyz`;
  342. }
  343. },
  344. //其他登录方式
  345. OnClick_BtOtherLogin: function () {
  346. this.isShowOther = true;
  347. this._updateOtherView();
  348. },
  349. onClickReturn() {
  350. this.isShowOther = false;
  351. this._updateOtherView();
  352. },
  353. h5LoginCb: function (res) {
  354. let code = this.getQueryStringNew(res, "code")
  355. console.log("code-5", code);
  356. if (code == null || code == undefined || code == "") {
  357. console.log("code错误");
  358. return;
  359. }
  360. if (this.isLogining) return;
  361. this.isLogining = true;
  362. this.httpPost(code, this.postCb);
  363. this.scheduleOnce(() => {
  364. this.isLogining = false;
  365. }, 7);
  366. },
  367. postCb: function (res) {
  368. let res_access_token = JSON.parse(res);
  369. // console.log("res_access_token--1",res_access_token)
  370. let access_token = res_access_token.access_token
  371. console.log("res_access_token--2", access_token)
  372. if (access_token == null || access_token == undefined || access_token == "") {
  373. console.log("access_token error");
  374. return;
  375. }
  376. var xhr = new XMLHttpRequest();
  377. xhr.onreadystatechange = function () {
  378. if (xhr.readyState === 4 && (xhr.status >= 200 && xhr.status < 400)) {
  379. var respone = decodeURI(xhr.responseText);
  380. if (window.LOG_WEB_DATA) console.log("httpGet返回1 ", respone);
  381. //respone = respone.replace(/\s+\r\n/g,'');
  382. // while(respone != '' && respone[0].charCodeAt() == 65279){//口或?开头 原因不明
  383. // var end1 = respone.lastIndexOf("}");
  384. // var end2 = respone.lastIndexOf("]");
  385. // var end = Math.max(end1, end2)
  386. // end = end>=0?end+1:respone.length;
  387. // respone = respone.substring(1, end );
  388. // }
  389. // if(window.LOG_WEB_DATA)console.log("httpGet返回2 "+respone)
  390. let userinfo = JSON.parse(respone);
  391. if (userinfo == null || userinfo == undefined || userinfo == "") {
  392. console.log("获取用户信息失败")
  393. return;
  394. }
  395. console.log("userinfo-", userinfo)
  396. if (userinfo.pictureUrl == null || userinfo.pictureUrl == undefined) {
  397. userinfo.pictureUrl = ""
  398. }
  399. let codeObj = { openid: userinfo.userId, nickname: userinfo.displayName, sex: 1, headimgurl: userinfo.pictureUrl }
  400. let code = JSON.stringify(codeObj)
  401. //let code = "{openid:"+userinfo.userId+",nickname:"+userinfo.displayName+",sex:1,headimgurl:"+userinfo.pictureUrl+"}"
  402. var webUrlH5 = window.PHP_HOME + '/UserFunc.php?&GetMark=11&code=' + code;
  403. console.log("webUrl请求", webUrlH5)
  404. setTimeout(() => {
  405. WebCenter.GetData(webUrlH5, null, function (data) {
  406. if (window.LOG_NET_DATA) console.log("Login--22登入返回 " + data)
  407. var Login = JSON.parse(data);
  408. if (Login.errcode != null) return this.ShowAlert("ErrCode:" + Login.errcode);
  409. // cc.sys.localStorage.setItem(window.Key_LoginPlatform, window.PLATFORM_WX);
  410. g_Login.LoginAccount(Login.Accounts, Login.LogonPass);
  411. }.bind(this));
  412. }, 500);
  413. }
  414. }.bind(this);
  415. xhr.timeout = 5000;// 5 seconds for timeout
  416. xhr.open("GET", "https://api.line.me/v2/profile", true);
  417. // xhr.setRequestHeader('Content-Type','text/plain');
  418. xhr.setRequestHeader("Authorization", "Bearer " + access_token);
  419. xhr.send();
  420. },
  421. getQueryStringNew: function (url, name) {
  422. const queryString = url;
  423. const urlParams = new URLSearchParams(queryString);
  424. console.log("urlParams--1", urlParams.toString())
  425. const param = urlParams.get(name);
  426. console.log("param--", param)
  427. return param;
  428. },
  429. //获得第三方CODE "{\"headimgurl\":\"%@\",\"sex\":\"%@\",\"unionid\":\"%@\",\"openid\":\"%@\",\"nickname\":\"%@\"}"
  430. onWXCode: function (code) {
  431. if (window.LOG_NET_DATA) console.log("onWXCode " + code)
  432. if (code == '') {
  433. console.log("Login--空 ")
  434. return;
  435. } else {
  436. var json = JSON.parse(code);
  437. json.nickname = json.nickname.replace(/&/g, '%26');
  438. code = JSON.stringify(json);
  439. var webUrl = window.PHP_HOME + '/UserFunc.php?&GetMark=11&code=' + code;
  440. setTimeout(() => {
  441. if (window.LOG_NET_DATA) console.log("Login--6登入 " + code)
  442. WebCenter.GetData(webUrl, null, function (data) {
  443. if (window.LOG_NET_DATA) console.log("Login--登入返回 " + data)
  444. var Login = JSON.parse(data);
  445. if (Login.errcode != null) return this.ShowAlert("ErrCode:" + Login.errcode);
  446. // cc.sys.localStorage.setItem(window.Key_LoginPlatform, window.PLATFORM_WX);
  447. this.LoginAccount(Login.Accounts, Login.LogonPass);
  448. }.bind(this));
  449. }, 600);
  450. }
  451. },
  452. //RegisterAccount
  453. // RegisterAccount: function (Account, Password, Nickname, Gender, PhoneReg) {
  454. // if (!this.CheckToggle()) return;
  455. // this.ShowLoading(null, '正在注册');
  456. // var LogonAccounts = new CMD_GP_RegisterAccounts();
  457. // LogonAccounts.dwPlazaVersion = cc.VERSION_PLAZA;
  458. // LogonAccounts.szAccounts = Account
  459. // LogonAccounts.szPassWord = Password;
  460. // LogonAccounts.szMachineID = "creator";
  461. // LogonAccounts.cbGender = (Gender ? 1 : 0);
  462. // if(Nickname) LogonAccounts.szNickName = Nickname;
  463. // else {
  464. // var nowDate = new Date();
  465. // LogonAccounts.szNickName = '游客';
  466. // LogonAccounts.szNickName += nowDate.getMonth() + 1;
  467. // LogonAccounts.szNickName += nowDate.getDate();
  468. // LogonAccounts.szNickName += 'r' + nowDate.getTime() % 1000;
  469. // }
  470. // if(PhoneReg) var LoginMission = new CGPLoginMission(this, MDM_GP_LOGON, SUB_GP_REGISTER_PHONE, LogonAccounts);
  471. // else var LoginMission = new CGPLoginMission(this, MDM_GP_LOGON, SUB_GP_REGISTER_ACCOUNTS, LogonAccounts);
  472. // var pGlobalUserData = g_GlobalUserInfo.GetGlobalUserData();
  473. // pGlobalUserData.szPassword = LogonAccounts.szPassWord;
  474. // cc.sys.localStorage.setItem('LoginAcc', Account);
  475. // cc.sys.localStorage.setItem('LoginPswT', Password);
  476. // },
  477. RegisterAccount: function (Account, Password, Nickname, Gender, PhoneReg) {
  478. // 注册账号主逻辑
  479. if (!this.CheckToggle()) return; // 校验用户协议勾选状态,未勾选则中断流程
  480. this.ShowLoading(null, '註冊中'); // 显示全局加载提示框
  481. // 构建注册协议数据结构
  482. var LogonAccounts = new CMD_GP_RegisterAccounts(); // 创建注册协议对象
  483. LogonAccounts.dwPlazaVersion = cc.VERSION_PLAZA; // 设置当前大厅版本号
  484. LogonAccounts.szAccounts = Account; // 用户输入账号
  485. LogonAccounts.szPassWord = Password; // 用户输入明文密码
  486. LogonAccounts.szMachineID = "creator"; // 固定设备标识(硬编码值)
  487. LogonAccounts.cbGender = (Gender ? 1 : 0); // 转换性別参数为协议格式(0-女,1-男)
  488. // 处理用户昵称逻辑
  489. if (Nickname) {
  490. LogonAccounts.szNickName = Nickname; // 直接使用传入的昵称参数
  491. } else {
  492. // 生成默认游客昵称(格式:游客+月份+日期+毫秒时间戳末三位)
  493. var nowDate = new Date();
  494. LogonAccounts.szNickName = '';
  495. LogonAccounts.szNickName += nowDate.getMonth() + 1; // 添加当前月份(+1修正0基值)
  496. LogonAccounts.szNickName += nowDate.getDate(); // 添加当前日期
  497. LogonAccounts.szNickName += 'r' + nowDate.getTime() % 1000; // 添加随机后缀
  498. }
  499. // 根据注册类型选择协议号
  500. var LoginMission; // 声明网络任务对象
  501. if (PhoneReg) {
  502. // 手机注册路径:使用手机注册子协议号
  503. LoginMission = new CGPLoginMission(this, MDM_GP_LOGON, SUB_GP_REGISTER_PHONE, LogonAccounts);
  504. } else {
  505. // 普通注册路径:使用账号注册子协议号
  506. LoginMission = new CGPLoginMission(this, MDM_GP_LOGON, SUB_GP_REGISTER_ACCOUNTS, LogonAccounts);
  507. }
  508. // 持久化存储用户凭证
  509. var pGlobalUserData = g_GlobalUserInfo.GetGlobalUserData(); // 获取全局用户数据
  510. pGlobalUserData.szPassword = LogonAccounts.szPassWord; // 更新全局密码字段
  511. cc.sys.localStorage.setItem('LoginAcc', Account); // 本地存储账号
  512. cc.sys.localStorage.setItem('LoginPswT', Password); // 本地存储明文密码
  513. },
  514. //LoginAccount
  515. // LoginAccount: function (Account, Password) {
  516. // if (!this.CheckToggle()) return;
  517. // gReLogin = false;
  518. // this.ShowLoading(null, '登录中');
  519. // var LogonAccounts = new CMD_GP_LogonAccounts();
  520. // LogonAccounts.dwPlazaVersion = cc.VERSION_PLAZA;
  521. // LogonAccounts.szAccounts = Account
  522. // LogonAccounts.szPassword = Password;
  523. // LogonAccounts.szPassPortID = "no";
  524. // var LoginMission = new CGPLoginMission(this, MDM_GP_LOGON, SUB_GP_LOGON_ACCOUNTS, LogonAccounts);
  525. // var pGlobalUserData = g_GlobalUserInfo.GetGlobalUserData();
  526. // pGlobalUserData.szPassword = LogonAccounts.szPassword;
  527. // cc.sys.localStorage.setItem('LoginAcc', Account);
  528. // cc.sys.localStorage.setItem('LoginPswT', Password);
  529. // },
  530. LoginAccount: function (Account, Password) {
  531. console.log("LoginAccount--1")
  532. if (window.LOG_NET_DATA) console.log("LoginAccount--1");
  533. // 账号登录主逻辑
  534. if (!this.CheckToggle()) {
  535. return; // 校验用户协议勾选状态,未勾选则中断流程
  536. }
  537. gReLogin = false; // 重置重新登录标识(防止循环登录)
  538. this.ShowLoading(null, '登入中'); // 显示全局加载提示框
  539. if (window.LOG_NET_DATA) console.log("LoginAccount--2");
  540. // 构建登录协议数据结构
  541. var LogonAccounts = new CMD_GP_LogonAccounts(); // 创建登录协议对象
  542. LogonAccounts.dwPlazaVersion = cc.VERSION_PLAZA; // 设置当前大厅版本号
  543. LogonAccounts.szAccounts = Account; // 用户输入账号
  544. LogonAccounts.szPassword = Password; // 用户输入明文密码
  545. LogonAccounts.szPassPortID = "no"; // 固定护照标识(硬编码值)
  546. // 创建登录网络任务
  547. var LoginMission = new CGPLoginMission(
  548. this,
  549. MDM_GP_LOGON, // 主协议号(登录模块)
  550. SUB_GP_LOGON_ACCOUNTS, // 子协议号(账号登录)
  551. LogonAccounts
  552. );
  553. if (window.LOG_NET_DATA) console.log("LoginAccount--3");
  554. // 持久化存储用户凭证
  555. var pGlobalUserData = g_GlobalUserInfo.GetGlobalUserData(); // 获取全局用户数据
  556. pGlobalUserData.szPassword = LogonAccounts.szPassword; // 更新全局密码字段
  557. cc.sys.localStorage.setItem('LoginAcc', Account); // 本地存储账号
  558. cc.sys.localStorage.setItem('LoginPswT', Password); // 本地存储明文密码
  559. },
  560. OnShowChangePsw: function () {
  561. // this.ShowPrefabDLG("ChangePsw");
  562. },
  563. OnClick_BtChangePsw: function () {
  564. // this.ShowPrefabDLG("ChangePsw");
  565. },
  566. // 显示登录框
  567. OnClick_BtPhoneLogin: function () {
  568. // cc.gSoundRes.PlaySound('Button');
  569. this.ShowPrefabDLG("PhoneLogin");
  570. },
  571. // 显示登录框
  572. OnClick_BtLogin: function () {
  573. // cc.gSoundRes.PlaySound('Button');
  574. this.ShowPrefabDLG("AccLogin");
  575. },
  576. onGPLoginSuccess: function () {
  577. },
  578. OnClick_BtShowAgreeNode: function () {
  579. this.ShowPrefabDLG('AgreeMent', this.m_DlgNode);
  580. // if(this.m_AgreeNode) this.m_AgreeNode.runAction(cc.moveTo(0.1, cc.v2(0, 0)));
  581. },
  582. OnClick_BtHideAgreeNode: function () {
  583. this.m_AgreeNode.runAction(cc.moveTo(0.1, cc.v2(-window.SCENE_WIGHT, 0)));
  584. },
  585. //
  586. CheckToggle: function () {
  587. if (!this.m_AgreeToggle.isChecked) {
  588. this.ShowAlert("請同意使用者協定!", Alert_Yes);
  589. return false;
  590. }
  591. return true;
  592. },
  593. //登录失败
  594. onGPLoginFailure: function (szDescription) {
  595. this.StopLoading();
  596. //提示信息
  597. this.ShowAlert(szDescription, Alert_Yes);
  598. },
  599. //登陆成功
  600. onGPLoginComplete: function () {
  601. //查询重连
  602. this.SendReLinkQuery()
  603. },
  604. //查询回连
  605. SendReLinkQuery: function () {
  606. // this.ShowLoading();
  607. var QueryRL = new CMD_GP_C_Relink();
  608. QueryRL.dwUserID = g_GlobalUserInfo.GetGlobalUserData().dwUserID;
  609. var LoginMission = new CGPLoginMission(this, MDM_GP_GET_SERVER, SUB_GP_QUERY_RELINK, QueryRL);
  610. },
  611. //进入服务器信息
  612. OnQueryServerRes: function (ReturnServer) {
  613. if (ReturnServer.wKindID == 0 || !this.BeLoadRes(ReturnServer.wKindID)) {
  614. ChangeScene('Lobby');
  615. return;
  616. }
  617. g_ServerListDataLast = new CGameServerItem();
  618. g_ServerListDataLast.wKindID = ReturnServer.wKindID;
  619. g_ServerListDataLast.wServerPort = ReturnServer.wServerPort;
  620. g_ServerListDataLast.szServerAddr = ReturnServer.szServerAddr;
  621. g_ServerListDataLast.wServerType = ReturnServer.wServerType;
  622. g_ServerListDataLast.llEnterScore = ReturnServer.llEnterScore;
  623. g_ServerListDataLast.szServerName = "";
  624. if (g_CurScene && g_CurScene.EnterGameScene) g_CurScene.EnterGameScene();
  625. },
  626. OnQueryRoomRes: function (ReturnServer) {
  627. if (window.LOG_NET_DATA) console.log('OnQueryRoomRes ', ReturnServer)
  628. if (ReturnServer.wKindID == 0 || !this.BeLoadRes(ReturnServer.wKindID)) {
  629. ChangeScene('Lobby');
  630. return;
  631. }
  632. g_ServerListDataLast = new CGameServerItem();
  633. g_ServerListDataLast.wKindID = ReturnServer.wKindID;
  634. g_ServerListDataLast.wServerPort = ReturnServer.wServerPort;
  635. g_ServerListDataLast.szServerAddr = ReturnServer.szServerAddr;
  636. g_ServerListDataLast.wServerType = ReturnServer.wServerType;
  637. g_ServerListDataLast.llEnterScore = ReturnServer.llEnterScore;
  638. g_ServerListDataLast.szServerName = "";
  639. window.g_dwRoomID = ReturnServer.dwRoomID;
  640. window.g_dwClubID = ReturnServer.dwClubID;
  641. if (g_CurScene && g_CurScene.EnterGameScene) g_CurScene.EnterGameScene();
  642. },
  643. //登陆成功
  644. onGetServerListFinish: function () { },
  645. OnBtTestLoginin: function (Tag, Num) {
  646. var key = 'test' + Num;
  647. if (this[key] == null) this[key] = true;
  648. else return this.OnReSetTestLogin();
  649. var InPutCnt = 0;
  650. for (var i = 1; i <= Num; i++) {
  651. if (this['test' + i] == null) return this.OnReSetTestLogin();
  652. else InPutCnt++;
  653. }
  654. if (InPutCnt >= 3) this.m_AccLogin.active = true;
  655. },
  656. OnReSetTestLogin: function () {
  657. for (var i = 1; i < 4; i++) this['test' + i] = null;
  658. },
  659. //游戏资源预加载
  660. BeLoadRes: function (wKindID) {
  661. try {
  662. //游戏自定义
  663. GameDef = new window['CMD_GAME_' + wKindID]();
  664. if (GameDef == null) {
  665. var game = window.GameList[wKindID];
  666. if (game == null) game = wKindID;
  667. return false;
  668. }
  669. //游戏桌布
  670. window.gGameBG = 'loading';
  671. window.LoadSetting();
  672. window.LoadSetting(wKindID);
  673. var pathInfo = window.Path_GameBG(wKindID, window.g_GameSetting[wKindID][window.SetKey_Table_BG], 0, true);
  674. GameDef.BGIndex = pathInfo.BGIndex;
  675. GameDef.BGPath = pathInfo.path;
  676. } catch (error) {
  677. return false;
  678. }
  679. return true;
  680. },
  681. httpPost: function (code, CallBack) {
  682. var xhr = new XMLHttpRequest();
  683. xhr.onreadystatechange = function () {
  684. if (xhr.readyState === 4 && (xhr.status >= 200 && xhr.status < 400)) {
  685. var respone = xhr.responseText;
  686. if (window.LOG_WEB_DATA) console.log("line-返回-1 " + respone)
  687. // while(respone != '' && respone[0].charCodeAt() == 65279){//口或?开头 原因不明
  688. // var end1 = respone.lastIndexOf("}");
  689. // var end2 = respone.lastIndexOf("]");
  690. // var end = Math.max(end1, end2)
  691. // end = end>=0?end+1:respone.length;
  692. // respone = respone.substring(1, end );
  693. // }
  694. //if(window.LOG_WEB_DATA) console.log("line-返回-2"+respone)
  695. CallBack(respone);
  696. }
  697. }.bind(this);
  698. xhr.timeout = 5000;// 5 seconds for timeout
  699. xhr.open("POST", "https://api.line.me/oauth2/v2.1/token/", true);
  700. xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  701. // xhr.setRequestBody("grant_type","authorization_code");
  702. // xhr.setRequestBody("code",code);
  703. // xhr.setRequestBody("redirect_uri","http://34.80.6.45:8080/h5/web-mobile");
  704. // xhr.setRequestBody("client_id","2007057599");
  705. // xhr.setRequestBody("client_secret","04bb8dd9bdf94572d44443df0643cc89");
  706. // xhr.send();
  707. xhr.send("grant_type=authorization_code&code=" + code + "&redirect_uri=http://34.80.6.45:8080/h5/web-mobile&client_id=2007057599&client_secret=04bb8dd9bdf94572d44443df0643cc89");
  708. }
  709. });