8970965a-7ad7-4e60-91f5-dff13fa490af.js 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765
  1. "use strict";
  2. cc._RF.push(module, '89709ZaetdOYJH13/E/pJCv', 'YZ_Tool_Douyin');
  3. // common-plugin/Scripts/YZ_Tool_Douyin.ts
  4. "use strict";
  5. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  6. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  7. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  8. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  9. return c > 3 && r && Object.defineProperty(target, key, r), r;
  10. };
  11. var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
  12. function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
  13. return new (P || (P = Promise))(function (resolve, reject) {
  14. function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
  15. function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
  16. function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
  17. step((generator = generator.apply(thisArg, _arguments || [])).next());
  18. });
  19. };
  20. var __generator = (this && this.__generator) || function (thisArg, body) {
  21. var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
  22. return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
  23. function verb(n) { return function (v) { return step([n, v]); }; }
  24. function step(op) {
  25. if (f) throw new TypeError("Generator is already executing.");
  26. while (_) try {
  27. if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
  28. if (y = 0, t) op = [op[0] & 2, t.value];
  29. switch (op[0]) {
  30. case 0: case 1: t = op; break;
  31. case 4: _.label++; return { value: op[1], done: false };
  32. case 5: _.label++; y = op[1]; op = [0]; continue;
  33. case 7: op = _.ops.pop(); _.trys.pop(); continue;
  34. default:
  35. if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
  36. if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
  37. if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
  38. if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
  39. if (t[2]) _.ops.pop();
  40. _.trys.pop(); continue;
  41. }
  42. op = body.call(thisArg, _);
  43. } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
  44. if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
  45. }
  46. };
  47. Object.defineProperty(exports, "__esModule", { value: true });
  48. var PlatUtils_1 = require("./PlatUtils");
  49. var Utils_1 = require("./Utils");
  50. var YZ_Constant_1 = require("./YZ_Constant");
  51. var YZ_LocalStorage_1 = require("./YZ_LocalStorage");
  52. var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
  53. var ST_ServerUrl = "https://apps.youlesp.com/gss?";
  54. var POST_ServerUrl = "https://report.youletd.com/gss?";
  55. // 默认配置
  56. var ST_DefaultServerConfig = "";
  57. var YZ_Tool_Douyin = /** @class */ (function () {
  58. function YZ_Tool_Douyin() {
  59. this._recorder = null;
  60. this._videoPath = null;
  61. this._shareCallback = null;
  62. this.recorderStarTime = 0; //开始录屏时间
  63. this.isAutoShare = true; //是否自动分享
  64. this.isClickEnd = false;
  65. this.isNewsArticleLite = false; //是否头条极速版
  66. //@ts-ignore
  67. this.tt = window.tt;
  68. /**
  69. * 服务器配置信息
  70. */
  71. this._serverConfig = null;
  72. //设备UID
  73. this._uid = "0";
  74. //服务器返回UID
  75. this._service_uid = "0";
  76. this._loginTime = 0;
  77. this._loginInterval = 30;
  78. this._reportLoginTime = 0;
  79. this._reportLoginInterval = 30;
  80. this.isReport = false;
  81. this._jumpIds = "";
  82. this._sysInfo = null;
  83. //是否是点完暂停按钮后自动分享得录屏
  84. this.is_auto_share_video = false;
  85. /**
  86. * 自动分享次数
  87. */
  88. this.recored_share_count = 0;
  89. this.appLaunchOptions = [];
  90. }
  91. Object.defineProperty(YZ_Tool_Douyin.prototype, "ServerConfig", {
  92. get: function () {
  93. return this._serverConfig;
  94. },
  95. enumerable: false,
  96. configurable: true
  97. });
  98. /**
  99. * 当前版本号
  100. */
  101. YZ_Tool_Douyin.prototype.gameVersion = function () {
  102. return Utils_1.utils.config.douyinconfig.version;
  103. };
  104. Object.defineProperty(YZ_Tool_Douyin.prototype, "uid", {
  105. get: function () {
  106. // if (this._service_uid != "0") return this._uid;
  107. // this._login();
  108. return "0";
  109. },
  110. enumerable: false,
  111. configurable: true
  112. });
  113. Object.defineProperty(YZ_Tool_Douyin.prototype, "serviceId", {
  114. /**
  115. * 服务器返回UID
  116. */
  117. get: function () {
  118. if (this._service_uid != "0")
  119. return this._service_uid;
  120. this.reportLogin();
  121. return "0";
  122. },
  123. enumerable: false,
  124. configurable: true
  125. });
  126. YZ_Tool_Douyin.prototype._login = function () {
  127. return __awaiter(this, void 0, void 0, function () {
  128. var curTime, interval, self;
  129. return __generator(this, function (_a) {
  130. curTime = new Date().getTime();
  131. interval = (curTime - this._loginTime) / 1000;
  132. if (interval > 0 && interval < 30) {
  133. Utils_1.utils.showLog("\u767B\u5F55\u8BF7\u6C42\u95F4\u9694\u5C0F\u4E8E\uFF1A" + this._loginInterval + "\u79D2");
  134. return [2 /*return*/];
  135. }
  136. this._loginTime = curTime;
  137. self = this;
  138. Utils_1.utils.showLog("douying暂时不获取uid,uid全部为0");
  139. this._uid = "0";
  140. return [2 /*return*/];
  141. });
  142. });
  143. };
  144. YZ_Tool_Douyin.prototype.login = function () {
  145. var _this = this;
  146. Utils_1.utils.showLog("douying login");
  147. //@ts-ignore
  148. tt.login({
  149. withRealNameAuthenticationInfo: true,
  150. success: function (_res) {
  151. Utils_1.utils.showLog("登录成功");
  152. // 调用 getUserInfo 前, 请确保登录成功
  153. //实名认证需要用户点击触发
  154. //@ts-ignore
  155. // 获取用户信息
  156. tt.getUserInfo({
  157. // withCredentials: true,
  158. withRealNameAuthenticationInfo: true,
  159. success: function (res) {
  160. Utils_1.utils.showLog("getUserInfo \u8C03\u7528\u6210\u529F", res.userInfo);
  161. if (res.userInfo) {
  162. if (res.userInfo.realNameAuthenticationStatus && res.userInfo.realNameAuthenticationStatus == "uncertified") {
  163. Utils_1.utils.showLog("getUserInfo \u7528\u6237\u672A\u8FDB\u884C\u5B9E\u540D\u5236\uFF01");
  164. _this.realNameAuth();
  165. }
  166. else if (res.userInfo.realNameAuthenticationStatus && res.userInfo.realNameAuthenticationStatus == "certified") {
  167. Utils_1.utils.showLog("getUserInfo \u7528\u6237\u5DF2\u5B9E\u540D\u5236\uFF01");
  168. cc.game.emit(YZ_Constant_1.default.ST_LOGIN_SUCCESS);
  169. }
  170. else {
  171. cc.game.emit(YZ_Constant_1.default.ST_LOGIN_FAIL);
  172. }
  173. }
  174. },
  175. fail: function (res) {
  176. Utils_1.utils.showLog("getUserInfo \u8C03\u7528\u5931\u8D25", res.errMsg);
  177. }
  178. });
  179. },
  180. fail: function () {
  181. cc.game.emit(YZ_Constant_1.default.ST_LOGIN_FAIL);
  182. _this.showToast("登录失败!");
  183. }
  184. });
  185. };
  186. YZ_Tool_Douyin.prototype.realNameAuth = function () {
  187. var _this = this;
  188. Utils_1.utils.showLog("douying realNameAuth");
  189. //@ts-ignore
  190. tt.authenticateRealName({
  191. success: function (_res) {
  192. Utils_1.utils.showLog("用户实名认证成功");
  193. cc.game.emit(YZ_Constant_1.default.ST_LOGIN_SUCCESS);
  194. },
  195. fail: function (res) {
  196. _this.showToast("实名制认证失败,请稍后重试!");
  197. cc.game.emit(YZ_Constant_1.default.ST_LOGIN_FAIL);
  198. Utils_1.utils.showLog("用户实名认证失败", res.errMsg);
  199. },
  200. });
  201. };
  202. /**
  203. * 上报登录接口获取UID
  204. */
  205. YZ_Tool_Douyin.prototype.reportLogin = function () {
  206. var _this = this;
  207. if (this.isReport)
  208. return;
  209. this.isReport = true;
  210. var self = this;
  211. var curTime = new Date().getTime();
  212. var interval = (curTime - self._reportLoginTime) / 1000;
  213. if (interval > 0 && interval < 30) {
  214. Utils_1.utils.showLog("\u4E0A\u62A5\u767B\u5F55\u83B7\u53D6UID\u5C0F\u4E8E\uFF1A" + self._reportLoginInterval + "\u79D2");
  215. return;
  216. }
  217. self._reportLoginTime = curTime;
  218. var method = "m=login";
  219. var url = ST_ServerUrl + method + "&device_data=0";
  220. Utils_1.utils.commomHttpRequest(url, function (ret, data) {
  221. if (ret) {
  222. if (data) {
  223. var result = JSON.parse(data);
  224. Utils_1.utils.showLog("data=" + data);
  225. Utils_1.utils.showLog("result=" + result);
  226. Utils_1.utils.showLog("result.uid=" + result.uid);
  227. if (result.uid) {
  228. self._service_uid = "" + result.uid;
  229. Utils_1.utils.showLog("服务器请求登录成功! _service_uid=" + self._service_uid);
  230. YZ_LocalStorage_1.default.setItem(YZ_Constant_1.default.ST_SERVICE_UID, self._service_uid);
  231. }
  232. }
  233. }
  234. else {
  235. Utils_1.utils.showLog("获取数据失败1");
  236. }
  237. _this.isReport = false;
  238. });
  239. };
  240. /**
  241. *
  242. * @param data 配置数据.
  243. */
  244. YZ_Tool_Douyin.prototype.init = function (data) {
  245. var _this = this;
  246. if (PlatUtils_1.default.IsDouyin) {
  247. if (data) {
  248. var configObj = JSON.parse(data);
  249. if (configObj && configObj.toutiao) {
  250. Utils_1.utils.showLog("本地配置数据:" + JSON.stringify(configObj.toutiao));
  251. ST_DefaultServerConfig = JSON.stringify(configObj.toutiao);
  252. }
  253. }
  254. this._service_uid = YZ_LocalStorage_1.default.getItem(YZ_Constant_1.default.ST_SERVICE_UID);
  255. this._service_uid = this._service_uid ? this._service_uid : "0";
  256. this._sysInfo = this.tt.getSystemInfoSync();
  257. Utils_1.utils.showLog("抖音平台信息:" + JSON.stringify(this._sysInfo));
  258. if (this._sysInfo && this._sysInfo.appName && this._sysInfo.appName == "news_article_lite") {
  259. this.isNewsArticleLite = true;
  260. }
  261. // // 拉取服务器配置
  262. // this.loadJumpIds().then(() => {
  263. // console.log("本地跳转ID加载成功!");
  264. // this._loadConfig();
  265. // }).catch((erro) => {
  266. // console.error("本地跳转ID加载失败:", erro);
  267. this._loadConfig();
  268. // })
  269. var self_1 = this;
  270. this._recorder = this.tt.getGameRecorderManager();
  271. if (this._recorder) {
  272. this._recorder.onStart(function (res) {
  273. self_1._videoPath = "";
  274. _this.isClickEnd = false;
  275. _this.is_auto_share_video = false;
  276. Utils_1.utils.isRecording = true;
  277. console.log("录屏开始>>>");
  278. Utils_1.utils.showLog('录屏开始');
  279. _this.recorderStarTime = new Date().getTime();
  280. cc.game.emit("YZ_CommonMessage", { type: "YZ_RecordStart" });
  281. });
  282. this._recorder.onStop(function (res) {
  283. Utils_1.utils.showLog("录屏结束 :" + res.videoPath);
  284. Utils_1.utils.isRecording = false;
  285. cc.game.emit("YZ_CommonMessage", { type: "YZ_RecordEnd" });
  286. var curTime = new Date().getTime();
  287. var interval = (curTime - _this.recorderStarTime) / 1000;
  288. if (interval > 3) {
  289. self_1._videoPath = res.videoPath;
  290. Utils_1.utils.showLog("录屏时间大于3秒", interval);
  291. if (_this.isAutoShare) {
  292. if (_this.isClickEnd) {
  293. _this.shareVideo();
  294. _this._shareCallback = null;
  295. _this.is_auto_share_video = true;
  296. }
  297. else if (Utils_1.utils.checkResultShow(1)) {
  298. Utils_1.utils.showLog("满足自动分享条件,弹出分享窗口!");
  299. if (Utils_1.utils.rewardCloseFunc == null) {
  300. Utils_1.utils.rewardValue = 0;
  301. Utils_1.utils.showShareRecordPanel();
  302. }
  303. }
  304. else if (interval > 100) {
  305. if (Utils_1.utils.rewardCloseFunc == null) {
  306. Utils_1.utils.rewardValue = 0;
  307. Utils_1.utils.showShareRecordPanel();
  308. }
  309. }
  310. }
  311. else {
  312. _this.isAutoShare = true;
  313. }
  314. }
  315. else {
  316. //@ts-ignore
  317. if (_this.isClickEnd) {
  318. _this.tt.showToast({
  319. title: "录屏时间小于3秒!",
  320. icon: "fail",
  321. duration: 2000,
  322. success: function (res) {
  323. console.log("" + res);
  324. },
  325. fail: function (res) {
  326. console.log("showToast\u8C03\u7528\u5931\u8D25");
  327. }
  328. });
  329. }
  330. self_1._videoPath = "";
  331. Utils_1.utils.showLog("录屏时间小于3秒,录录屏地址置空!");
  332. }
  333. });
  334. }
  335. // 开启右上角分享按钮
  336. //@ts-ignore
  337. this.tt.showShareMenu({
  338. withShareTicket: false
  339. });
  340. //@ts-ignore
  341. this.tt.onShareAppMessage(function (res) {
  342. return self_1._getShareInfo();
  343. });
  344. Utils_1.utils.registerServerInitEvent(function () {
  345. if (_this.ServerConfig.add_favorite) {
  346. setTimeout(function () {
  347. Utils_1.utils.showLog("延迟调用添加搜藏!!");
  348. _this.showFavoriteGuide();
  349. }, _this.ServerConfig.add_favorite * 1000);
  350. }
  351. }, this);
  352. }
  353. };
  354. /**
  355. * 添加搜藏
  356. */
  357. YZ_Tool_Douyin.prototype.showFavoriteGuide = function () {
  358. if (this.tt.showFavoriteGuide) {
  359. this.tt.showFavoriteGuide({
  360. type: "bar",
  361. content: "一键添加到我的小程序",
  362. position: this.ServerConfig.favorite_type ? this.ServerConfig.favorite_type : "bottom",
  363. success: function (res) {
  364. Utils_1.utils.showLog("引导组件展示成功");
  365. },
  366. fail: function (res) {
  367. Utils_1.utils.showLog("引导组件展示失败:ero=" + JSON.stringify(res));
  368. },
  369. });
  370. }
  371. else {
  372. Utils_1.utils.showLog("当前头条版本不支持添加收藏!");
  373. }
  374. };
  375. YZ_Tool_Douyin.prototype.loadJumpIds = function () {
  376. var _this = this;
  377. return new Promise(function (resolve, reject) {
  378. cc.loader.load("game.json", function (err, res) {
  379. if (!err) {
  380. res.ttNavigateToMiniGameAppIdList.forEach(function (element) {
  381. _this._jumpIds += element + ",";
  382. });
  383. _this._jumpIds.substring(0, _this._jumpIds.lastIndexOf(","));
  384. //@ts-ignore
  385. resolve();
  386. }
  387. reject(err);
  388. });
  389. });
  390. };
  391. YZ_Tool_Douyin.prototype._loadConfig = function () {
  392. var _this = this;
  393. if (PlatUtils_1.default.IsDouyin) {
  394. var method = "m=g";
  395. Utils_1.utils.commomHttpRequest(ST_ServerUrl + method + ("&jump_id=" + this._jumpIds), function (ret, data) {
  396. if (ret && data) {
  397. Utils_1.utils.showLog("抖音服务器配置数据获取成功: data = " + data);
  398. var result = JSON.parse(data);
  399. if (!Utils_1.utils.DebugLoacalConfig) {
  400. _this._serverConfig = result;
  401. }
  402. else {
  403. Utils_1.utils.showLog("调试模式,使用本地配置!");
  404. }
  405. }
  406. else {
  407. Utils_1.utils.showLog("抖音服务器配置数据获取失败, 使用本地配置!");
  408. }
  409. if (!_this.ServerConfig) {
  410. _this._serverConfig = JSON.parse(ST_DefaultServerConfig);
  411. }
  412. else {
  413. if (_this.ServerConfig.is_local_pos_id == "false") {
  414. Utils_1.utils.showLog("使用服务器下发的广告ID");
  415. Utils_1.utils.config.douyinconfig.bannerId = _this.ServerConfig.banner_pos_id;
  416. Utils_1.utils.config.douyinconfig.insertId = _this.ServerConfig.intersititia_pos_id;
  417. Utils_1.utils.config.douyinconfig.videoId = _this.ServerConfig.video_pos_id;
  418. }
  419. if (_this._serverConfig.shares && _this._serverConfig.shares.sy_title) {
  420. Utils_1.utils.config.otherconfig.shareTitle = _this._serverConfig.shares.sy_title;
  421. }
  422. if (_this._serverConfig.shares && _this._serverConfig.shares.sy_img) {
  423. Utils_1.utils.config.otherconfig.shareImgUrl = _this._serverConfig.shares.sy_img;
  424. }
  425. }
  426. Utils_1.utils.emitServerInitEvent();
  427. });
  428. }
  429. };
  430. /**
  431. * 开始录屏
  432. */
  433. YZ_Tool_Douyin.prototype.recordStart = function () {
  434. if (PlatUtils_1.default.IsDouyin) {
  435. if (this._recorder) {
  436. this._recorder.start({
  437. duration: this.ServerConfig.record_duration ? this.ServerConfig.record_duration : 120
  438. });
  439. }
  440. }
  441. };
  442. /**
  443. * 结束录屏
  444. */
  445. YZ_Tool_Douyin.prototype.recordEnd = function () {
  446. if (PlatUtils_1.default.IsDouyin) {
  447. this._recorder.stop();
  448. }
  449. };
  450. /**
  451. * 分享,有录屏就分享录屏,没有录屏就分享图片
  452. */
  453. YZ_Tool_Douyin.prototype.share = function (callback) {
  454. if (PlatUtils_1.default.IsDouyin) {
  455. this._shareCallback = callback;
  456. if (this._videoPath && !Utils_1.utils.isRecording) {
  457. this.shareVideo();
  458. }
  459. else {
  460. this.shareImage();
  461. }
  462. }
  463. };
  464. /**
  465. * 分享录屏
  466. */
  467. YZ_Tool_Douyin.prototype.shareVideo = function () {
  468. if (PlatUtils_1.default.IsDouyin) {
  469. if (this._videoPath) {
  470. var self_2 = this;
  471. //@ts-ignore
  472. this.tt.shareAppMessage({
  473. channel: 'video',
  474. extra: {
  475. videoPath: self_2._videoPath // 可用录屏得到的视频地址
  476. },
  477. success: function () {
  478. cc.log('视频分享成功!');
  479. if (self_2._shareCallback) {
  480. self_2._shareCallback(true);
  481. }
  482. },
  483. fail: function (e) {
  484. cc.log('视频分享失败!', JSON.stringify(e));
  485. self_2._videoPath = "";
  486. var msg = "分享失败!";
  487. if (e && e.errMsg) {
  488. msg = e.errMsg;
  489. if (msg.indexOf("fail") != -1) {
  490. console.log(self_2._sysInfo);
  491. if (self_2._sysInfo.appName == "XiGua") {
  492. msg = "分享失败!";
  493. }
  494. else {
  495. // 视频太短
  496. msg = "分享失败,录屏时间太短!";
  497. }
  498. }
  499. else {
  500. msg = "分享失败!";
  501. }
  502. }
  503. if (self_2._shareCallback) {
  504. self_2._shareCallback(false, msg);
  505. }
  506. if (self_2.is_auto_share_video) {
  507. self_2.is_auto_share_video = false;
  508. self_2.tt.showToast({
  509. title: msg,
  510. icon: "fail",
  511. duration: 2000,
  512. success: function (res) {
  513. console.log("" + res);
  514. },
  515. fail: function (res) {
  516. console.log("showToast\u8C03\u7528\u5931\u8D25");
  517. }
  518. });
  519. }
  520. }
  521. });
  522. }
  523. }
  524. };
  525. /**
  526. * 分享图片
  527. */
  528. YZ_Tool_Douyin.prototype.shareImage = function () {
  529. if (PlatUtils_1.default.IsDouyin) {
  530. var shareInfo = Utils_1.utils.getShareInfo();
  531. Utils_1.utils.showLog("\u5206\u4EAB\u56FE\u7247\uFF1Atitle:" + shareInfo.title + "; imageUrl:" + shareInfo.imageUrl);
  532. if (shareInfo) {
  533. var self_3 = this;
  534. //@ts-ignore
  535. this.tt.shareAppMessage({
  536. title: shareInfo.title,
  537. imageUrl: shareInfo.imageUrl,
  538. success: function () {
  539. Utils_1.utils.showLog('图片分享成功!');
  540. if (self_3._shareCallback) {
  541. self_3._shareCallback(true);
  542. }
  543. },
  544. fail: function (e) {
  545. Utils_1.utils.showLog('图片分享失败!' + JSON.stringify(e));
  546. if (self_3._shareCallback) {
  547. self_3._shareCallback(false);
  548. }
  549. }
  550. });
  551. }
  552. }
  553. };
  554. /**
  555. * 显示更多游戏按钮
  556. */
  557. YZ_Tool_Douyin.prototype.showMoreGamesButton = function (params) {
  558. if (PlatUtils_1.default.IsDouyin) {
  559. var left = 0;
  560. var top = 0;
  561. var width = 0;
  562. var height = 0;
  563. if (cc.view.getDesignResolutionSize().width < 1080) {
  564. width = 188 / 1080 * this._sysInfo.screenWidth;
  565. height = 223 / 1080 * this._sysInfo.screenWidth;
  566. }
  567. else {
  568. width = 188 / cc.view.getDesignResolutionSize().width * this._sysInfo.screenWidth;
  569. height = 223 / cc.view.getDesignResolutionSize().width * this._sysInfo.screenWidth;
  570. }
  571. if (params) {
  572. if (params.left) {
  573. left = params.left / cc.view.getDesignResolutionSize().width * this._sysInfo.screenWidth;
  574. }
  575. else if (params.right) {
  576. left = this._sysInfo.screenWidth - params.right / cc.view.getDesignResolutionSize().width * this._sysInfo.screenWidth - width;
  577. }
  578. if (params.top) {
  579. top = params.top / cc.view.getDesignResolutionSize().height * this._sysInfo.screenHeight;
  580. }
  581. else if (params.bottom) {
  582. top = this._sysInfo.screenHeight - params.bottom / cc.view.getDesignResolutionSize().height * this._sysInfo.screenHeight - height;
  583. }
  584. }
  585. Utils_1.utils.showLog("\u66F4\u591A\u6E38\u620F\u6309\u94AE\u53C2\u6570\uFF1Aleft:" + left + "; top:" + top + "; width:" + width + "; height:" + height);
  586. //@ts-ignore
  587. return this.tt.createMoreGamesButton({
  588. type: "image",
  589. image: "img/more_game.png",
  590. style: {
  591. left: left,
  592. top: top,
  593. width: width,
  594. height: height,
  595. lineHeight: 40,
  596. backgroundColor: "#ff0000",
  597. textColor: "#ffffff",
  598. textAlign: "center",
  599. fontSize: 16,
  600. borderRadius: 4,
  601. borderWidth: 0,
  602. borderColor: '#ff0000'
  603. },
  604. appLaunchOptions: [],
  605. onNavigateToMiniGame: function (res) {
  606. Utils_1.utils.showLog('跳转其他小游戏' + res);
  607. if (res && res.errCode == 0) {
  608. // 跳转成功
  609. }
  610. }
  611. });
  612. }
  613. };
  614. YZ_Tool_Douyin.prototype._getShareInfo = function () {
  615. if (PlatUtils_1.default.IsDouyin) {
  616. var shareInfo = Utils_1.utils.getShareInfo();
  617. if (shareInfo) {
  618. return {
  619. title: shareInfo.title,
  620. imageUrl: shareInfo.imageUrl,
  621. success: function (res) {
  622. Utils_1.utils.showLog("分享成功!");
  623. },
  624. fail: function (err) {
  625. Utils_1.utils.showLog("分享失败!");
  626. }
  627. };
  628. }
  629. }
  630. return {};
  631. };
  632. /**
  633. * 比较当前平台版本是否高于指定的版本号
  634. * @param miniVersion 最低平台版本号
  635. */
  636. YZ_Tool_Douyin.prototype.isOverMiniVersion = function (miniVersion) {
  637. if (PlatUtils_1.default.IsDouyin) {
  638. if (this._sysInfo && miniVersion != null) {
  639. return this._compareVersion(this._sysInfo.SDKVersion, miniVersion);
  640. }
  641. }
  642. return false;
  643. };
  644. YZ_Tool_Douyin.prototype._compareVersion = function (first, second) {
  645. return parseInt(first.split(".").join("")) >= parseInt(second.split(".").join(""));
  646. };
  647. /**
  648. * 判断是否支持显示更多游戏弹窗
  649. */
  650. YZ_Tool_Douyin.prototype.isShowMoreGamesModal = function () {
  651. if (PlatUtils_1.default.IsAndroid && this.tt.showMoreGamesModal) {
  652. return true;
  653. }
  654. Utils_1.utils.showLog("当前版本不支持显示抖音更多游戏弹窗!");
  655. return false;
  656. };
  657. /**
  658. * 持显示更多游戏弹窗
  659. */
  660. YZ_Tool_Douyin.prototype.showMoreGamesModal = function () {
  661. if (PlatUtils_1.default.IsAndroid) {
  662. this.tt.showMoreGamesModal({
  663. appLaunchOptions: [],
  664. success: function (res) {
  665. console.log("success", res.errMsg);
  666. },
  667. fail: function (res) {
  668. console.log("fail", res.errMsg);
  669. }
  670. });
  671. }
  672. else {
  673. Utils_1.utils.showMsg("当前平台暂时不支持跳转");
  674. }
  675. };
  676. /**
  677. * 获取交叉推广数据
  678. */
  679. YZ_Tool_Douyin.prototype.getRecommondGameList = function () {
  680. if (PlatUtils_1.default.IsDouyin
  681. && this.ServerConfig) {
  682. return this.ServerConfig.jump_list;
  683. }
  684. return null;
  685. };
  686. /**
  687. * 上报关卡数据
  688. * @param level 当前关卡ID
  689. * @param levelName 关卡名称
  690. * @param status 状态
  691. */
  692. YZ_Tool_Douyin.prototype.postLevel = function (level, status, levelName) {
  693. if (PlatUtils_1.default.IsDouyin) {
  694. var method = "m=rlevel";
  695. var url = POST_ServerUrl + method + ("&level_id=" + level + "&level_name=" + encodeURI(levelName) + "&status=" + status);
  696. Utils_1.utils.commomHttpRequest(url, function (ret, data) {
  697. if (ret) {
  698. Utils_1.utils.showLog("关卡数据上报成功!");
  699. }
  700. else {
  701. Utils_1.utils.showLog("关卡数据上报失败!");
  702. }
  703. }.bind(this));
  704. }
  705. };
  706. /**
  707. * 上报自定义事件
  708. * @param level 当前关卡ID
  709. * @param levelName 关卡名称
  710. * @param status 状态
  711. */
  712. YZ_Tool_Douyin.prototype.sendEvent = function (eventName) {
  713. if (PlatUtils_1.default.IsDouyin) {
  714. var method = "m=revent";
  715. var url = POST_ServerUrl + method + ("&event=" + encodeURI(eventName));
  716. Utils_1.utils.commomHttpRequest(url, function (ret, data) {
  717. if (ret) {
  718. Utils_1.utils.showLog("上报自定义事件成功!");
  719. }
  720. else {
  721. Utils_1.utils.showLog("上报自定义事件失败!");
  722. }
  723. }.bind(this));
  724. }
  725. };
  726. /**
  727. * 弹出提示框
  728. * @param msg 消息
  729. */
  730. YZ_Tool_Douyin.prototype.showToast = function (msg) {
  731. if (PlatUtils_1.default.IsDouyin) {
  732. //@ts-ignore
  733. tt.showToast({
  734. title: msg,
  735. icon: "none",
  736. duration: 2000,
  737. success: function (res) {
  738. console.log("" + res);
  739. },
  740. fail: function (res) {
  741. console.log("showToast\u8C03\u7528\u5931\u8D25");
  742. }
  743. });
  744. }
  745. };
  746. YZ_Tool_Douyin.prototype.GameExit = function () {
  747. //@ts-ignore
  748. tt.exitMiniProgram({
  749. success: function (res) {
  750. console.log("调用成功", res.data);
  751. },
  752. fail: function (res) {
  753. console.log("调用失败", res.errMsg);
  754. },
  755. });
  756. };
  757. YZ_Tool_Douyin = __decorate([
  758. ccclass
  759. ], YZ_Tool_Douyin);
  760. return YZ_Tool_Douyin;
  761. }());
  762. exports.default = YZ_Tool_Douyin;
  763. cc._RF.pop();