Login.js 37 KB

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