WXtrialInterface.html 59 KB

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