Login.js 35 KB

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