JiuWuSDK.ts 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. import Tools from "../Common/Tools";
  2. import Global from "../Common/Global";
  3. //import QgApi from "../Common/manage/Api/QgApi";
  4. import Loading from "../Scene/Loading";
  5. import LogMgr from "../Common/LogMgr";
  6. import CacheMgr from "../Common/manage/CacheMgr";
  7. export default class JiuWuSDK {
  8. public static qgToken: any = null;
  9. public static initSDK: boolean = false;
  10. public static url = {
  11. test: "ZHhttps://api.jiuwugame.cn",
  12. host: "ZHhttps://api.jiuwugame.cn",
  13. }
  14. public static gameInfo: GameInfo = {
  15. gameId: 125,
  16. gameVersion: "ZH20211026",
  17. client: 'ZH95e7b3d7beceea9a7b85a3235892e728',
  18. token: 'ZH$2a$10$gjXXqXHT85QpdRZSsS8QZuu6AnI5hJL/ZzyJ8yzMCit2ii7RhGd.W',
  19. }
  20. public static launchData: launchData = {
  21. scene: '',
  22. query: null,
  23. shareTicket: '',
  24. referrerInfo: {
  25. appId: '',
  26. extraData: null
  27. }
  28. }
  29. public static inSet_API_Config() {
  30. return new Promise((resolve, reject) => {
  31. this.login().then(() => {
  32. this.register().then((data) => {
  33. Global.allData = data;
  34. let gmsUser = Global.allData.data.data.gmsUser;
  35. CacheMgr.userId = gmsUser.userId;
  36. CacheMgr.openId = gmsUser.openId;
  37. CacheMgr.isAuth = gmsUser.isAuth;
  38. // @ts-ignore
  39. Global.config = JSON.parse(Global.allData.data.data.versionMode);
  40. // QgApi.createAdv() ;
  41. LogMgr.log('一切就绪......')
  42. this.initSDK = true;
  43. resolve(true);
  44. }, () => {
  45. LogMgr.error('就绪失败......')
  46. })
  47. })
  48. })
  49. }
  50. /**
  51. * 后台 注册或者登录
  52. */
  53. public static register() {
  54. try {
  55. return new Promise((resolve, reject) => {
  56. console.log('准备发送请求......')
  57. let param: regisMessage = Object(null);
  58. console.log('发送请求中......A')
  59. param.url = Tools.getHost() + '/api/login/loginsum';
  60. console.log('发送请求中......B')
  61. param.data = {
  62. code: this.qgToken,
  63. gameId: this.gameInfo.gameId,
  64. sceneVal: undefined,
  65. exportId: undefined,
  66. version: this.gameInfo.gameVersion,
  67. }
  68. console.log('发送请求中......C')
  69. param.method = 'POST';
  70. param.header = this.headers();
  71. param.header['content-type'] = 'application/json';
  72. param.success = (res) => {
  73. if (res.data.code === 200) {
  74. console.log('后台登录注册成功:', res)
  75. resolve(res);
  76. } else {
  77. console.error('登录错误:', res);
  78. reject(res);
  79. }
  80. };
  81. param.fail = (err) => {
  82. console.error('发送请求失败:', err);
  83. }
  84. console.log('发送请求中......D')
  85. // QgApi.sponsorHttps(param);
  86. });
  87. } catch (e) {
  88. console.error('后台登录错误:', e);
  89. }
  90. }
  91. /**
  92. * 登录vivo
  93. */
  94. public static login() {
  95. return new Promise((resolve, reject) => {
  96. try {
  97. // QgApi.login().then((token) => {
  98. // if (token != false) {
  99. // this.qgToken = token;
  100. // resolve(true);
  101. // }
  102. // }, () => {
  103. // console.error('登录失败')
  104. // })
  105. } catch (e) {
  106. console.log(' login error', e);
  107. }
  108. })
  109. }
  110. public static headers() {
  111. return {
  112. 'x-client': this.gameInfo.client,
  113. 'x-token': this.gameInfo.token
  114. }
  115. }
  116. }
  117. interface GameInfo {
  118. gameId: number,
  119. gameVersion: string,
  120. client: string,
  121. token: string
  122. }
  123. interface launchData {
  124. scene: string,
  125. query: any,
  126. shareTicket: string,
  127. referrerInfo: referrerInfo
  128. }
  129. export interface referrerInfo {
  130. appId: string,
  131. extraData: any
  132. }
  133. export interface regisMessage {
  134. url: string,
  135. data: object,
  136. method: string,
  137. success: any,
  138. fail: any,
  139. header: any
  140. }