YZ_Tool_Broswer.ts 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. import PlatUtils from "./PlatUtils";
  2. import { utils } from "./Utils";
  3. import { LevelStatus } from "./YZ_Constant";
  4. const ST_ServerUrl: string = "http://apps.youlesp.com/aconfig?";
  5. let ST_DefaultServerConfig: string = "";
  6. const ST_NativeInsertAdClickTimes: string = "NativeInsertAdClickTimes";
  7. const ST_LastDateTime: string = "LastDateTime";
  8. const POST_ServerUrl: string = "https://report.youletd.com/gss?";
  9. export default class YZ_Tool_Broswer {
  10. _serverConfig: any = null;
  11. public get ServerConfig() {
  12. return this._serverConfig;
  13. }
  14. _nativeInsertAdClickTimes: number = 0;
  15. public get NativeInsertAdClickTimes() {
  16. return this._nativeInsertAdClickTimes;
  17. }
  18. public _img_url: string = "app/editor/static/img/logo-with-text.png"
  19. // 桌面图标是否创建
  20. _shortcutCreated: boolean = false;
  21. public get ShortcutCreated() {
  22. return this._shortcutCreated;
  23. }
  24. get img_url(): string {
  25. return window.location.href + this._img_url;
  26. }
  27. /**
  28. * 获取交叉推广数据
  29. */
  30. public getRecommondGameList() {
  31. return [
  32. {
  33. "id": "30213731",
  34. "name": "测试一",
  35. "appid": "com.yzxx.hcrttt.kyx.nearme.gamecenter",
  36. "logo": this.img_url,
  37. "icon": this.img_url
  38. },
  39. {
  40. "id": "30213731",
  41. "name": "测试二",
  42. "appid": "com.yzxx.hcrttt.kyx.nearme.gamecenter",
  43. "logo": this.img_url,
  44. "icon": this.img_url
  45. },
  46. {
  47. "id": "30213731",
  48. "name": "测试三",
  49. "appid": "com.yzxx.hcrttt.kyx.nearme.gamecenter",
  50. "logo": this.img_url,
  51. "icon": this.img_url
  52. },
  53. {
  54. "id": "30213731",
  55. "name": "测试四",
  56. "appid": "com.yzxx.hcrttt.kyx.nearme.gamecenter",
  57. "logo": this.img_url,
  58. "icon": this.img_url
  59. },
  60. {
  61. "id": "30213731",
  62. "name": "测试五",
  63. "appid": "com.yzxx.hcrttt.kyx.nearme.gamecenter",
  64. "logo": this.img_url,
  65. "icon": this.img_url
  66. },
  67. {
  68. "id": "30213731",
  69. "name": "测试六",
  70. "appid": "com.yzxx.hcrttt.kyx.nearme.gamecenter",
  71. "logo": this.img_url,
  72. "icon": this.img_url
  73. },
  74. {
  75. "id": "30213731",
  76. "name": "测试七",
  77. "appid": "com.yzxx.hcrttt.kyx.nearme.gamecenter",
  78. "logo": this.img_url,
  79. "icon": this.img_url
  80. },
  81. {
  82. "id": "30213731",
  83. "name": "测试八",
  84. "appid": "com.yzxx.hcrttt.kyx.nearme.gamecenter",
  85. "logo": this.img_url,
  86. "icon": this.img_url
  87. },
  88. {
  89. "id": "30213731",
  90. "name": "测试九",
  91. "appid": "com.yzxx.hcrttt.kyx.nearme.gamecenter",
  92. "logo": this.img_url,
  93. "icon": this.img_url
  94. },
  95. {
  96. "id": "30213731",
  97. "name": "测试10",
  98. "appid": "com.yzxx.hcrttt.kyx.nearme.gamecenter",
  99. "logo": this.img_url,
  100. "icon": this.img_url
  101. },
  102. {
  103. "id": "30213731",
  104. "name": "测试11",
  105. "appid": "com.yzxx.hcrttt.kyx.nearme.gamecenter",
  106. "logo": this.img_url,
  107. "icon": this.img_url
  108. },
  109. {
  110. "id": "30213731",
  111. "name": "测试12",
  112. "appid": "com.yzxx.hcrttt.kyx.nearme.gamecenter",
  113. "logo": this.img_url,
  114. "icon": this.img_url
  115. },
  116. {
  117. "id": "30213731",
  118. "name": "测试13",
  119. "appid": "com.yzxx.hcrttt.kyx.nearme.gamecenter",
  120. "logo": this.img_url,
  121. "icon": this.img_url
  122. },
  123. {
  124. "id": "30213731",
  125. "name": "测试14",
  126. "appid": "com.yzxx.hcrttt.kyx.nearme.gamecenter",
  127. "logo": this.img_url,
  128. "icon": this.img_url
  129. }
  130. ];
  131. }
  132. /**
  133. *
  134. * @param data 配置数据
  135. */
  136. public init(data: string) {
  137. if (data) {
  138. let configObj: any = JSON.parse(data);
  139. if (configObj && configObj.oppo) {
  140. ST_DefaultServerConfig = JSON.stringify(configObj.oppo);
  141. }
  142. }
  143. let self = this;
  144. let xhr = new XMLHttpRequest();
  145. xhr.open('GET', this.img_url);
  146. xhr.send();
  147. xhr.onreadystatechange = function () {
  148. if (xhr.readyState == 4 && xhr.status == 200) {
  149. console.log("测试图片路径正常")
  150. self._loadConfig();
  151. }
  152. if (xhr.readyState == 4 && xhr.status == 404) {
  153. console.log("测试图片路径不存在切换图片路径");
  154. self._img_url = "app/editor/static/preview-templates/splash.png"
  155. self._loadConfig();
  156. }
  157. }
  158. xhr.ontimeout = function () {
  159. console.log("测试图片加载超时切换图片路径");
  160. self._img_url = "app/editor/static/preview-templates/splash.png"
  161. self._loadConfig();
  162. }
  163. xhr.onerror = function (err) {
  164. console.log("测试图片路径异常:" + err + "切换图片路径");
  165. self._img_url = "app/editor/static/preview-templates/splash.png"
  166. self._loadConfig();
  167. }
  168. }
  169. _loadConfig() {
  170. this._serverConfig = JSON.parse(ST_DefaultServerConfig);
  171. this._serverConfig.icon_jump = 5;
  172. this._serverConfig.jump_list = this.getRecommondGameList();
  173. utils.emitServerInitEvent();
  174. }
  175. /**
  176. * 上报自定义事件
  177. * @param level 当前关卡ID
  178. * @param levelName 关卡名称
  179. * @param status 状态
  180. */
  181. public sendEvent(eventName: string) {
  182. if (PlatUtils.IsTest) {
  183. // let method = "m=revent";
  184. utils.showLog("上报自定义事件 " + eventName);
  185. // let url: string = POST_ServerUrl + method + `&event=${encodeURI(eventName)}`;
  186. // utils.commomHttpRequest(url, function (ret, data) {
  187. // if (ret) {
  188. // utils.showLog("上报自定义事件成功!");
  189. // } else {
  190. // utils.showLog("上报自定义事件失败!");
  191. // }
  192. // }.bind(this));
  193. }
  194. }
  195. /**
  196. *
  197. * @param level 当前关卡ID
  198. * @param levelName 关卡名称
  199. * @param status 状态
  200. */
  201. public postLevel(level: string, status: LevelStatus, levelName?: string) {
  202. if (PlatUtils.IsTest) {
  203. // let method = "m=rlevel";
  204. utils.showLog(`关卡${level},${status}`);
  205. // let url: string = POST_ServerUrl + method + `&level_id=${level}&level_name=${encodeURI(levelName)}&status=${status}`;
  206. // utils.commomHttpRequest(url, function (ret, data) {
  207. // if (ret) {
  208. // utils.showLog("关卡数据上报成功!");
  209. // } else {
  210. // utils.showLog("关卡数据上报失败!");
  211. // }
  212. // }.bind(this));
  213. }
  214. }
  215. /**
  216. * 实名认证
  217. */
  218. public realNameAuth(code: string, name: string, callBack: Function) {
  219. if (!utils._isConfigInit) {
  220. utils.showLog("warn:" + "本地数据未初始化!");
  221. return;
  222. }
  223. let method: string = "m=realNameAuth"
  224. let completeCallback = callBack;
  225. let xhr = new XMLHttpRequest();
  226. xhr.timeout = 6000; // 单位毫秒
  227. let data: any = {};
  228. data.kyx = false;
  229. data.app_id = "6103b73b864a9558e6d65af8";
  230. data.channel = "m233";
  231. data.device_uid = 0;
  232. data.uid = "482501611";
  233. data.game_type = 2;
  234. data.device_data = "";
  235. data.game_version = "1.0.0";
  236. data.reqv = "";
  237. data.app_list = "";
  238. data.id_card = code;
  239. data.real_name = name;
  240. let requestData = JSON.stringify(data);
  241. let requestUrl: string = "https://apps.youlesp.com/gss?" + method + `&time_stamp=${(new Date()).getTime()}&json_data=${utils.aesEncrypt(requestData)}`;
  242. utils.showLog("服务器地址:" + requestUrl);
  243. xhr.open('GET', requestUrl);
  244. xhr.send();
  245. xhr.onreadystatechange = function () {
  246. utils.showLog("请求状态改变, reaedyState=", xhr.readyState, "; status=", xhr.status);
  247. if (xhr.readyState == 4) {
  248. if (xhr.status == 200) {
  249. if (completeCallback) {
  250. completeCallback(true, utils.aesDecrypt(xhr.responseText));
  251. }
  252. } else {
  253. if (completeCallback) {
  254. completeCallback(false, "");
  255. }
  256. }
  257. }
  258. if (xhr.status != 200) {
  259. }
  260. }
  261. xhr.ontimeout = function () {
  262. utils.showLog("请求超时!");
  263. if (completeCallback) {
  264. completeCallback(false, "");
  265. }
  266. }
  267. xhr.onerror = function (err) {
  268. if (completeCallback) {
  269. completeCallback(false, "");
  270. }
  271. }
  272. }
  273. }