Login.js 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862
  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.m_BtOtherLogin.active = true;
  271. this._updateOtherView();
  272. },
  273. _updateOtherView() {
  274. this.m_otherNode.active = this.isShowOther;
  275. this.m_BtLINELogin.active = this.isShowOther;
  276. this.m_BtWXLogin.active = false//this.isShowOther && false;
  277. this.m_BtGOOGLELogin.active = this.isShowOther && !(cc.sys.isNative && cc.sys.OS_ANDROID == cc.sys.os);
  278. let btnsNode = [this.m_BtGOOGLELogin, this.m_BtIOSLogin, this.m_BtLINELogin, this.m_BtWXLogin];
  279. let posIndex = 0;
  280. 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 },];
  281. for (let btnNode of btnsNode) {
  282. if (!btnNode.active) {
  283. continue;
  284. }
  285. let posInfo = posArr[posIndex++];
  286. btnNode.x = posInfo.x;
  287. btnNode.y = posInfo.y;
  288. }
  289. if (cc.sys.OS_IOS != cc.sys.os) {
  290. this.m_BtPlatformLogin.getChildByName("google").active = this.isShowOther;
  291. this.m_BtGOOGLELogin.active = this.isShowOther;
  292. }
  293. this.m_BtLINELogin.active = this.isShowOther;
  294. },
  295. //微信账号登录按钮点击事件
  296. OnClick_BtWXLogin: function () {
  297. // cc.gSoundRes.PlaySound('Button');
  298. if (!this.CheckToggle()) return;
  299. if (this.isLogining) return;
  300. this.ShowLoading(null, '登入中');
  301. if (cc.sys.isNative) {
  302. ThirdPartyWXLogin();
  303. } else if (cc.sys.isBrowser) {
  304. 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`;
  305. }
  306. },
  307. //Line账号登录按钮点击事件
  308. OnClick_BtLINELogin: function () {
  309. // cc.gSoundRes.PlaySound('Button');
  310. if (!this.CheckToggle()) return;
  311. if (this.isLogining) return;
  312. this.ShowLoading(null, '登入中');
  313. if (cc.sys.isNative) {
  314. ThirdPartyLINELogin();
  315. } else if (cc.sys.isBrowser) {
  316. window.location.href = `https://access.line.me/oauth2/v2.1/authorize?response_type=code&client_id=2008795912&redirect_uri=${window.PHP_HOME}/h5/web-mobile&state=12345abcde&scope=profile%20openid&nonce=09876xyz`;
  317. }
  318. },
  319. //苹果账号登录按钮点击事件
  320. OnClick_BtIOSLogin: function () {
  321. // cc.gSoundRes.PlaySound('Button');
  322. if (!this.CheckToggle()) return;
  323. if (this.isLogining) return;
  324. if (cc.sys.OS_IOS != cc.sys.os) {
  325. return;
  326. }
  327. this.ShowLoading(null, '登入中');
  328. if (cc.sys.isNative) {
  329. ThirdPartyIOSLogin();
  330. } else if (cc.sys.isBrowser) {
  331. 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`;
  332. }
  333. },
  334. //谷歌账号登录按钮点击事件
  335. OnClick_BtGOOGLELogin: function () {
  336. // cc.gSoundRes.PlaySound('Button');
  337. if (!this.CheckToggle()) return;
  338. if (this.isLogining) return;
  339. this.ShowLoading(null, '登入中');
  340. if (cc.sys.isNative) {
  341. ThirdPartyGoogleLogin();
  342. } else if (cc.sys.isBrowser) {
  343. 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`;
  344. }
  345. },
  346. //平台登录按钮点击事件
  347. OnClick_BtPlatformLogin: function () {
  348. // cc.gSoundRes.PlaySound('Button');
  349. if (!this.CheckToggle()) return;
  350. if (this.isLogining) return;
  351. this.ShowLoading(null, '登入中');
  352. if (cc.sys.isNative) {
  353. if (cc.sys.OS_IOS == cc.sys.os) {
  354. ThirdPartyIOSLogin();
  355. } else if (cc.sys.OS_ANDROID == cc.sys.os) {
  356. ThirdPartyGoogleLogin();
  357. }
  358. } else if (cc.sys.isBrowser) {
  359. 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`;
  360. }
  361. },
  362. //其他登录方式
  363. OnClick_BtOtherLogin: function () {
  364. this.isShowOther = true;
  365. this._updateOtherView();
  366. },
  367. onClickReturn() {
  368. this.isShowOther = false;
  369. this._updateOtherView();
  370. },
  371. h5LoginCb: function (res) {
  372. let code = this.getQueryStringNew(res, "code")
  373. console.log("code-5", code);
  374. if (code == null || code == undefined || code == "") {
  375. console.log("code错误");
  376. return;
  377. }
  378. if (this.isLogining) return;
  379. this.isLogining = true;
  380. this.httpPost(code, this.postCb);
  381. this.scheduleOnce(() => {
  382. this.isLogining = false;
  383. }, 7);
  384. },
  385. postCb: function (res) {
  386. let res_access_token = JSON.parse(res);
  387. // console.log("res_access_token--1",res_access_token)
  388. let access_token = res_access_token.access_token
  389. console.log("res_access_token--2", access_token)
  390. if (access_token == null || access_token == undefined || access_token == "") {
  391. console.log("access_token error");
  392. return;
  393. }
  394. var xhr = new XMLHttpRequest();
  395. xhr.onreadystatechange = function () {
  396. if (xhr.readyState === 4 && (xhr.status >= 200 && xhr.status < 400)) {
  397. var respone = decodeURI(xhr.responseText);
  398. if (window.LOG_WEB_DATA) console.log("httpGet返回1 ", respone);
  399. //respone = respone.replace(/\s+\r\n/g,'');
  400. // while(respone != '' && respone[0].charCodeAt() == 65279){//口或?开头 原因不明
  401. // var end1 = respone.lastIndexOf("}");
  402. // var end2 = respone.lastIndexOf("]");
  403. // var end = Math.max(end1, end2)
  404. // end = end>=0?end+1:respone.length;
  405. // respone = respone.substring(1, end );
  406. // }
  407. // if(window.LOG_WEB_DATA)console.log("httpGet返回2 "+respone)
  408. let userinfo = JSON.parse(respone);
  409. if (userinfo == null || userinfo == undefined || userinfo == "") {
  410. console.log("获取用户信息失败")
  411. return;
  412. }
  413. console.log("userinfo-", userinfo)
  414. if (userinfo.pictureUrl == null || userinfo.pictureUrl == undefined) {
  415. userinfo.pictureUrl = ""
  416. }
  417. let codeObj = { openid: userinfo.userId, nickname: userinfo.displayName, sex: 1, headimgurl: userinfo.pictureUrl }
  418. let code = JSON.stringify(codeObj)
  419. //let code = "{openid:"+userinfo.userId+",nickname:"+userinfo.displayName+",sex:1,headimgurl:"+userinfo.pictureUrl+"}"
  420. var webUrlH5 = window.PHP_HOME + '/UserFunc.php?&GetMark=11&code=' + code;
  421. console.log("webUrl请求", webUrlH5)
  422. setTimeout(() => {
  423. WebCenter.GetData(webUrlH5, null, function (data) {
  424. if (window.LOG_NET_DATA) console.log("Login--22登入返回 " + data)
  425. var Login = JSON.parse(data);
  426. if (Login.errcode != null) return this.ShowAlert("ErrCode:" + Login.errcode);
  427. // cc.sys.localStorage.setItem(window.Key_LoginPlatform, window.PLATFORM_WX);
  428. g_Login.LoginAccount(Login.Accounts, Login.LogonPass);
  429. }.bind(this));
  430. }, 500);
  431. }
  432. }.bind(this);
  433. xhr.timeout = 5000;// 5 seconds for timeout
  434. xhr.open("GET", "https://api.line.me/v2/profile", true);
  435. // xhr.setRequestHeader('Content-Type','text/plain');
  436. xhr.setRequestHeader("Authorization", "Bearer " + access_token);
  437. xhr.send();
  438. },
  439. getQueryStringNew: function (url, name) {
  440. const queryString = url;
  441. const urlParams = new URLSearchParams(queryString);
  442. console.log("urlParams--1", urlParams.toString())
  443. const param = urlParams.get(name);
  444. console.log("param--", param)
  445. return param;
  446. },
  447. //获得第三方CODE "{\"headimgurl\":\"%@\",\"sex\":\"%@\",\"unionid\":\"%@\",\"openid\":\"%@\",\"nickname\":\"%@\"}"
  448. onWXCode: function (code) {
  449. if (window.LOG_NET_DATA) console.log("onWXCode " + code)
  450. if (code == '') {
  451. console.log("Login--空 ")
  452. window.PLATFORM_ID = 0;
  453. return;
  454. } else {
  455. var json = JSON.parse(code);
  456. json.nickname = json.nickname.replace(/&/g, '%26');
  457. code = JSON.stringify(json);
  458. var webUrl = window.PHP_HOME + '/UserFunc.php?&GetMark=11&code=' + code;
  459. setTimeout(() => {
  460. if (window.LOG_NET_DATA) console.log("Login--6登入 " + code)
  461. WebCenter.GetData(webUrl, null, function (data) {
  462. if (window.LOG_NET_DATA) console.log("Login--登入返回 " + data)
  463. var Login = JSON.parse(data);
  464. if (Login.errcode != null) return this.ShowAlert("ErrCode:" + Login.errcode);
  465. // cc.sys.localStorage.setItem(window.Key_LoginPlatform, window.PLATFORM_WX);
  466. this.LoginAccount(Login.Accounts, Login.LogonPass);
  467. }.bind(this));
  468. }, 600);
  469. }
  470. },
  471. //RegisterAccount
  472. // RegisterAccount: function (Account, Password, Nickname, Gender, PhoneReg) {
  473. // if (!this.CheckToggle()) return;
  474. // this.ShowLoading(null, '正在注册');
  475. // var LogonAccounts = new CMD_GP_RegisterAccounts();
  476. // LogonAccounts.dwPlazaVersion = cc.VERSION_PLAZA;
  477. // LogonAccounts.szAccounts = Account
  478. // LogonAccounts.szPassWord = Password;
  479. // LogonAccounts.szMachineID = "creator";
  480. // LogonAccounts.cbGender = (Gender ? 1 : 0);
  481. // if(Nickname) LogonAccounts.szNickName = Nickname;
  482. // else {
  483. // var nowDate = new Date();
  484. // LogonAccounts.szNickName = '游客';
  485. // LogonAccounts.szNickName += nowDate.getMonth() + 1;
  486. // LogonAccounts.szNickName += nowDate.getDate();
  487. // LogonAccounts.szNickName += 'r' + nowDate.getTime() % 1000;
  488. // }
  489. // if(PhoneReg) var LoginMission = new CGPLoginMission(this, MDM_GP_LOGON, SUB_GP_REGISTER_PHONE, LogonAccounts);
  490. // else var LoginMission = new CGPLoginMission(this, MDM_GP_LOGON, SUB_GP_REGISTER_ACCOUNTS, LogonAccounts);
  491. // var pGlobalUserData = g_GlobalUserInfo.GetGlobalUserData();
  492. // pGlobalUserData.szPassword = LogonAccounts.szPassWord;
  493. // cc.sys.localStorage.setItem('LoginAcc', Account);
  494. // cc.sys.localStorage.setItem('LoginPswT', Password);
  495. // },
  496. RegisterAccount: function (Account, Password, Nickname, Gender, PhoneReg) {
  497. // 注册账号主逻辑
  498. if (!this.CheckToggle()) return; // 校验用户协议勾选状态,未勾选则中断流程
  499. this.ShowLoading(null, '註冊中'); // 显示全局加载提示框
  500. // 构建注册协议数据结构
  501. var LogonAccounts = new CMD_GP_RegisterAccounts(); // 创建注册协议对象
  502. LogonAccounts.dwPlazaVersion = cc.VERSION_PLAZA; // 设置当前大厅版本号
  503. LogonAccounts.szAccounts = Account; // 用户输入账号
  504. LogonAccounts.szPassWord = Password; // 用户输入明文密码
  505. LogonAccounts.szMachineID = "creator"; // 固定设备标识(硬编码值)
  506. LogonAccounts.cbGender = (Gender ? 1 : 0); // 转换性別参数为协议格式(0-女,1-男)
  507. // 处理用户昵称逻辑
  508. if (Nickname) {
  509. LogonAccounts.szNickName = Nickname; // 直接使用传入的昵称参数
  510. } else {
  511. // 生成默认游客昵称(格式:游客+月份+日期+毫秒时间戳末三位)
  512. var nowDate = new Date();
  513. LogonAccounts.szNickName = '';
  514. LogonAccounts.szNickName += nowDate.getMonth() + 1; // 添加当前月份(+1修正0基值)
  515. LogonAccounts.szNickName += nowDate.getDate(); // 添加当前日期
  516. LogonAccounts.szNickName += 'r' + nowDate.getTime() % 1000; // 添加随机后缀
  517. }
  518. // 根据注册类型选择协议号
  519. var LoginMission; // 声明网络任务对象
  520. if (PhoneReg) {
  521. // 手机注册路径:使用手机注册子协议号
  522. LoginMission = new CGPLoginMission(this, MDM_GP_LOGON, SUB_GP_REGISTER_PHONE, LogonAccounts);
  523. } else {
  524. // 普通注册路径:使用账号注册子协议号
  525. LoginMission = new CGPLoginMission(this, MDM_GP_LOGON, SUB_GP_REGISTER_ACCOUNTS, LogonAccounts);
  526. }
  527. // 持久化存储用户凭证
  528. var pGlobalUserData = g_GlobalUserInfo.GetGlobalUserData(); // 获取全局用户数据
  529. pGlobalUserData.szPassword = LogonAccounts.szPassWord; // 更新全局密码字段
  530. cc.sys.localStorage.setItem('LoginAcc', Account); // 本地存储账号
  531. cc.sys.localStorage.setItem('LoginPswT', Password); // 本地存储明文密码
  532. },
  533. //LoginAccount
  534. // LoginAccount: function (Account, Password) {
  535. // if (!this.CheckToggle()) return;
  536. // gReLogin = false;
  537. // this.ShowLoading(null, '登录中');
  538. // var LogonAccounts = new CMD_GP_LogonAccounts();
  539. // LogonAccounts.dwPlazaVersion = cc.VERSION_PLAZA;
  540. // LogonAccounts.szAccounts = Account
  541. // LogonAccounts.szPassword = Password;
  542. // LogonAccounts.szPassPortID = "no";
  543. // var LoginMission = new CGPLoginMission(this, MDM_GP_LOGON, SUB_GP_LOGON_ACCOUNTS, LogonAccounts);
  544. // var pGlobalUserData = g_GlobalUserInfo.GetGlobalUserData();
  545. // pGlobalUserData.szPassword = LogonAccounts.szPassword;
  546. // cc.sys.localStorage.setItem('LoginAcc', Account);
  547. // cc.sys.localStorage.setItem('LoginPswT', Password);
  548. // },
  549. LoginAccount: function (Account, Password) {
  550. console.log("LoginAccount--1")
  551. if (window.LOG_NET_DATA) console.log("LoginAccount--1");
  552. // 账号登录主逻辑
  553. if (!this.CheckToggle()) {
  554. return; // 校验用户协议勾选状态,未勾选则中断流程
  555. }
  556. gReLogin = false; // 重置重新登录标识(防止循环登录)
  557. this.ShowLoading(null, '登入中'); // 显示全局加载提示框
  558. if (window.LOG_NET_DATA) console.log("LoginAccount--2");
  559. // 构建登录协议数据结构
  560. var LogonAccounts = new CMD_GP_LogonAccounts(); // 创建登录协议对象
  561. LogonAccounts.dwPlazaVersion = cc.VERSION_PLAZA; // 设置当前大厅版本号
  562. LogonAccounts.szAccounts = Account; // 用户输入账号
  563. LogonAccounts.szPassword = Password; // 用户输入明文密码
  564. LogonAccounts.szPassPortID = "no"; // 固定护照标识(硬编码值)
  565. // 创建登录网络任务
  566. var LoginMission = new CGPLoginMission(
  567. this,
  568. MDM_GP_LOGON, // 主协议号(登录模块)
  569. SUB_GP_LOGON_ACCOUNTS, // 子协议号(账号登录)
  570. LogonAccounts
  571. );
  572. if (window.LOG_NET_DATA) console.log("LoginAccount--3");
  573. // 持久化存储用户凭证
  574. var pGlobalUserData = g_GlobalUserInfo.GetGlobalUserData(); // 获取全局用户数据
  575. pGlobalUserData.szPassword = LogonAccounts.szPassword; // 更新全局密码字段
  576. cc.sys.localStorage.setItem('LoginAcc', Account); // 本地存储账号
  577. cc.sys.localStorage.setItem('LoginPswT', Password); // 本地存储明文密码
  578. },
  579. OnShowChangePsw: function () {
  580. // this.ShowPrefabDLG("ChangePsw");
  581. },
  582. OnClick_BtChangePsw: function () {
  583. // this.ShowPrefabDLG("ChangePsw");
  584. },
  585. // 显示登录框
  586. OnClick_BtPhoneLogin: function () {
  587. // cc.gSoundRes.PlaySound('Button');
  588. this.ShowPrefabDLG("PhoneLogin");
  589. },
  590. // 显示登录框
  591. OnClick_BtLogin: function () {
  592. // cc.gSoundRes.PlaySound('Button');
  593. this.ShowPrefabDLG("AccLogin");
  594. },
  595. onGPLoginSuccess: function () {
  596. },
  597. OnClick_BtShowAgreeNode: function () {
  598. this.ShowPrefabDLG('AgreeMent', this.m_DlgNode);
  599. // if(this.m_AgreeNode) this.m_AgreeNode.runAction(cc.moveTo(0.1, cc.v2(0, 0)));
  600. },
  601. OnClick_BtHideAgreeNode: function () {
  602. this.m_AgreeNode.runAction(cc.moveTo(0.1, cc.v2(-window.SCENE_WIGHT, 0)));
  603. },
  604. //
  605. CheckToggle: function () {
  606. if (!this.m_AgreeToggle.isChecked) {
  607. this.ShowAlert("請同意使用者協定!", Alert_Yes);
  608. return false;
  609. }
  610. return true;
  611. },
  612. //登录失败
  613. onGPLoginFailure: function (szDescription) {
  614. this.StopLoading();
  615. //提示信息
  616. this.ShowAlert(szDescription, Alert_Yes);
  617. },
  618. //登陆成功
  619. onGPLoginComplete: function () {
  620. //查询重连
  621. this.SendReLinkQuery()
  622. },
  623. //查询回连
  624. SendReLinkQuery: function () {
  625. // this.ShowLoading();
  626. var QueryRL = new CMD_GP_C_Relink();
  627. QueryRL.dwUserID = g_GlobalUserInfo.GetGlobalUserData().dwUserID;
  628. var LoginMission = new CGPLoginMission(this, MDM_GP_GET_SERVER, SUB_GP_QUERY_RELINK, QueryRL);
  629. },
  630. //进入服务器信息
  631. OnQueryServerRes: function (ReturnServer) {
  632. if (ReturnServer.wKindID == 0 || !this.BeLoadRes(ReturnServer.wKindID)) {
  633. ChangeScene('Lobby');
  634. return;
  635. }
  636. g_ServerListDataLast = new CGameServerItem();
  637. g_ServerListDataLast.wKindID = ReturnServer.wKindID;
  638. g_ServerListDataLast.wServerPort = ReturnServer.wServerPort;
  639. g_ServerListDataLast.szServerAddr = ReturnServer.szServerAddr;
  640. g_ServerListDataLast.wServerType = ReturnServer.wServerType;
  641. g_ServerListDataLast.llEnterScore = ReturnServer.llEnterScore;
  642. g_ServerListDataLast.szServerName = "";
  643. if (g_CurScene && g_CurScene.EnterGameScene) g_CurScene.EnterGameScene();
  644. },
  645. OnQueryRoomRes: function (ReturnServer) {
  646. if (window.LOG_NET_DATA) console.log('OnQueryRoomRes ', ReturnServer)
  647. if (ReturnServer.wKindID == 0 || !this.BeLoadRes(ReturnServer.wKindID)) {
  648. ChangeScene('Lobby');
  649. return;
  650. }
  651. g_ServerListDataLast = new CGameServerItem();
  652. g_ServerListDataLast.wKindID = ReturnServer.wKindID;
  653. g_ServerListDataLast.wServerPort = ReturnServer.wServerPort;
  654. g_ServerListDataLast.szServerAddr = ReturnServer.szServerAddr;
  655. g_ServerListDataLast.wServerType = ReturnServer.wServerType;
  656. g_ServerListDataLast.llEnterScore = ReturnServer.llEnterScore;
  657. g_ServerListDataLast.szServerName = "";
  658. window.g_dwRoomID = ReturnServer.dwRoomID;
  659. window.g_dwClubID = ReturnServer.dwClubID;
  660. if (g_CurScene && g_CurScene.EnterGameScene) g_CurScene.EnterGameScene();
  661. },
  662. //登陆成功
  663. onGetServerListFinish: function () { },
  664. OnBtTestLoginin: function (Tag, Num) {
  665. var key = 'test' + Num;
  666. if (this[key] == null) this[key] = true;
  667. else return this.OnReSetTestLogin();
  668. var InPutCnt = 0;
  669. for (var i = 1; i <= Num; i++) {
  670. if (this['test' + i] == null) return this.OnReSetTestLogin();
  671. else InPutCnt++;
  672. }
  673. if (InPutCnt >= 3) this.m_AccLogin.active = true;
  674. },
  675. OnReSetTestLogin: function () {
  676. for (var i = 1; i < 4; i++) this['test' + i] = null;
  677. },
  678. //游戏资源预加载
  679. BeLoadRes: function (wKindID) {
  680. try {
  681. //游戏自定义
  682. GameDef = new window['CMD_GAME_' + wKindID]();
  683. if (GameDef == null) {
  684. var game = window.GameList[wKindID];
  685. if (game == null) game = wKindID;
  686. return false;
  687. }
  688. //游戏桌布
  689. window.gGameBG = 'loading';
  690. window.LoadSetting();
  691. window.LoadSetting(wKindID);
  692. var pathInfo = window.Path_GameBG(wKindID, window.g_GameSetting[wKindID][window.SetKey_Table_BG], 0, true);
  693. GameDef.BGIndex = pathInfo.BGIndex;
  694. GameDef.BGPath = pathInfo.path;
  695. } catch (error) {
  696. return false;
  697. }
  698. return true;
  699. },
  700. httpPost: function (code, CallBack) {
  701. var xhr = new XMLHttpRequest();
  702. xhr.onreadystatechange = function () {
  703. if (xhr.readyState === 4 && (xhr.status >= 200 && xhr.status < 400)) {
  704. var respone = xhr.responseText;
  705. if (window.LOG_WEB_DATA) console.log("line-返回-1 " + respone)
  706. // while(respone != '' && respone[0].charCodeAt() == 65279){//口或?开头 原因不明
  707. // var end1 = respone.lastIndexOf("}");
  708. // var end2 = respone.lastIndexOf("]");
  709. // var end = Math.max(end1, end2)
  710. // end = end>=0?end+1:respone.length;
  711. // respone = respone.substring(1, end );
  712. // }
  713. //if(window.LOG_WEB_DATA) console.log("line-返回-2"+respone)
  714. CallBack(respone);
  715. }
  716. }.bind(this);
  717. xhr.timeout = 5000;// 5 seconds for timeout
  718. xhr.open("POST", "https://api.line.me/oauth2/v2.1/token/", true);
  719. xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  720. // xhr.setRequestBody("grant_type","authorization_code");
  721. // xhr.setRequestBody("code",code);
  722. // xhr.setRequestBody("redirect_uri","http://34.80.6.45:8080/h5/web-mobile");
  723. // xhr.setRequestBody("client_id","2007057599");
  724. // xhr.setRequestBody("client_secret","04bb8dd9bdf94572d44443df0643cc89");
  725. // xhr.send();
  726. 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");
  727. },
  728. //======================同意按钮点击事件回调方法======================
  729. OnClick_AgreeToggle: function (event, customData) {
  730. // 在这里处理同意按钮的点击逻辑
  731. console.log('同意按钮被点击了', customData);
  732. },
  733. OnClick_reset: function (event, customData) {
  734. // 在这里处理同意按钮的点击逻辑
  735. console.log('同意按钮被点击了', customData);
  736. },
  737. OnClick_0: function (event, customData) {
  738. // 在这里处理同意按钮的点击逻辑
  739. console.log('同意按钮被点击了', customData);
  740. },
  741. OnClick_1: function (event, customData) {
  742. // 在这里处理同意按钮的点击逻辑
  743. console.log('同意按钮被点击了', customData);
  744. },
  745. OnClick_2: function (event, customData) {
  746. // 在这里处理同意按钮的点击逻辑
  747. console.log('同意按钮被点击了', customData);
  748. },
  749. OnClick_3: function (event, customData) {
  750. // 在这里处理同意按钮的点击逻辑
  751. console.log('同意按钮被点击了', customData);
  752. },
  753. });