JsbSystem.ts 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687
  1. import { DataEventId } from "../../game/data/GameData";
  2. /**
  3. * Jsb管理类(与安卓Java类或者IOS交互)
  4. * @description
  5. * @author 冯聪
  6. */
  7. export default class JsbSystem {
  8. /**代码桥在AS中的路径 */
  9. private static _JSB_ANDROID_PATH: string = "org/cocos2dx/javascript/thirdSdk/ThirdSdkMgr";
  10. /**代码桥在IOS中的路径 */
  11. private static _JSB_IOS_PATH: string = "ThirdSdkMgr";
  12. /**代码桥在AS中的路径 */
  13. private static _JSB_ANDROID_PATH_JSDK: string = "org/cocos2dx/javascript/thirdSdk/ysdk/YSDKMgr";
  14. //callBack
  15. public static callBack: Function = null;
  16. /**
  17. * 是否文件存在
  18. * @param filePath 文件路径
  19. * @returns 是否文件存在 boolean
  20. */
  21. public static isFileExist(fileName: string): boolean {
  22. if (cc.sys.os == cc.sys.OS_WINDOWS) {
  23. return true;
  24. }
  25. let filePath = this.getWritablePath() + fileName + ".apk";
  26. return jsb.fileUtils.isFileExist(filePath);
  27. }
  28. /**
  29. * 获取写入的路径
  30. * @description
  31. * @returns path 写入路径(string)
  32. */
  33. public static getWritablePath(): string {
  34. return jsb.fileUtils.getWritablePath();
  35. }
  36. /**
  37. * 调用项目工程静态方法
  38. * @description 调用Android与IOS对应的静态方法
  39. * @param path 调用路径:"org/cocos2dx/javascript/AppActivity":java中的包名(.换成/)+class文件名,就当是路径好了
  40. * @param methodName 调用的方法名:必须public static
  41. * @param methodSignature 方法签名:“(Ljava/lang/String;)Ljava/lang/String;”:()内的是调用的java方法的参数类型,()外面的是返回值类
  42. * @param parameters 参数:是java方法需要传入的参数(可以多个,与methodSignature中()内的数量和类型一一对应)
  43. */
  44. public static callStaticMethod(path: string, methodName: string, methodSignature: string, ...parameters: any): any {
  45. let value = jsb.reflection.callStaticMethod(path, methodName, methodSignature, ...parameters);
  46. return value;
  47. }
  48. /**
  49. * Java调用返回测试
  50. * @description 自定义功能 JavaToCocos
  51. */
  52. public static backTest() {
  53. }
  54. /**
  55. * 更新设备信息
  56. * @description 自定义功能 JavaToCocos
  57. * @param info info(Java返回)
  58. */
  59. public static updateDeviceInfo(info) {
  60. mk.console.log("===[JsbSystem] updateDeviceInfo", info)
  61. if (cc.sys.os == cc.sys.OS_ANDROID) {
  62. gData.appData.updateDeviceInfo(info);
  63. }
  64. else if (cc.sys.os == cc.sys.OS_IOS) {
  65. }
  66. }
  67. /** 获取手机授权 */
  68. public static checkPermission() {
  69. if (CC_DEBUG) {
  70. gData.appData.mac = '07:16:ec:c3:d3:55,79:46:dc:dd:b7:13';
  71. gData.appData.machineInfo.mac = gData.appData.mac;
  72. gData.appData.getDeviceInfoCompelete = true;
  73. }
  74. if (cc.sys.os == cc.sys.OS_ANDROID) {
  75. this.callStaticMethod(this._JSB_ANDROID_PATH, "checkPermission", "()V");
  76. }
  77. else if (cc.sys.os == cc.sys.OS_IOS) {
  78. jsb.reflection.callStaticMethod("GameConfig", "checkPermission:", "");
  79. }
  80. }
  81. /**
  82. * 获取设备信息
  83. * @description 自定义功能 CocosToJava
  84. */
  85. public static getDeviceInfo() {
  86. let deviceInfo = "";
  87. if (cc.sys.os == cc.sys.OS_ANDROID) {
  88. deviceInfo = this.callStaticMethod(this._JSB_ANDROID_PATH, "getDeviceInfo", "()Ljava/lang/String;");
  89. console.log("===[JsbSystem] getDeviceInfo ", deviceInfo);
  90. gData.appData.updateDeviceInfo(deviceInfo);
  91. }
  92. else if (cc.sys.os == cc.sys.OS_IOS) {
  93. this.callStaticMethod(this._JSB_IOS_PATH, "getDeviceInfo", "");
  94. }
  95. else {
  96. gData.appData.getDeviceInfoCompelete = true;
  97. }
  98. }
  99. /**
  100. * 获取包名
  101. * @description 自定义功能 CocosToJava
  102. * @returns packName 包名
  103. */
  104. public static getPackageName() {
  105. let packName = '';
  106. if (cc.sys.os == cc.sys.OS_ANDROID) {
  107. packName = this.callStaticMethod(this._JSB_ANDROID_PATH, "getPackageName", "()Ljava/lang/String;");
  108. }
  109. else if (cc.sys.os == cc.sys.OS_IOS) {
  110. packName = this.callStaticMethod("CsjAdReward", "getPackageName", "");
  111. }
  112. return packName;
  113. }
  114. /**
  115. * 获取appid 和 配置version
  116. * @description 自定义功能 CocosToJava
  117. * @returns appid
  118. */
  119. public static getWxAppId() {
  120. let unicodeStr = "";
  121. if (cc.sys.os == cc.sys.OS_ANDROID) {
  122. unicodeStr = this.callStaticMethod(this._JSB_ANDROID_PATH, "getWxAppId", "()Ljava/lang/String;");
  123. }
  124. else if (cc.sys.os == cc.sys.OS_IOS) {
  125. unicodeStr = this.callStaticMethod("CsjAdReward", "getWxAppId", "",);
  126. }
  127. let unicodeArr = unicodeStr.split(';');
  128. if (unicodeArr) {
  129. gData.appData.appId = unicodeArr[0];
  130. gData.appData.version = unicodeArr[1];
  131. }
  132. if (CC_DEBUG) {
  133. //gData.appData.appId = "wx3c0cc2f730c5ad5a";
  134. //gData.appData.version = "1.0.0";
  135. gData.appData.appId = "wxd98fe9d52af10e59";
  136. gData.appData.version = "1.1.5";
  137. }
  138. // console.log('gData.appData ', unicodeStr)
  139. // console.log('gData.appData.appId ', gData.appData.appId)
  140. // console.log('gData.appData.version ', gData.appData.version)
  141. }
  142. /**
  143. * 获取广告渠道和相关id
  144. * @description 自定义功能 CocosToJava
  145. * @returns str
  146. */
  147. public static getAdvertisingChannel(): string {
  148. let str = "";
  149. if (cc.sys.os == cc.sys.OS_ANDROID) {
  150. str = this.callStaticMethod(this._JSB_ANDROID_PATH, "getAdvertisingChannel", "()Ljava/lang/String;");
  151. }
  152. else if (cc.sys.os == cc.sys.OS_IOS) {
  153. str = this.callStaticMethod("CsjAdReward", "AdvertisingChannel", "");
  154. }
  155. let arr = str.split(',')
  156. gData.warnTipData.AdIDArr = arr.slice(3);
  157. return str;
  158. }
  159. /** 显示开屏 */
  160. static showSplash() {
  161. // mk.data.sendDataEvent('slashAd', '开屏')
  162. if (cc.sys.os == cc.sys.OS_ANDROID) {
  163. this.callStaticMethod(this._JSB_ANDROID_PATH, "showSplash", "()V");
  164. }
  165. else if (cc.sys.os == cc.sys.OS_IOS) {
  166. jsb.reflection.callStaticMethod("GameConfig", "showSplash:", "");
  167. }
  168. }
  169. /**
  170. * 复制到剪切板
  171. * @description Andorid功能 CocosToJava
  172. * @param str 剪切板字符串内容
  173. */
  174. public static setClipboard(str: string) {
  175. if (cc.sys.os == cc.sys.OS_ANDROID) {
  176. this.callStaticMethod(this._JSB_ANDROID_PATH, "setClipboard", "(Ljava/lang/String;)V", str);
  177. }
  178. else if (cc.sys.os == cc.sys.OS_IOS) {
  179. }
  180. else if (cc.sys.isBrowser) {
  181. var input = str;
  182. const el: any = document.createElement('textarea');
  183. el.value = input;
  184. el.setAttribute('readonly', '');
  185. el.style.contain = 'strict';
  186. el.style.position = 'absolute';
  187. el.style.left = '-9999px';
  188. el.style.fontSize = '12pt';
  189. const selection = getSelection();
  190. var originalRange: any = false;
  191. if (selection.rangeCount > 0) {
  192. originalRange = selection.getRangeAt(0);
  193. }
  194. document.body.appendChild(el);
  195. el.select();
  196. el.selectionStart = 0;
  197. el.selectionEnd = input.length;
  198. var success = false;
  199. try {
  200. success = document.execCommand('copy');
  201. } catch (err) { }
  202. document.body.removeChild(el);
  203. if (originalRange) {
  204. selection.removeAllRanges();
  205. selection.addRange(originalRange);
  206. }
  207. return success;
  208. }
  209. }
  210. /**
  211. * 请求用户授权
  212. * @description Andorid功能 CocosToJava
  213. */
  214. public static requestPermission() {
  215. if (cc.sys.os == cc.sys.OS_ANDROID) {
  216. this.callStaticMethod(this._JSB_ANDROID_PATH, "requestPermission", "()V");
  217. }
  218. else if (cc.sys.os == cc.sys.OS_IOS) {
  219. this.callStaticMethod("AppController", "requestPermission", "");
  220. }
  221. }
  222. /**
  223. * 获取安卓的版本号
  224. * @description Andorid功能 CocosToJava
  225. */
  226. public static getAppVersion() {
  227. if (cc.sys.os == cc.sys.OS_ANDROID) {
  228. this.callStaticMethod(this._JSB_ANDROID_PATH, "getAppVersion", "()V");
  229. }
  230. else if (cc.sys.os == cc.sys.OS_IOS) {
  231. this.callStaticMethod("AppController", "getAppVersion", "");
  232. }
  233. }
  234. /**
  235. * 设置安卓得版本号
  236. * @description Andorid功能 JavaToCocos
  237. * @param appVersion app版本号
  238. */
  239. public static setAppVersion(appVersion: string) {
  240. if (cc.sys.os == cc.sys.OS_ANDROID) {
  241. // GameConst.appVersion = appVersion;
  242. }
  243. else if (cc.sys.os == cc.sys.OS_IOS) {
  244. }
  245. }
  246. /**
  247. * 安装apk
  248. * @description Andorid功能 CocosToJava
  249. * @param apkName apkName
  250. */
  251. public static installApk(apkName: string) {
  252. let fullPath = this.getWritablePath() + apkName + ".apk";
  253. if (cc.sys.os == cc.sys.OS_ANDROID) {
  254. this.callStaticMethod(this._JSB_ANDROID_PATH, "installApk", "(Ljava/lang/String;)V", fullPath);
  255. }
  256. else if (cc.sys.os == cc.sys.OS_IOS) {
  257. this.callStaticMethod("GameConfig", "installApk:", "");
  258. }
  259. }
  260. /**
  261. * 是否可以启动游戏
  262. * @param packageName 包名
  263. * @param start 如存在是否启动
  264. * @returns ifCan
  265. */
  266. public static ifCanStartGame(packageName: string, start: boolean): boolean {
  267. let isCan = false;
  268. if (cc.sys.os == cc.sys.OS_ANDROID) {
  269. isCan = this.callStaticMethod(this._JSB_ANDROID_PATH, "isStartGame", "(Ljava/lang/String;Z)Z", packageName, start);
  270. return isCan;
  271. }
  272. else if (cc.sys.os == cc.sys.OS_IOS) {
  273. isCan = this.callStaticMethod("GameConfig", "installApk:", "");
  274. }
  275. return isCan;
  276. }
  277. /**
  278. * 数数事件注册
  279. * @description 数数SDK功能
  280. * @returns
  281. */
  282. static setTAEventRegister() {
  283. if (cc.sys.os == cc.sys.OS_ANDROID) {
  284. this.callStaticMethod(this._JSB_ANDROID_PATH, "setTAEventRegister", "()V");
  285. }
  286. else if (cc.sys.os == cc.sys.OS_IOS) {
  287. }
  288. }
  289. /**
  290. * 发送自定义事件 自定义功能 CocosToJava
  291. * @description 发送统计事件
  292. * @param key 事件的key值
  293. * @param value 事件的value值
  294. */
  295. public static sendEvent(key: string, value: string) {
  296. if (cc.sys.os == cc.sys.OS_ANDROID) {
  297. this.callStaticMethod(this._JSB_ANDROID_PATH, "sendEvent", "(Ljava/lang/String;Ljava/lang/String;)V", key, value);
  298. }
  299. else if (cc.sys.os == cc.sys.OS_IOS) {
  300. }
  301. }
  302. /**
  303. * 发送自定义事件 自定义功能 CocosToJava
  304. * @description 发送统计事件
  305. * @param key 事件的key值
  306. * @param value 事件的value值
  307. */
  308. public static sendEventValue(key: string, value: string, value1: number) {
  309. if (cc.sys.os == cc.sys.OS_ANDROID) {
  310. this.callStaticMethod(this._JSB_ANDROID_PATH, "sendEventValue", "(Ljava/lang/String;Ljava/lang/String;F)V", key, value, value1);
  311. }
  312. else if (cc.sys.os == cc.sys.OS_IOS) {
  313. }
  314. }
  315. /**
  316. * 设置人物属性
  317. * @param type 0 set 1 add
  318. * @param property 属性名
  319. * @param value 数值
  320. */
  321. public static setTAEventUser(type: number, property: string, value: number) {
  322. if (cc.sys.os == cc.sys.OS_ANDROID) {
  323. this.callStaticMethod(this._JSB_ANDROID_PATH, "setTAEventUser", "(ILjava/lang/String;F)V", type, property, value);
  324. }
  325. else if (cc.sys.os == cc.sys.OS_IOS) {
  326. }
  327. }
  328. /**
  329. * 设置人物属性
  330. * @param type 0 set 1 add
  331. * @param property 属性名
  332. * @param value 数值
  333. */
  334. public static setTAEventUserStr(type: number, property: string, value: string) {
  335. if (cc.sys.os == cc.sys.OS_ANDROID) {
  336. this.callStaticMethod(this._JSB_ANDROID_PATH, "setTAEventUserStr", "(ILjava/lang/String;Ljava/lang/String;)V", type, property, value);
  337. }
  338. else if (cc.sys.os == cc.sys.OS_IOS) {
  339. }
  340. }
  341. /** 设置人物uin到数数
  342. * id uin
  343. */
  344. public static setTAUserID(id: string) {
  345. if (cc.sys.os == cc.sys.OS_ANDROID) {
  346. this.callStaticMethod(this._JSB_ANDROID_PATH, "setTAUserID", "(Ljava/lang/String;)V", id);
  347. }
  348. else if (cc.sys.os == cc.sys.OS_IOS) {
  349. }
  350. }
  351. /**
  352. * 微信授权
  353. * @description 微信SDK功能 CocosToJava
  354. */
  355. public static WxAuth() {
  356. if (cc.sys.os == cc.sys.OS_ANDROID) {
  357. this.callStaticMethod(this._JSB_ANDROID_PATH, "WxAuth", "()V");
  358. }
  359. else if (cc.sys.os == cc.sys.OS_IOS) {
  360. this.callStaticMethod("AppController", "WxAuth", "");
  361. }
  362. }
  363. /**
  364. * 获取授权code
  365. * @description 微信SDK功能 JavaToCocos
  366. * @param code 微信code(Java返回)
  367. */
  368. public static onGetWxAccessCode(code) {
  369. // 暂时注释,需要网络通信
  370. gData.wechatData.code = code;
  371. console.log("=== gData.wechatData.code", gData.wechatData.code);
  372. mk.tip.pop("微信登陆成功,快提现吧!");
  373. gData.loginData.wxLogin();
  374. let value = mk.storage.getStorage('loadingAuth');
  375. if (!value) {
  376. mk.storage.setStorage('loadingAuth', 1);
  377. mk.data.sendDataEvent(DataEventId.loading, '微信授权登录成功');
  378. }
  379. mk.ui.closePanel('authUI');
  380. }
  381. /**
  382. * 微信打开小游戏
  383. * @description 微信SDK功能 CocosToJava
  384. */
  385. public static OpenMiniGame() {
  386. if (cc.sys.os == cc.sys.OS_ANDROID) {
  387. this.callStaticMethod(this._JSB_ANDROID_PATH, "OpenMiniGame", "()V");
  388. }
  389. else if (cc.sys.os == cc.sys.OS_IOS) {
  390. this.callStaticMethod("AppController", "WxAuth", "");
  391. }
  392. }
  393. /**
  394. * 分享成微信小游戏
  395. * @description 微信SDK功能 CocosToJava
  396. */
  397. public static ShareToMiniGame() {
  398. if (cc.sys.os == cc.sys.OS_ANDROID) {
  399. this.callStaticMethod(this._JSB_ANDROID_PATH, "ShareToMiniGame", "()V");
  400. }
  401. else if (cc.sys.os == cc.sys.OS_IOS) {
  402. this.callStaticMethod("AppController", "WxAuth", "");
  403. }
  404. }
  405. /**
  406. * 分享图片
  407. * @description 微信SDK功能 CocosToJava
  408. */
  409. public static sharePic() {
  410. if (cc.sys.platform == cc.sys.WECHAT_GAME) {
  411. return
  412. }
  413. if (cc.sys.os == cc.sys.OS_ANDROID) {
  414. jsb.reflection.callStaticMethod(this._JSB_ANDROID_PATH, "sharePic", "()V");
  415. }
  416. else if (cc.sys.os == cc.sys.OS_IOS) {
  417. jsb.reflection.callStaticMethod("GameConfig", "sharePic:", "");
  418. }
  419. }
  420. /** 打开微信 */
  421. public static openWx() {
  422. if (cc.sys.os == cc.sys.OS_ANDROID) {
  423. this.callStaticMethod(this._JSB_ANDROID_PATH, "openWx", "()V");
  424. }
  425. else if (cc.sys.os == cc.sys.OS_IOS) {
  426. this.callStaticMethod("AppController", "openWx", "");
  427. }
  428. }
  429. /** 下载文件
  430. * @param url 下载地址
  431. * @param fileName 存储文件名称
  432. * @param successCb 成功回调
  433. * @param failCb 失败回调
  434. * @param progressCb 下载进度回调
  435. */
  436. public static downFile2Local(url, fileName, successCb, failCb, progressCb): any {
  437. var fullPath = jsb.fileUtils.getWritablePath() + fileName
  438. if (jsb) {
  439. var downloader = new jsb.Downloader();
  440. downloader.setOnFileTaskSuccess(function () {
  441. console.log("DownLoadM setOnFileTaskSuccess", "")
  442. if (successCb) {
  443. console.log("DownLoadM result... ", jsb.fileUtils.isFileExist(fullPath))
  444. console.log("DownLoadM setOnFileTaskSuccess fullPath...", fullPath)
  445. successCb(fullPath);
  446. }
  447. });
  448. downloader.setOnTaskError(function (task: any, errorCode: number, errorCodeInternal: number, errorStr: string) {
  449. console.log("DownLoadM setOnTaskError", errorCode + " ; " + errorCodeInternal + " ; " + errorStr)
  450. if (failCb) {
  451. failCb(fullPath);
  452. }
  453. });
  454. downloader.setOnTaskProgress(function (task: any, bytesReceived: number, totalBytesReceived: number, totalBytesExpected: number) {
  455. console.log("DownLoadM", bytesReceived + " ; " + totalBytesReceived + " ; " + totalBytesExpected)
  456. if (progressCb) {
  457. progressCb(bytesReceived, totalBytesReceived, totalBytesExpected)
  458. }
  459. });
  460. downloader.createDownloadFileTask(url, fullPath);//创建下载任务
  461. return downloader
  462. }
  463. }
  464. private static singleClick = true;
  465. private static splashADid = '';
  466. /** 上传开屏广告星云埋点 */
  467. public static updateSplashAdLog(info) {
  468. let arr = info.split('#')
  469. // console.log('updateSplashAdLog placementId ', arr[0])
  470. // console.log('updateSplashAdLog callbackInfo ', arr[1])
  471. let data = JSON.parse(arr[1])
  472. gData.adData.updateADLog(6, arr[0], data);
  473. this.splashADid = arr[0];
  474. let times = mk.storage.getStorage('ad_openEcpm');
  475. if (!times) {
  476. times = 1;
  477. }
  478. else {
  479. times++;
  480. }
  481. mk.storage.setStorage('ad_openEcpm', times);
  482. if (times <= 300) {
  483. if (times <= 50) {
  484. mk.data.sendDataEventValue(DataEventId.ad_openEcpm, `ad_video_ecpm${times}`, data.adsource_price);
  485. }
  486. else if (times % 10 == 0) {
  487. mk.data.sendDataEventValue(DataEventId.ad_openEcpm, `ad_video_ecpm${times}`, data.adsource_price);
  488. }
  489. }
  490. }
  491. public static clickSplash() {
  492. mk.data.sendDataEvent(DataEventId.Ad_click, 'splash_click');
  493. gData.adData.updateADLog(54, this.splashADid);
  494. if (this.singleClick) {
  495. this.singleClick = false;
  496. gData.adData.updateADLog(74, this.splashADid);
  497. }
  498. }
  499. /** 获取阿里风控设备token */
  500. public static getAliRiskDeviceToken() {
  501. let token = '';
  502. if (cc.sys.os == cc.sys.OS_ANDROID) {
  503. token = this.callStaticMethod(this._JSB_ANDROID_PATH, "getAliDeviceToken", "()Ljava/lang/String;");
  504. }
  505. else if (cc.sys.os == cc.sys.OS_IOS) {
  506. token = this.callStaticMethod("AppController", "openWx", "");
  507. }
  508. return token;
  509. }
  510. public static backKeyCallBack() {
  511. if (this.callBack) {
  512. this.callBack();
  513. }
  514. }
  515. public static systemExit() {
  516. if (cc.sys.os == cc.sys.OS_ANDROID) {
  517. this.callStaticMethod(this._JSB_ANDROID_PATH, "systemExit", "()V");
  518. }
  519. }
  520. public static changeNetState(state: string) {
  521. if (state == '1') {
  522. mk.ui.closePanel('NetDisConnect');
  523. }
  524. else if (state == '0') {
  525. mk.ui.openPanel('module/netDisconnect/NetDisConnect');
  526. }
  527. }
  528. //分享链接
  529. public static shareInviteUrl(url: string, title: string, describe: string, imgUrl: string) {
  530. if (cc.sys.platform == cc.sys.WECHAT_GAME) {
  531. return
  532. }
  533. if (cc.sys.os == cc.sys.OS_ANDROID) {
  534. jsb.reflection.callStaticMethod(this._JSB_ANDROID_PATH, "shareInviteUrl",
  535. "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V", url, title, describe, imgUrl);
  536. }
  537. else if (cc.sys.os == cc.sys.OS_IOS) {
  538. //to do
  539. // jsb.reflection.callStaticMethod("GameConfig", "sharePic:", "");
  540. }
  541. }
  542. /** 初始化ysdk */
  543. public static ysdkInit() {
  544. if (cc.sys.os == cc.sys.OS_ANDROID) {
  545. this.callStaticMethod(this._JSB_ANDROID_PATH_JSDK, "init", "()V");
  546. }
  547. else if (cc.sys.os == cc.sys.OS_IOS) {
  548. this.callStaticMethod("AppController", "init", "");
  549. }
  550. }
  551. /** ysdk登录 */
  552. public static autologin() {
  553. if (cc.sys.os == cc.sys.OS_ANDROID) {
  554. this.callStaticMethod(this._JSB_ANDROID_PATH_JSDK, "autologin", "()V");
  555. }
  556. else if (cc.sys.os == cc.sys.OS_IOS) {
  557. this.callStaticMethod("AppController", "autologin", "");
  558. }
  559. }
  560. public static ysdkAuthSuccess() {
  561. gData.loginData.passAnti = true;
  562. mk.data.setTAEventUserStr(0, 'realName', "认证通过人数");
  563. //mk.data.sendDataEvent(DataEventId.realName, '认证通过人数');
  564. }
  565. /** 统计时长 */
  566. public static updateActivateLog(sessionDuration) {
  567. console.log('test>>> updateActivateLog ', sessionDuration)
  568. let data = {
  569. 'appId': gData.appData.appId,
  570. 'uin': gData.loginData.uin,
  571. 'sessionDuration': sessionDuration
  572. }
  573. mk.http.sendData('activateLog', data);
  574. }
  575. /** 屏蔽对应广告位的广告源 */
  576. public static setFilterAdSourceIdList(adID: string, adSourceStr: string) {
  577. if (cc.sys.os == cc.sys.OS_ANDROID) {
  578. jsb.reflection.callStaticMethod(this._JSB_ANDROID_PATH, "setFilterAdSourceIdList", "(Ljava/lang/String;Ljava/lang/String;)V", adID, adSourceStr);
  579. }
  580. else if (cc.sys.os == cc.sys.OS_IOS) {
  581. jsb.reflection.callStaticMethod("GameConfig", "setFilterAdSourceIdList:", "");
  582. }
  583. }
  584. /** 数盟获取设备id */
  585. public static getQueryID() {
  586. if (cc.sys.os == cc.sys.OS_ANDROID) {
  587. jsb.reflection.callStaticMethod(this._JSB_ANDROID_PATH, "getQueryID", "()V");
  588. }
  589. else if (cc.sys.os == cc.sys.OS_IOS) {
  590. jsb.reflection.callStaticMethod("GameConfig", "getQueryID:", "");
  591. }
  592. }
  593. /** 设置数盟设备id */
  594. public static setShuzilmEquipID(szlm_did: string) {
  595. mk.shuzilmM.setShuzilmEquipID(szlm_did);
  596. }
  597. /** 设置同盾设备id */
  598. public static setTDEquipID(equipID) {
  599. mk.tongdunM.setTDEquipID(equipID);
  600. }
  601. /** 同盾初始化 */
  602. public static tongdunInit() {
  603. if (cc.sys.os == cc.sys.OS_ANDROID) {
  604. jsb.reflection.callStaticMethod(this._JSB_ANDROID_PATH, "tongdunInit", "()V");
  605. }
  606. else if (cc.sys.os == cc.sys.OS_IOS) {
  607. jsb.reflection.callStaticMethod("GameConfig", "tongdunInit:", "");
  608. }
  609. }
  610. }
  611. window['JsbMgr'] = JsbSystem