WXtrialInterface.html 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8" />
  5. <title>双子星云手机</title>
  6. <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  7. <meta name="x5-orientation" content="portrait" />
  8. <meta name="screen-orientation" content="portrait" />
  9. <meta
  10. name="viewport"
  11. content="width=device-width, initial-scale=1, user-scalable=no"
  12. />
  13. <meta name="apple-mobile-web-app-capable" content="yes" />
  14. <!-- 删除苹果默认的工具栏和菜单栏 -->
  15. <meta name="apple-mobile-web-app-status-bar-style" content="black" />
  16. <!-- 设置苹果工具栏颜? -->
  17. <meta name="format-detection" content="telphone=no, email=no" />
  18. <!-- 忽略页面中的数字识别为电话,忽略email识别 -->
  19. <!-- 启用360浏览器的极速模?(webkit) -->
  20. <meta name="renderer" content="webkit" />
  21. <!-- 针对手持设备优化,主要是针对一些老的不识别viewport的浏览器,比如黑? -->
  22. <meta name="HandheldFriendly" content="true" />
  23. <!-- 微软的老式浏览? -->
  24. <meta name="MobileOptimized" content="320" />
  25. <!-- 不能旋转,问题出在这 -->
  26. <!-- UC强制全屏 -->
  27. <meta name="full-screen" content="yes" />
  28. <!-- QQ强制全屏 -->
  29. <meta name="x5-fullscreen" content="true" />
  30. <!-- UC应用模式 -->
  31. <meta name="browsermode" content="application" />
  32. <!-- QQ应用模式 -->
  33. <meta name="x5-page-mode" content="app" />
  34. <!-- windows phone 点击无高? -->
  35. <meta name="msapplication-tap-highlight" content="no" />
  36. <link rel="stylesheet" type="text/css" href="css/WXtrialInterface.css" />
  37. <link
  38. rel="stylesheet"
  39. href="https://cdn.bootcss.com/weui/1.1.3/style/weui.min.css"
  40. />
  41. <link
  42. rel="stylesheet"
  43. href="https://cdn.bootcss.com/jquery-weui/1.2.1/css/jquery-weui.min.css"
  44. />
  45. <script src="../static/lib/doT-1.1.3/doT.min.js"></script>
  46. </head>
  47. <body class="scroll h-player" style="overscroll-behavior: contain">
  48. <template id="template-phone-size-item">
  49. {{~ it.list :value:index }}
  50. <div
  51. class="phone-size-item {{? value.width === it.active.width && value.height === it.active.height }}active{{?}}"
  52. data-width="{{= value.width }}"
  53. data-height="{{= value.height }}"
  54. data-id="{{= value.id }}"
  55. >
  56. <span>{{= value.width }}x{{= value.height }}</span>
  57. </div>
  58. {{~}}
  59. </template>
  60. <div class="container" id="player">
  61. <div class="muted" id="btnMuted">
  62. <div class="control-right-img" data-id="1">
  63. <img src="../static/img/xuanfu_icon.png" />
  64. </div>
  65. </div>
  66. <div id="wine">
  67. <video
  68. id="playerVideo"
  69. x5-video-orientation="landscape"
  70. playsinline="true"
  71. autoplay="true"
  72. webkit-playsinline="true"
  73. x5-playsinline="true"
  74. x5-video-player-type="h5"
  75. x5-video-player-fullscreen="false"
  76. style="
  77. pointer-events: none;
  78. object-fit: fill;
  79. width: 100%;
  80. height: 100%;
  81. "
  82. ></video>
  83. <div id="box"></div>
  84. <audio
  85. preload="auto"
  86. autoplay
  87. controls
  88. poster="images/loader-thumb.jpg"
  89. id="audioPlayer"
  90. style="position: absolute; top: 0; width: 0; height: 0"
  91. ></audio>
  92. </div>
  93. <div class="leftmains">
  94. <div class="PictureQualityMain">
  95. <div class="menu-btn PictureQuality" data-id="4">高清</div>
  96. <div class="menu-btn PictureQuality avit" data-id="3">标清</div>
  97. <div class="menu-btn PictureQuality" data-id="2">极速</div>
  98. </div>
  99. <div class="">
  100. <div class="menu-btn" id="open-set-phone-size-dialog-btn">
  101. <span>分辨率</span>
  102. </div>
  103. </div>
  104. <div class="operation">
  105. <div class="upload" id="showsuss" data-text="uploads">
  106. <img src="../static/img/wx/shangchuan_icon.png" />
  107. <div>上传</div>
  108. </div>
  109. <div class="upload" onclick="showShearPlate()" data-text="Shearplate">
  110. <img src="../static/img/wx/jianqieban_icon.png" />
  111. <div>剪贴板</div>
  112. </div>
  113. <div class="upload" id="upload" data-text="Signout">
  114. <img src="../static/img/wx/tuichu_icon.png" />
  115. <div>退出</div>
  116. </div>
  117. </div>
  118. </div>
  119. <div class="bottommains">
  120. <div class="botmat1">
  121. <div class="botmat1img" data-text="gengduo">
  122. <img src="../static/img/wx/gengduo_icon.png" />
  123. </div>
  124. </div>
  125. <div class="botmat1">
  126. <div class="botmat1img" data-text="home">
  127. <img src="../static/img/wx/home_icon.png" />
  128. </div>
  129. </div>
  130. <div class="botmat1">
  131. <div class="botmat1img" data-text="return">
  132. <img src="../static/img/wx/fanhui_icon.png" />
  133. </div>
  134. </div>
  135. </div>
  136. <img class="loading loading_sceen_pic" />
  137. </div>
  138. <div class="mask">
  139. <div class="box-shear-plate"></div>
  140. <img
  141. class="close"
  142. onclick="handleClose()"
  143. src="img/guanbi_icon@2x.png"
  144. alt=""
  145. />
  146. </div>
  147. <div class="weui-mask_transparent"></div>
  148. <div class="weui-toast weui_loading_toast weui-toast--visible">
  149. <div class="weui_loading">
  150. <i class="weui-loading weui-icon_toast"></i>
  151. </div>
  152. <p class="weui-toast_content">数据加载中</p>
  153. </div>
  154. <div class="try-use-wrap">
  155. <div class="try-use-container">
  156. <video
  157. width="100%"
  158. height="100%"
  159. id="source"
  160. autoplay="autoplay"
  161. loop="loop"
  162. webkit-playsinline="true"
  163. playsinline="true"
  164. x5-video-player-type="h5-page"
  165. >
  166. 您的浏览器不支持 video 标签。
  167. </video>
  168. <div class="time-close-wrap"><span class="time-node"></span> 关闭</div>
  169. </div>
  170. </div>
  171. <div class="buy-phone-wrap">
  172. <div class="bug-wrap">
  173. <div class="bug-title">获得极致体验服务请购买云手机</div>
  174. <div class="btn-list">
  175. <div class="btn cannel-btn">取消</div>
  176. <div class="btn go-bug">去购买</div>
  177. </div>
  178. </div>
  179. </div>
  180. <div class="look-wrap">
  181. <div class="bug-wrap">
  182. <div class="bug-title">关闭广告会退出云手机是否继续观看</div>
  183. <div class="btn-list">
  184. <div class="btn cannel-btn cannel-ad-btn">放弃</div>
  185. <div class="btn go-bug looking">继续观看</div>
  186. </div>
  187. </div>
  188. </div>
  189. <!-- <body oncontextmenu="Back()"></body> -->
  190. <div id="set-phone-size-dialog" class="dialog">
  191. <div class="dialog-mask"></div>
  192. <!-- 设置分辨率的弹窗 -->
  193. <div class="dialog-content-border">
  194. <div class="dialog-content">
  195. <div class="dialog-header">
  196. <div class="dialog-btn cancel">
  197. <span>取消</span>
  198. </div>
  199. <div class="dialog-btn confirm">
  200. <span>确定</span>
  201. </div>
  202. </div>
  203. <div class="dialog-main">
  204. <div id="phone-size-list"></div>
  205. </div>
  206. </div>
  207. </div>
  208. </div>
  209. <script
  210. type="text/javascript"
  211. src="https://res.wx.qq.com/open/js/jweixin-1.3.2.js"
  212. ></script>
  213. <script src="https://lf1-cdn-tos.bytegoofy.com/goofy/developer/jssdk/jssdk-1.0.3.js"></script>
  214. <script
  215. type="text/javascript"
  216. src="../static/js/jquery-1.11.0.min.js"
  217. ></script>
  218. <script type="text/javascript" src="helper.js"></script>
  219. <script type="text/javascript" src="pcm-player.js"></script>
  220. <script
  221. type="text/javascript"
  222. src="https://cdn.bootcss.com/vConsole/3.2.0/vconsole.min.js"
  223. ></script>
  224. <script src="https://cdn.bootcss.com/jquery-weui/1.2.1/js/jquery-weui.min.js"></script>
  225. <script type="text/javascript" src="jmuxer.js"></script>
  226. <script type="text/javascript" src="spsParser.js"></script>
  227. <script
  228. type="text/javascript"
  229. src="https://js.cdn.aliyun.dcloud.net.cn/dev/uni-app/uni.webview.1.5.2.js"
  230. ></script>
  231. <script>
  232. var url = window.location.href;
  233. url = url.split('/');
  234. var baseUrl = url[0] + '//' + url[2];
  235. var parameters = GetRequest();
  236. var token = parameters['token'];
  237. var userCardId = parameters['userCardId'];
  238. var mealType = parameters['mealType'];
  239. var videoTimer = null,
  240. videoTime = 0,
  241. adType = 0,
  242. sourceType = isNaN(parameters['sourceType'])
  243. ? 0
  244. : +parameters['sourceType'],
  245. disconnectionFlag = false,
  246. getDate = false;
  247. var isDev =
  248. /^192\.168\./.test(location.host) ||
  249. /^127\.0\.0\.1/.test(location.host) ||
  250. /^localhost/.test(location.host);
  251. // if (isDev) {
  252. // baseUrl = 'http://gntest.phone.androidscloud.com:1280';
  253. // sourceType = 2;
  254. // }
  255. if (parameters['mealType'] === 'VIP') {
  256. $('.loading_sceen_pic').attr('src', '../static/img/home_bg_VIP.png');
  257. } else if (parameters['mealType'] === 'SVIP') {
  258. $('.loading_sceen_pic').attr('src', '../static/img/home_bg_SVIP.png');
  259. } else if (parameters['mealType'] === 'STAR') {
  260. $('.loading_sceen_pic').attr('src', '../static/img/home_bg_STAR.png');
  261. } else if (parameters['mealType'] === 'STARPRO') {
  262. $('.loading_sceen_pic').attr('src', '../static/img/home_bg_PRO.png');
  263. }
  264. initAD();
  265. let dbName = parameters['username'],
  266. version = 1,
  267. storeName = 'usercard';
  268. let indexedDB = window.indexedDB;
  269. let db, socketURL, cUrl, cardToken, resolvingPower;
  270. const request = indexedDB.open(dbName, version);
  271. request.onsuccess = function (event) {
  272. db = event.target.result; // 数据库对象
  273. console.log('数据库打开成功');
  274. };
  275. request.onerror = function (event) {
  276. console.log('数据库打开报错');
  277. };
  278. request.onupgradeneeded = function (event) {
  279. // 数据库创建或升级的时候会触发
  280. console.log('onupgradeneeded');
  281. db = event.target.result; // 数据库对象
  282. let objectStore;
  283. if (!db.objectStoreNames.contains(storeName)) {
  284. objectStore = db.createObjectStore(storeName, { keyPath: 'id' }); // 创建表
  285. }
  286. };
  287. // 添加数据
  288. function addData(db, storeName, data) {
  289. let request = db
  290. .transaction([storeName], 'readwrite') // 事务对象 指定表格名称和操作模式("只读"或"读写")
  291. .objectStore(storeName) // 仓库对象
  292. .add(data);
  293. request.onsuccess = function (event) {
  294. console.log('数据写入成功');
  295. };
  296. request.onerror = function (event) {
  297. console.log('数据写入失败');
  298. throw new Error(event.target.error);
  299. };
  300. }
  301. // 根据id获取数据
  302. function getDataByKey(db, storeName, key) {
  303. let transaction = db.transaction([storeName]); // 事务
  304. let objectStore = transaction.objectStore(storeName); // 仓库对象
  305. let request = objectStore.get(key);
  306. request.onerror = function (event) {
  307. connect('add');
  308. };
  309. request.onsuccess = function (event) {
  310. console.log('主键查询结果: ', request.result);
  311. if (request.result) {
  312. socketURL = request.result.socketURL;
  313. cUrl = request.result.cUrl;
  314. cardToken = request.result.cardToken;
  315. resolvingPower = request.result.resolvingPower;
  316. doConnectBusiness();
  317. doConnectDirectives();
  318. } else {
  319. connect('add');
  320. }
  321. };
  322. }
  323. // 根据id修改数
  324. function updateDB(db, storeName, data) {
  325. let request = db
  326. .transaction([storeName], 'readwrite') // 事务对象
  327. .objectStore(storeName) // 仓库对象
  328. .put(data);
  329. request.onsuccess = function () {
  330. console.log('数据更新成功');
  331. };
  332. request.onerror = function () {
  333. console.log('数据更新失败');
  334. };
  335. }
  336. // 由于打开indexDB是异步的加个定时器避免 db对象还没获取到值导致 报错
  337. setTimeout(() => {
  338. getDataByKey(db, storeName, userCardId);
  339. }, 1000);
  340. var isAudioPlay = false;
  341. if (navigator.userAgent.toLowerCase().includes('toutiaomicroapp')) {
  342. var video = document.getElementById('playerVideo');
  343. video.play();
  344. setTimeout(() => {
  345. // 抖音环境需要设置延时,不然会有video默认图显示
  346. $.alert({
  347. title: '提示',
  348. text: '开始使用云手机',
  349. onOK: function () {
  350. setTimeout(() => {
  351. isAudioPlay = true;
  352. }, 1000);
  353. },
  354. });
  355. }, 1000);
  356. } else {
  357. $.alert({
  358. title: '提示',
  359. text: '开始使用云手机',
  360. onOK: function () {
  361. var video = document.getElementById('playerVideo');
  362. video.play();
  363. isAudioPlay = true;
  364. },
  365. });
  366. }
  367. //云机倒计时
  368. let validTime = parameters['validTime'] || 10000;
  369. if (validTime > 32000) {
  370. validTime = 32000;
  371. }
  372. let detailTime = validTime * 60 * 1000;
  373. setTimeout(() => {
  374. $('.bug-title').eq(0).text('尊敬的用户您的云手机试用时间已到期');
  375. getDate = true;
  376. $('.buy-phone-wrap').eq(0).show();
  377. }, detailTime);
  378. var topwinHeight = window.screen.height - window.innerHeight + 30; //计算title top 头部
  379. $('#wine').css({
  380. width: window.screen.width,
  381. height: window.screen.height - topwinHeight - 20,
  382. position: 'absolute',
  383. });
  384. $('.loading').css({
  385. width: window.screen.width,
  386. height: window.screen.height - topwinHeight - 20,
  387. });
  388. var winese = document.createElement('wine');
  389. wine.style.top = '-' + winese + 'px';
  390. var isVisuable = true;
  391. var isFeed = true;
  392. var isFinish = false;
  393. var myVideo = document.getElementById('playerVideo');
  394. Module = {};
  395. Module.onRuntimeInitialized = function () {
  396. isFinish = true;
  397. };
  398. function connect(type) {
  399. $.ajax({
  400. url: baseUrl + '/api/resources/user/cloud/connect',
  401. type: 'post',
  402. data: JSON.stringify({
  403. userCardId: Number(userCardId),
  404. }),
  405. headers: {
  406. 'content-Type': 'application/json',
  407. Authorization: token,
  408. },
  409. dataType: 'json',
  410. async: false,
  411. success: function (res) {
  412. if (res.status === 0) {
  413. if (res.data.internetHttps) {
  414. socketURL =
  415. 'wss://' +
  416. res.data.internetHttps +
  417. '/plugflow?cardIp=' +
  418. res.data.localIp +
  419. '&token=' +
  420. res.data.cardToken +
  421. '&type=business';
  422. cUrl =
  423. 'wss://' +
  424. res.data.internetHttps +
  425. '/businessChannel?cardIp=' +
  426. res.data.localIp +
  427. '&token=' +
  428. res.data.cardToken +
  429. '&type=directives';
  430. cardToken = res.data.cardToken;
  431. resolvingPower = res.data.resolvingPower;
  432. doConnectBusiness();
  433. doConnectDirectives();
  434. if (type === 'add') {
  435. addData(db, storeName, {
  436. id: userCardId,
  437. socketURL: socketURL,
  438. cUrl: cUrl,
  439. cardToken: res.data.cardToken,
  440. resolvingPower: res.data.resolvingPower,
  441. });
  442. } else {
  443. updateDB(db, storeName, {
  444. id: userCardId,
  445. socketURL: socketURL,
  446. cUrl: cUrl,
  447. cardToken: res.data.cardToken,
  448. resolvingPower: res.data.resolvingPower,
  449. });
  450. }
  451. } else {
  452. $.toast('网络异常,请稍后重试', 'text');
  453. }
  454. } else {
  455. $.toast('画面异常,请重新进入', 'text');
  456. clearInterval(intervaler);
  457. quit();
  458. ws.close();
  459. wsss.close();
  460. }
  461. },
  462. });
  463. }
  464. var jmuxer = new JMuxer({
  465. node: 'playerVideo',
  466. flushingTime: 33,
  467. fps: 30,
  468. mode: 'video',
  469. debug: false,
  470. });
  471. window.onload = function () {
  472. var myPlay = document.getElementById('wine');
  473. myPlay.onkeydown = function (event) {
  474. ExexuteKeyDown(e.keyCode);
  475. };
  476. };
  477. var ws,
  478. errorTime = 0;
  479. // 节流
  480. // 设置一个标志
  481. function throttle(fn, delay) {
  482. let flag = true;
  483. errorTime += delay;
  484. return () => {
  485. if (!flag) return;
  486. flag = false;
  487. timer = setTimeout(() => {
  488. fn();
  489. flag = true;
  490. }, delay);
  491. };
  492. }
  493. var intervaler;
  494. function doConnectBusiness() {
  495. ws = new WebSocket(socketURL);
  496. ws.binaryType = 'arraybuffer';
  497. intervaler = setInterval(() => {
  498. if (ws.readyState === 1) {
  499. ws.send('ping');
  500. } else {
  501. clearInterval(intervaler);
  502. $.toast('画面异常,请重新进入', 'text');
  503. quit();
  504. }
  505. }, 3000);
  506. ws.addEventListener('open', function (event) {
  507. // sn只要长度满足17位随机数,不需要从后台获取
  508. var verifyBuffer = VerifyCode('RK3923C1201900139', cardToken);
  509. console.log('鉴权报文:' + PrintArry(verifyBuffer));
  510. ws.send(verifyBuffer);
  511. });
  512. ws.addEventListener('error', function (event) {
  513. ws.close();
  514. clearInterval(intervaler);
  515. throttle(doConnectBusiness, 100);
  516. if (errorTime > 1000) {
  517. $.toast('画面异常,请重新进入', 'text');
  518. wsss.close();
  519. quit();
  520. }
  521. });
  522. ws.addEventListener('message', function (event) {
  523. var data = ParseProto(event.data); //JAVA服务器转发
  524. if (isAudioPlay) {
  525. $('.weui-mask_transparent').hide();
  526. $('.weui-toast').hide();
  527. $('.loading').hide();
  528. }
  529. var input = new Uint8Array(event.data);
  530. if (data.audio != null && isAudioPlay) {
  531. //喂音频
  532. if (input[0] == 0xff) {
  533. if (isFinish) {
  534. decodeAAC(input);
  535. }
  536. }
  537. }
  538. if (
  539. data.frameType != undefined &&
  540. data.frameType != 1 &&
  541. data.frameType != 6
  542. ) {
  543. if (data.frameType == 7) {
  544. let info = spsParser(data.video);
  545. if (
  546. info.width != myVideo.videoWidth &&
  547. info.height != myVideo.videoHeight
  548. ) {
  549. if (myVideo.videoWidth == 0) {
  550. console.log(
  551. 'SPS计算得到宽 %d, 高 %d, 控件宽 %d, %d',
  552. info.width,
  553. info.height,
  554. myVideo.videoWidth,
  555. myVideo.videoHeight,
  556. );
  557. }
  558. }
  559. }
  560. }
  561. if (data.video != null) {
  562. //喂视频
  563. if (data.frameType == 0x05 && isVisuable) {
  564. isFeed = true;
  565. }
  566. if (data.frameType == 7 || data.frameType == 8) {
  567. isFeed = true;
  568. isAudioPlay = true;
  569. }
  570. if (isFeed) {
  571. jmuxer.feed(data);
  572. }
  573. }
  574. });
  575. }
  576. var hidden, visibilityChange;
  577. if (typeof document.hidden !== 'undefined') {
  578. // Opera 12.10 and Firefox 18 and later support
  579. hidden = 'hidden';
  580. visibilityChange = 'visibilitychange';
  581. } else if (typeof document.msHidden !== 'undefined') {
  582. hidden = 'msHidden';
  583. visibilityChange = 'msvisibilitychange';
  584. } else if (typeof document.webkitHidden !== 'undefined') {
  585. hidden = 'webkitHidden';
  586. visibilityChange = 'webkitvisibilitychange';
  587. }
  588. // 处理页面可见属性的改变
  589. document.addEventListener(
  590. 'visibilitychange',
  591. function () {
  592. if (navigator.userAgent.toLowerCase().includes('toutiaomicroapp')) {
  593. visibilitychange();
  594. } else if (window.__wxjs_environment === 'miniprogram') {
  595. visibilitychange();
  596. } else {
  597. if (document[hidden]) {
  598. ws.close();
  599. wsss.close();
  600. uni.webView.navigateBack({
  601. delta: 1,
  602. });
  603. }
  604. }
  605. },
  606. false,
  607. );
  608. function visibilitychange() {
  609. if (document.visibilityState == 'visible') {
  610. var buffer = RequestIFrame();
  611. ws.send(buffer);
  612. isVisuable = true;
  613. } else {
  614. isVisuable = false;
  615. isFeed = false;
  616. myVideo.pause();
  617. }
  618. }
  619. myVideo.addEventListener('pause', function () {
  620. isFeed = false;
  621. });
  622. var decodeCount = 1;
  623. var player = new PCMPlayer({
  624. encoding: '16bitInt',
  625. channels: 2,
  626. sampleRate: 44100,
  627. flushingTime: 22,
  628. debug: false,
  629. });
  630. function handleClose() {
  631. $('.mask').hide();
  632. }
  633. function decodeAAC(data) {
  634. var retPtr = Module._malloc(4 * 5 * 1024); // 接收的数据
  635. var inputPtr = Module._malloc(4 * data.length); // 输入数据
  636. for (var i = 0; i < data.length; i++) {
  637. Module.HEAPU8[inputPtr + i] = data[i]; //转换为堆数据
  638. }
  639. var pcmLen = Module._feedData(retPtr, inputPtr, data.length);
  640. if (pcmLen >= 0) {
  641. var pcmData = new Uint8Array(pcmLen);
  642. for (var i = 0; i < pcmLen; i++) {
  643. pcmData[i] = Module.HEAPU8[retPtr + i];
  644. }
  645. player.feed(pcmData);
  646. }
  647. decodeCount++;
  648. Module._free(inputPtr);
  649. Module._free(retPtr);
  650. }
  651. //解协议
  652. function ParseProto(data) {
  653. var input = new Uint8Array(data),
  654. duration,
  655. video,
  656. frameType,
  657. audio;
  658. if (input[0] == 0 && input[1] == 0 && input[2] == 0 && input[3] == 1) {
  659. video = input;
  660. duration = 24;
  661. var nalType = input[4] & 0x1f;
  662. frameType = nalType;
  663. if (!isFeed) {
  664. if (nalType == 0x05 && isVisuable) {
  665. isFeed = true;
  666. }
  667. }
  668. } else if (input[0] == 0xff) {
  669. audio = input;
  670. duration = 24;
  671. } else if (input[0] == 0x68) {
  672. if (input[23] == 0x5c) {
  673. console.log('收到消息:' + PrintArry(input));
  674. if (CheckVerifyCode(input)) {
  675. ws.send(ConfigChannel('RK3923C1201900139'));
  676. var checkBuffer = GetScreenState();
  677. ws.send(checkBuffer);
  678. } else {
  679. connect('update');
  680. }
  681. }
  682. if (input[23] == 0x05) {
  683. //横竖屏标识
  684. var state = CheckScreenDirection(input.slice(24, 24 + 8));
  685. if (state == 1) {
  686. console.log('安卓卡此时竖屏');
  687. //竖屏处理
  688. resolving = 1;
  689. } else {
  690. console.log('安卓卡此时横屏');
  691. //横屏处理
  692. resolving = 0;
  693. }
  694. }
  695. if (input[23] == 0x0b) {
  696. //多端登录处理, 数据从索引24开始取, input 是接收到的原始数据
  697. var jsonobj = checkMultiLoginInfo(input);
  698. }
  699. }
  700. return {
  701. audio: audio,
  702. video: video,
  703. duration: duration,
  704. frameType: frameType,
  705. };
  706. }
  707. function GetRequest() {
  708. var url = location.search; // 获取url中"?"符后的字串
  709. var obj = new Object();
  710. if (url.indexOf('?') != -1) {
  711. var str = url.substr(1);
  712. strs = str.split('&');
  713. for (var i = 0; i < strs.length; i++) {
  714. obj[strs[i].split('=')[0]] = strs[i].split('=')[1];
  715. }
  716. }
  717. return obj;
  718. }
  719. function Back() {
  720. ExexuteKeyDown(4);
  721. window.event.returnValue = false;
  722. return false;
  723. }
  724. function array_unique(arr) {
  725. return arr.filter(function (e, i) {
  726. return arr.indexOf(e) === i;
  727. });
  728. }
  729. var cutList = [];
  730. let timer,
  731. isFlag = true;
  732. function showShearPlate() {
  733. if (!isControl) {
  734. return;
  735. }
  736. stopManyClick(() => {
  737. $('.box-shear-plate').empty();
  738. $.ajax({
  739. url: baseUrl + '/api/public/v5/shear/content',
  740. headers: {
  741. Authorization: token,
  742. },
  743. type: 'get',
  744. dataType: 'json',
  745. success: function (res) {
  746. if (res.status === 0) {
  747. if (res.data.length) {
  748. cutList = array_unique(res.data);
  749. var str =
  750. '<div class="title">剪贴板<div onclick="handleClear()" class="btn-clear">清空</div></div><div class="slide-wrapper-content">';
  751. cutList.forEach(function (item) {
  752. str +=
  753. "<div class='slide-wrapper'><div class='slide-scroll animate-slide-start'><div class='slide-content'><div onclick='handleCopy(\"" +
  754. item.content +
  755. '")\'>' +
  756. item.content +
  757. "</div></div><div class='slide-content-button'><button onclick='handleDelete(" +
  758. item.id +
  759. ")'>删除</button></div></div></div>";
  760. });
  761. str += '</div>';
  762. $('.box-shear-plate').append(str);
  763. } else {
  764. $('.box-shear-plate').append(
  765. '<img class="empty" src="img/jianqieban_pic@2x.png" alt="" /><div class="empty-txt">剪贴板为空</div>',
  766. );
  767. }
  768. $('.mask').show();
  769. initSlider();
  770. } else {
  771. $('.box-shear-plate').append(
  772. '<img class="empty" src="img/jianqieban_pic@2x.png" alt="" /><div class="empty-txt">剪贴板为空</div>',
  773. );
  774. $('.mask').show();
  775. }
  776. },
  777. });
  778. });
  779. }
  780. //防止提示一秒内重复显示
  781. function stopManyClick(fn) {
  782. if (isFlag) {
  783. fn();
  784. }
  785. isFlag = false;
  786. if (timer) {
  787. clearTimeout(timer);
  788. }
  789. timer = setTimeout(() => {
  790. isFlag = true;
  791. }, 1500);
  792. }
  793. // 清空剪贴板
  794. function handleClear() {
  795. var ids = '';
  796. cutList.forEach(function (item) {
  797. ids += 'ids=' + item.id + '&';
  798. });
  799. ids = ids.substring(0, ids.lastIndexOf('&'));
  800. $.confirm('确定清空剪贴板?', function () {
  801. $.ajax({
  802. url: baseUrl + '/api/public/v5/shear/content?' + ids,
  803. headers: {
  804. Authorization: token,
  805. },
  806. type: 'DELETE',
  807. dataType: 'json',
  808. success: function (res) {
  809. if (res.status === 0) {
  810. showShearPlate();
  811. } else {
  812. $.toast(res.msg, 'text');
  813. }
  814. },
  815. });
  816. });
  817. }
  818. function handleCopy(content) {
  819. var cutting = {
  820. type: 'cutting',
  821. data: {
  822. str: content,
  823. },
  824. };
  825. wsss.send(JSON.stringify(cutting));
  826. }
  827. // 删除剪贴板
  828. function handleDelete(id) {
  829. $.ajax({
  830. url: baseUrl + '/api/public/v5/shear/content?ids=' + id,
  831. headers: {
  832. Authorization: token,
  833. },
  834. type: 'DELETE',
  835. dataType: 'json',
  836. success: function (res) {
  837. if (res.status === 0) {
  838. showShearPlate();
  839. } else {
  840. $.toast(res.msg, 'text');
  841. }
  842. },
  843. });
  844. }
  845. function initSlider() {
  846. //手指滑动多少距离就认为是滑成功
  847. //这个值不能太大,否则影响斜着滑动时,垂直滑动的流畅性,也不能太小,太灵敏也不好
  848. var diffXDistance = 50;
  849. //当前滑动的对象
  850. var currentObject;
  851. //上一次滑动的对象
  852. var lastObject;
  853. //是否可以左右滑动,在上下滑的时候禁止左右滑
  854. var canSlide = true;
  855. //用于记录按下的点
  856. var startPoint;
  857. $('.slide-content').css({
  858. width: $('.slide-wrapper').width(),
  859. });
  860. document.body.removeEventListener(
  861. 'touchmove',
  862. function (e) {
  863. e.preventDefault();
  864. },
  865. {
  866. passive: false,
  867. },
  868. );
  869. $('.slide-scroll')
  870. .css({
  871. width:
  872. $('.slide-wrapper').width() + $('.slide-content-button').width(),
  873. })
  874. .on('touchstart', function (e) {
  875. currentObject = this;
  876. startPoint = {
  877. x: e.originalEvent.changedTouches[0].pageX,
  878. y: e.originalEvent.changedTouches[0].pageY,
  879. };
  880. })
  881. .on('touchmove', function (e) {
  882. //如果是左右滑动,就禁止上下的滑动
  883. //如果是上下的滑动,就禁止左右滑动
  884. if (
  885. Math.abs(e.originalEvent.changedTouches[0].pageX - startPoint.x) >
  886. Math.abs(e.originalEvent.changedTouches[0].pageY - startPoint.y)
  887. ) {
  888. event.preventDefault();
  889. } else {
  890. canSlide = false;
  891. }
  892. })
  893. .on('touchend', function (e) {
  894. //如果是上下滑动,这里就直接返回了
  895. if (!canSlide) {
  896. canSlide = true;
  897. return true;
  898. }
  899. //点击除当前左滑对象之外的任意其他位置
  900. if (lastObject && currentObject != lastObject) {
  901. //右滑→
  902. $(lastObject).removeClass('animate-slide');
  903. //清空上一个左滑的对象
  904. lastObject = undefined;
  905. }
  906. var diffX = e.originalEvent.changedTouches[0].pageX - startPoint.x;
  907. if (diffX < -diffXDistance) {
  908. //左滑←
  909. $(currentObject).addClass('animate-slide');
  910. if (lastObject && lastObject != currentObject) {
  911. //右滑→
  912. $(lastObject).removeClass('animate-slide');
  913. }
  914. //记录上一个左滑的对象
  915. lastObject = currentObject;
  916. } else if (diffX >= diffXDistance) {
  917. if (currentObject == lastObject) {
  918. //右滑→
  919. $(currentObject).removeClass('animate-slide');
  920. //清空上一个左滑的对象
  921. lastObject = undefined;
  922. }
  923. }
  924. });
  925. }
  926. var btnMuted = document.querySelector('#btnMuted');
  927. btnMuted &&
  928. (function () {
  929. var setHistory = function (left, top) {
  930. try {
  931. localStorage.setItem(
  932. 'muted-btn-loc',
  933. JSON.stringify({
  934. left: left,
  935. top: top,
  936. }),
  937. );
  938. } catch (ex) {}
  939. };
  940. var getHistory = function () {
  941. try {
  942. var value = localStorage.getItem('muted-btn-loc');
  943. if (!value) return null;
  944. value = JSON.parse(value);
  945. if (!value) return null;
  946. return value;
  947. } catch (ex) {
  948. return null;
  949. }
  950. };
  951. var fixLoc = function (loc) {
  952. var rect = btnMuted.getBoundingClientRect();
  953. rect = {
  954. top: rect.top,
  955. left: rect.left,
  956. width: rect.width,
  957. height: rect.height,
  958. }; //部分低版本浏览器,该属性为只读
  959. if (loc) {
  960. rect.left = loc.left;
  961. rect.top = loc.top;
  962. }
  963. var minX = 0;
  964. var minY = 0;
  965. var docRect = document.documentElement.getBoundingClientRect();
  966. var maxY = docRect.height - rect.height;
  967. var maxX = docRect.width - rect.width;
  968. var left = rect.left;
  969. var top = rect.top;
  970. left = Math.min(left, maxX);
  971. left = Math.max(left, minX);
  972. top = Math.min(top, maxY);
  973. top = Math.max(top, minY);
  974. if (loc || top !== rect.top || left !== rect.left) {
  975. btnMuted.style.cssText +=
  976. 'left:' + left + 'px;top:' + top + 'px;';
  977. }
  978. };
  979. window.addEventListener('resize', function () {
  980. fixLoc();
  981. });
  982. var touchPoint = {
  983. pageY: 0,
  984. pageX: 0,
  985. };
  986. var currentLoc = {
  987. top: 0,
  988. left: 0,
  989. curTop: 0,
  990. curLeft: 0,
  991. };
  992. var toMove = false;
  993. var touchmove = function (e) {
  994. e.preventDefault();
  995. var point = e.changedTouches[0];
  996. var top = -touchPoint.pageY + point.pageY;
  997. var left = -touchPoint.pageX + point.pageX;
  998. if (toMove) {
  999. top += currentLoc.top;
  1000. left += currentLoc.left;
  1001. currentLoc.curLeft = left;
  1002. currentLoc.curTop = top;
  1003. btnMuted.style.cssText +=
  1004. 'left:' + left + 'px;top:' + top + 'px;';
  1005. } else {
  1006. if (Math.abs(top) >= 5 || Math.abs(left) >= 5) {
  1007. toMove = true;
  1008. }
  1009. }
  1010. };
  1011. var touchend = function () {
  1012. window.removeEventListener('touchmove', touchmove, {
  1013. passive: false,
  1014. });
  1015. window.removeEventListener('touchend', touchend, {
  1016. passive: false,
  1017. });
  1018. if (toMove) {
  1019. setHistory(currentLoc.curLeft, currentLoc.curTop);
  1020. fixLoc();
  1021. } else {
  1022. //按点击处理
  1023. var set = $('.control-right-img').attr('data-id');
  1024. if (set == '1') {
  1025. $('.control-right-img').attr({
  1026. 'data-id': '2',
  1027. });
  1028. $('.leftmains').css({
  1029. right: '0rem',
  1030. });
  1031. } else {
  1032. $('.control-right-img').attr({
  1033. 'data-id': '1',
  1034. });
  1035. $('.leftmains').css({
  1036. right: '-4rem',
  1037. });
  1038. }
  1039. }
  1040. };
  1041. btnMuted.addEventListener(
  1042. 'touchstart',
  1043. function (e) {
  1044. e.preventDefault();
  1045. toMove = false;
  1046. var point = e.changedTouches[0];
  1047. touchPoint.pageX = point.pageX;
  1048. touchPoint.pageY = point.pageY;
  1049. var rect = e.target.getBoundingClientRect();
  1050. currentLoc.top = rect.top;
  1051. currentLoc.left = rect.left;
  1052. window.addEventListener('touchmove', touchmove, {
  1053. passive: false,
  1054. });
  1055. window.addEventListener('touchend', touchend, {
  1056. passive: false,
  1057. });
  1058. },
  1059. {
  1060. passive: false,
  1061. },
  1062. );
  1063. var history = getHistory();
  1064. if (history) {
  1065. fixLoc(history);
  1066. }
  1067. btnMuted.classList.remove('hide');
  1068. })();
  1069. $('#upload').on('click', function () {
  1070. clearInterval(intervaler);
  1071. quit();
  1072. ws.close();
  1073. wsss.close();
  1074. });
  1075. function selectText(x) {
  1076. if (document.selection) {
  1077. var range = document.body.createTextRange();
  1078. range.moveToElementText(x);
  1079. range.select();
  1080. } else if (window.getSelection) {
  1081. var selection = window.getSelection();
  1082. var range = document.createRange();
  1083. selection.removeAllRanges();
  1084. range.selectNodeContents(x);
  1085. selection.addRange(range);
  1086. }
  1087. }
  1088. // 激活码广告相关配置
  1089. function getConfigByPhoneType() {
  1090. return new Promise((resolve, reject) => {
  1091. $.ajax({
  1092. url: baseUrl + '/api/pay/v5/trialCodeConfig/getConfigByPhoneType',
  1093. headers: {
  1094. Authorization: token,
  1095. },
  1096. data: {
  1097. userCardId: userCardId,
  1098. phoneType: mealType,
  1099. },
  1100. type: 'get',
  1101. dataType: 'json',
  1102. success: function (res) {
  1103. let obj = res.data;
  1104. if (res.status === 0) {
  1105. resolve(obj);
  1106. } else {
  1107. $.toast(res.msg, 'text');
  1108. }
  1109. },
  1110. });
  1111. });
  1112. }
  1113. //列表
  1114. function getSetmealList() {
  1115. return new Promise((resolve, reject) => {
  1116. $.ajax({
  1117. url: baseUrl + '/api/resources/v4/freetrial/setmeal/list',
  1118. headers: {
  1119. Authorization: token,
  1120. },
  1121. type: 'get',
  1122. dataType: 'json',
  1123. success: function (res) {
  1124. if (res.status === 0) {
  1125. let list = res.data;
  1126. list.map((item) => {
  1127. if (item.phoneType === parameters['mealType']) {
  1128. resolve(item);
  1129. }
  1130. });
  1131. } else {
  1132. $.toast(res.msg, 'text');
  1133. }
  1134. },
  1135. });
  1136. });
  1137. }
  1138. //广告信息
  1139. var adData = null; // 广告数据
  1140. var adLastTime = 0; // 广告时间
  1141. var intervalTime = 0; // 间隔时间
  1142. // let adType = 0;
  1143. console.log(
  1144. '🚀 ~ file: WXtrialInterface.html ~ line 973 ~ sourceType',
  1145. sourceType,
  1146. );
  1147. // 拉取广告数据
  1148. function getAD() {
  1149. return $.ajax({
  1150. url: baseUrl + '/api/public/v5/advertising/getAdInfoByAdPlace',
  1151. headers: {
  1152. Authorization: token,
  1153. },
  1154. data: JSON.stringify({
  1155. adPlace: adType,
  1156. os: 0,
  1157. }),
  1158. type: 'POST',
  1159. dataType: 'json',
  1160. contentType: 'application/json;charset=UTF-8',
  1161. }).then(function (res) {
  1162. if (res.status === 0) {
  1163. var list = res.data.filter(
  1164. (v) => v.adType === 1 && !!v.adVideoBase.videoUrl,
  1165. );
  1166. adData = list[Math.floor(Math.random() * list.length)];
  1167. console.log(
  1168. '🚀 ~ file: WXtrialInterface.html ~ line 990 ~ getAD ~ adData',
  1169. adData,
  1170. );
  1171. return adData;
  1172. } else {
  1173. return Promise.reject(new Error(res.msg));
  1174. }
  1175. });
  1176. }
  1177. // 播放广告
  1178. function playAD() {
  1179. var nowTime = Date.now();
  1180. if (
  1181. adData &&
  1182. // [1, 2].includes(sourceType) &&
  1183. $('.try-use-wrap').eq(0).is(':hidden') &&
  1184. nowTime > adLastTime + intervalTime
  1185. ) {
  1186. $('#source').attr('src', adData.adVideoBase.videoUrl);
  1187. $('.try-use-wrap').eq(0).show();
  1188. $('#source')[0].play();
  1189. videoTime = adData.forcedTime;
  1190. adData = null;
  1191. adLastTime = nowTime;
  1192. videoTimer = setInterval(() => {
  1193. if (videoTime > 0) {
  1194. videoTime--;
  1195. $('.time-node')
  1196. .eq(0)
  1197. .text(videoTime + 's');
  1198. } else {
  1199. clearInterval(videoTimer);
  1200. $('.time-node').eq(0).text('');
  1201. }
  1202. }, 1000);
  1203. if (intervalTime > 0) {
  1204. // 间隔广告拉取下一次广告数据
  1205. adType = 16;
  1206. getAD();
  1207. }
  1208. if (adType === 16 && sourceType == 1) {
  1209. // 间隔广告和试用才上报
  1210. report(0);
  1211. }
  1212. }
  1213. }
  1214. /**
  1215. * 初始化广告
  1216. * 因移动端video无法自动播放,play()方法不能异步调用。
  1217. * 解决方案,初始化时预先请求广告数据,在用户对云手机touchmove事件中去播放广告并请求下一次广告数据。
  1218. */
  1219. function initAD() {
  1220. console.log(
  1221. '🚀 ~ file: WXtrialInterface.html ~ line 1052 ~ initAD ~ sourceType',
  1222. sourceType,
  1223. );
  1224. (function () {
  1225. switch (sourceType) {
  1226. case 1: {
  1227. return getSetmealList().then(function (res) {
  1228. intervalTime =
  1229. res.intervalSwitch === 1
  1230. ? res.intervalAdvertDuration * 1000 * 60
  1231. : 0;
  1232. if (res.pushFlowAdvert === 1) {
  1233. adType = 15;
  1234. adTime = 0;
  1235. } else if (intervalTime > 0) {
  1236. adType = 16;
  1237. adTime = date.now();
  1238. }
  1239. });
  1240. }
  1241. case 2: {
  1242. return getConfigByPhoneType().then(function (res) {
  1243. if (res.isDisconnectionTime === 1) {
  1244. var time = res.disconnectionTime * 60 * 1000;
  1245. setTimeout(() => {
  1246. disconnectionFlag = true;
  1247. $('.buy-phone-wrap').eq(0).show();
  1248. }, time);
  1249. }
  1250. intervalTime =
  1251. res.isIntervalPlayAd === 1
  1252. ? res.intervalPlayAdTime * 1000 * 60
  1253. : 0;
  1254. if (res.isShowAd === 1) {
  1255. adType = 15;
  1256. adTime = 0;
  1257. } else if (intervalTime > 0) {
  1258. adType = 16;
  1259. adTime = date.now();
  1260. }
  1261. });
  1262. }
  1263. default: {
  1264. return Promise.reject();
  1265. }
  1266. }
  1267. })().then(function () {
  1268. console.log(adType);
  1269. this.$('#wine').on('touchstart', playAD);
  1270. getAD();
  1271. });
  1272. }
  1273. //广告信息
  1274. // function adInit() {
  1275. // sourceType = parameters['sourceType'];
  1276. // if (sourceType == 1) {
  1277. // getSetmealList().then((res) => {
  1278. // if (res.pushFlowAdvert === 1) {
  1279. // getAdList(15);
  1280. // }
  1281. // if (res.intervalSwitch === 1) {
  1282. // let time = res.intervalAdvertDuration * 60 * 1000;
  1283. // setInterval(() => {
  1284. // $('.try-use-wrap').eq(0).hide();
  1285. // getAdList(16);
  1286. // }, time);
  1287. // }
  1288. // })
  1289. // } else if (sourceType == 2) {
  1290. // getConfigByPhoneType().then((res) => {
  1291. // if (res.isDisconnectionTime === 1) {
  1292. // let time = res.disconnectionTime * 60 * 1000;
  1293. // setTimeout(() => {
  1294. // disconnectionFlag = true;
  1295. // $('.buy-phone-wrap').eq(0).show();
  1296. // }, time);
  1297. // }
  1298. // if (res.isShowAd === 1) {
  1299. // getAdList(15);
  1300. // }
  1301. // if (res.isIntervalPlayAd === 1) {
  1302. // let time = res.intervalPlayAdTime * 60 * 1000;
  1303. // setInterval(() => {
  1304. // $('.try-use-wrap').eq(0).hide();
  1305. // getAdList(16);
  1306. // }, time);
  1307. // }
  1308. // })
  1309. // }
  1310. // }
  1311. // 广告接口
  1312. // function getAdList(type) {
  1313. // adType = type;
  1314. // $.ajax({
  1315. // url: baseUrl + '/api/public/v5/advertising/getAdInfoByAdPlace',
  1316. // headers: {
  1317. // Authorization: form.token,
  1318. // },
  1319. // data: JSON.stringify({
  1320. // adPlace: type,
  1321. // os: 0,
  1322. // }),
  1323. // type: 'POST',
  1324. // dataType: 'json',
  1325. // contentType: 'application/json;charset=UTF-8',
  1326. // success: function (res) {
  1327. // if (res.status === 0) {
  1328. // let list = res.data;
  1329. // let indexs = Math.floor(Math.random() * list.length);
  1330. // videoTime = list[indexs].forcedTime;
  1331. // // $('#source').src = list[0].adVideoBase.videoUrl;
  1332. // $('#source').attr('src', list[indexs].adVideoBase.videoUrl); //更新url
  1333. // $('#source').attr('autoplay', 'true'); //直接播放
  1334. // videoTimer = setInterval(() => {
  1335. // if (videoTime > 0) {
  1336. // videoTime--;
  1337. // $('.time-node')
  1338. // .eq(0)
  1339. // .text(videoTime + 's');
  1340. // } else {
  1341. // clearInterval(videoTimer);
  1342. // $('.time-node').eq(0).text('');
  1343. // }
  1344. // }, 1000);
  1345. // if (adType === 16 && sourceType == 1) {
  1346. // // 间隔广告和试用才上报
  1347. // report(0);
  1348. // }
  1349. // $('.try-use-wrap').eq(0).show();
  1350. // } else {
  1351. // $.toast(res.msg, 'text');
  1352. // }
  1353. // },
  1354. // });
  1355. // }
  1356. //间隔广告上报
  1357. function report(type) {
  1358. $.ajax({
  1359. url: baseUrl + '/api/resources/v1/trial/report',
  1360. headers: {
  1361. Authorization: token,
  1362. },
  1363. data: JSON.stringify({
  1364. userCardId: userCardId,
  1365. reportType: type,
  1366. }),
  1367. type: 'POST',
  1368. dataType: 'json',
  1369. contentType: 'application/json;charset=UTF-8',
  1370. success: function (res) {},
  1371. });
  1372. }
  1373. // 观看广告次数上报
  1374. function reportFrequency() {
  1375. $.ajax({
  1376. url:
  1377. baseUrl +
  1378. '/api/resoures/v1/trial/reportFrequency/' +
  1379. form.userCardId,
  1380. headers: {
  1381. Authorization: form.token,
  1382. },
  1383. type: 'post',
  1384. contentType: 'application/json',
  1385. dataType: 'json',
  1386. success: function (res) {},
  1387. });
  1388. }
  1389. //关闭广告
  1390. $('.time-close-wrap')[0].addEventListener('click', () => {
  1391. if (videoTime == 0) {
  1392. reportFrequency();
  1393. }
  1394. $('.buy-phone-wrap').eq(0).show();
  1395. });
  1396. // 点击取消
  1397. $('.cannel-btn')[0].addEventListener('click', () => {
  1398. $('.buy-phone-wrap').eq(0).hide();
  1399. if (disconnectionFlag || getDate) {
  1400. //设置了断线时间,取消直接退出
  1401. systemBuriedPoint('激活码-断线-取消');
  1402. quit();
  1403. return;
  1404. }
  1405. let pointName = '';
  1406. if (sourceType == 1) {
  1407. pointName =
  1408. videoTime == 0 ? '免费试用-关闭-取消' : '免费试用-强制关闭-取消';
  1409. } else {
  1410. pointName =
  1411. videoTime == 0 ? '激活码-关闭-取消' : '激活码-强制关闭-取消';
  1412. }
  1413. systemBuriedPoint(pointName);
  1414. if (videoTime == 0) {
  1415. if (adType === 16 && sourceType == 1) {
  1416. report(1);
  1417. }
  1418. $('.try-use-wrap').eq(0).hide();
  1419. $('#source')[0].pause();
  1420. return;
  1421. }
  1422. $('.look-wrap').eq(0).show();
  1423. });
  1424. // 点击去购买
  1425. $('.go-bug')[0].addEventListener('click', () => {
  1426. let pointName = '';
  1427. if (disconnectionFlag) {
  1428. pointName = '激活码-断线-去购买';
  1429. } else if (sourceType == 1) {
  1430. pointName =
  1431. videoTime == 0
  1432. ? '免费试用-关闭-去购买'
  1433. : '免费试用-强制关闭-去购买';
  1434. } else {
  1435. pointName =
  1436. videoTime == 0 ? '激活码-关闭-去购买' : '激活码-强制关闭-去购买';
  1437. }
  1438. systemBuriedPoint(pointName);
  1439. if (getDate) {
  1440. wx.miniProgram.navigateTo({
  1441. url: '/packageA/order/buy/index?buyType=试用界面购买',
  1442. });
  1443. } else {
  1444. // 过期续费按钮进入
  1445. wx.miniProgram.navigateTo({
  1446. url:
  1447. `/packageA/order/renew/index?buyType=${
  1448. sourceType == 1
  1449. ? '试用弹窗购买按钮进入-普通试用'
  1450. : '试用弹窗购买按钮进入-激活码试用'
  1451. }&record=` + userCardId,
  1452. });
  1453. }
  1454. });
  1455. // 放弃
  1456. $('.cannel-ad-btn')[0].addEventListener('click', () => {
  1457. if (sourceType == 1) {
  1458. systemBuriedPoint('免费试用-强制关闭-放弃');
  1459. } else {
  1460. systemBuriedPoint('激活码-强制关闭-放弃');
  1461. }
  1462. quit();
  1463. });
  1464. // 继续观看
  1465. $('.looking')[0].addEventListener('click', () => {
  1466. $('.look-wrap').eq(0).hide();
  1467. if (sourceType == 1) {
  1468. systemBuriedPoint('免费试用-强制关闭-继续观看');
  1469. } else {
  1470. systemBuriedPoint('激活码-强制关闭-继续观看');
  1471. }
  1472. });
  1473. // 埋点
  1474. function systemBuriedPoint(pointName) {
  1475. $.ajax({
  1476. url: baseUrl + '/api/public/v1/systemBuriedPoint/stat',
  1477. headers: {
  1478. Authorization: token,
  1479. },
  1480. type: 'post',
  1481. data: JSON.stringify({
  1482. pointName: pointName,
  1483. }),
  1484. contentType: 'application/json',
  1485. dataType: 'json',
  1486. success: function (res) {},
  1487. });
  1488. }
  1489. function quit() {
  1490. if (navigator.userAgent.toLowerCase().includes('toutiaomicroapp')) {
  1491. tt.miniProgram.switchTab({
  1492. url: '/pages/home/home',
  1493. });
  1494. } else if (window.__wxjs_environment === 'miniprogram') {
  1495. wx.miniProgram.switchTab({
  1496. url: '/pages/home/home',
  1497. });
  1498. } else {
  1499. uni.webView.navigateBack({
  1500. delta: 1,
  1501. });
  1502. }
  1503. }
  1504. window.onbeforeunload = function () {
  1505. ws.close();
  1506. wsss.close();
  1507. };
  1508. function updatePhoneSizeListHtml() {
  1509. const templatePhoneSizeItem = doT.template(
  1510. $('#template-phone-size-item').html().replace(/&amp;/g, '&'),
  1511. );
  1512. const phoneSizeListItemsHtml = templatePhoneSizeItem({
  1513. list: window.phoneSizeList,
  1514. active: window.activePhoneSize,
  1515. });
  1516. $('#phone-size-list').html(phoneSizeListItemsHtml);
  1517. }
  1518. $('#open-set-phone-size-dialog-btn').on('click', function (e) {
  1519. window.activePhoneSize = window.currentPhoneSize;
  1520. updatePhoneSizeListHtml();
  1521. $('#set-phone-size-dialog').addClass('show');
  1522. });
  1523. // $('#set-phone-size-dialog').addClass('show');
  1524. $('.dialog .dialog-mask')
  1525. .add('.dialog .dialog-btn.cancel')
  1526. .on('click', function (e) {
  1527. $(e.currentTarget).parents('.dialog').removeClass('show');
  1528. });
  1529. // 分辨率列表
  1530. window.phoneSizeList = [];
  1531. // 当前生效的分辨率
  1532. window.currentPhoneSize = {
  1533. width: 720,
  1534. height: 1280,
  1535. };
  1536. // 选中的分辨率
  1537. window.activePhoneSize = window.currentPhoneSize;
  1538. function getPhoneSizeList() {
  1539. return $.ajax({
  1540. url:
  1541. baseUrl + '/api/resources/v5/machine/resolution/getResolvingPower',
  1542. headers: {
  1543. Authorization: token,
  1544. },
  1545. type: 'get',
  1546. dataType: 'json',
  1547. data: {
  1548. userCardId,
  1549. },
  1550. }).then(function (response) {
  1551. return response.data.map(function (v) {
  1552. return {
  1553. id: v.id,
  1554. dpi: v.dpi,
  1555. width: v.width || v.abscissa,
  1556. height: v.height || v.ordinate || v.high,
  1557. };
  1558. });
  1559. });
  1560. }
  1561. getPhoneSizeList().then(function (phoneSizeList) {
  1562. window.phoneSizeList = phoneSizeList;
  1563. const currentPhoneSize = window.phoneSizeList.find(function (v) {
  1564. return (
  1565. v.width === window.currentPhoneSize.width &&
  1566. v.height === window.currentPhoneSize.height
  1567. );
  1568. });
  1569. window.currentPhoneSize = currentPhoneSize || window.currentPhoneSize;
  1570. return updatePhoneSizeListHtml();
  1571. });
  1572. // const phoneSizeListSwiper = new Swiper('#phone-size-list-swiper', {
  1573. // direction: 'vertical',
  1574. // slidesPerView: 'auto',
  1575. // loop: false,
  1576. // centeredSlides: true,
  1577. // });
  1578. function setPhoneSize(config) {
  1579. wsss.send(
  1580. JSON.stringify({
  1581. type: 'setPhoneSize',
  1582. data: {
  1583. width: config.width,
  1584. height: config.height,
  1585. },
  1586. }),
  1587. );
  1588. wsss.send(
  1589. JSON.stringify({
  1590. type: 'forwardMsg',
  1591. data: {
  1592. code: 'phoneSizeChange',
  1593. id: config.id,
  1594. width: config.width,
  1595. height: config.height,
  1596. desc: '分辨率修改', // 可选
  1597. },
  1598. }),
  1599. );
  1600. $.ajax({
  1601. url:
  1602. baseUrl +
  1603. '/api/resources/v5/machine/resolution/operationResolvingPower',
  1604. headers: {
  1605. Authorization: token,
  1606. },
  1607. type: 'post',
  1608. dataType: 'json',
  1609. contentType: 'application/json; charset=UTF-8',
  1610. data: JSON.stringify({
  1611. userCardId: window.userCardId,
  1612. width: config.width,
  1613. height: config.height,
  1614. resolvingPowerId: config.id,
  1615. }),
  1616. });
  1617. window.currentPhoneSize = config;
  1618. }
  1619. // wsss.addEventListener('message', function (event) {
  1620. // console.log(
  1621. // '🚀 ~ file: WXtrialInterface.html ~ line 1476 ~ event',
  1622. // event,
  1623. // );
  1624. // });
  1625. $('#phone-size-list').on('click', '.phone-size-item', function (e) {
  1626. const data = $(e.currentTarget).data();
  1627. window.activePhoneSize = data;
  1628. updatePhoneSizeListHtml();
  1629. // setPhoneSize(data.width, data.height);
  1630. });
  1631. $('#set-phone-size-dialog .dialog-btn.confirm').on('click', function (e) {
  1632. setPhoneSize(window.activePhoneSize);
  1633. $('#set-phone-size-dialog').removeClass('show');
  1634. });
  1635. </script>
  1636. <script type="text/javascript" src="WXdraw.js"></script>
  1637. <script type="text/javascript" src="aac.js"></script>
  1638. </body>
  1639. </html>