WXtrialInterface.html 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8" />
  5. <title></title>
  6. <meta name="x5-orientation" content="portrait" />
  7. <meta name="screen-orientation" content="portrait" />
  8. <meta name="apple-mobile-web-app-capable" content="yes" />
  9. <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
  10. <!-- 删除苹果默认的工具栏和菜单栏 -->
  11. <meta name="apple-mobile-web-app-status-bar-style" content="black" />
  12. <!-- 设置苹果工具栏颜 -->
  13. <meta name="format-detection" content="telphone=no, email=no" />
  14. <!-- 忽略页面中的数字识别为电话,忽略email识别 -->
  15. <!-- 启用360浏览器的极速模(webkit) -->
  16. <meta name="renderer" content="webkit" />
  17. <!-- 避免IE使用兼容模式 -->
  18. <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  19. <!-- 针对手持设备优化,主要是针对一些老的不识别viewport的浏览器,比如黑 -->
  20. <meta name="HandheldFriendly" content="true" />
  21. <!-- 微软的老式浏览 -->
  22. <meta name="MobileOptimized" content="320" />
  23. <!-- 不能旋转,问题出在这 -->
  24. <!-- UC强制全屏 -->
  25. <meta name="full-screen" content="yes" />
  26. <!-- QQ强制全屏 -->
  27. <meta name="x5-fullscreen" content="true" />
  28. <!-- UC应用模式 -->
  29. <meta name="browsermode" content="application" />
  30. <!-- QQ应用模式 -->
  31. <meta name="x5-page-mode" content="app" />
  32. <!-- windows phone 点击无高 -->
  33. <meta name="msapplication-tap-highlight" content="no" />
  34. <link rel="stylesheet" type="text/css" href="css/WXtrialInterface.css" />
  35. <link rel="stylesheet" href="https://cdn.bootcss.com/weui/1.1.3/style/weui.min.css" />
  36. <link rel="stylesheet" href="https://cdn.bootcss.com/jquery-weui/1.2.1/css/jquery-weui.min.css" />
  37. </head>
  38. <body class="scroll h-player" style="overscroll-behavior: contain">
  39. <div class="container" id="player">
  40. <div class="muted" id="btnMuted">
  41. <div class="control-right-img" data-id="1">
  42. <img src="../static/img/xuanfu_icon.png" />
  43. </div>
  44. </div>
  45. <div id="wine">
  46. <div id="box">
  47. <canvas id="playCanvas" width="450" height="800"></canvas>
  48. </div>
  49. </div>
  50. <div class="leftmains">
  51. <div class="PictureQualityMain">
  52. <div class="PictureQuality" data-id="4">高清</div>
  53. <div class="PictureQuality avit" data-id="3">标清</div>
  54. <div class="PictureQuality" data-id="2">极速</div>
  55. </div>
  56. <div class="operation">
  57. <div class="upload" id="showsuss" data-text="uploads">
  58. <img src="../static/img/wx/shangchuan_icon.png" />
  59. <div>上传</div>
  60. </div>
  61. <div class="upload" onclick="showShearPlate()" data-text="Shearplate">
  62. <img src="../static/img/wx/jianqieban_icon.png" />
  63. <div>剪贴板</div>
  64. </div>
  65. <div class="upload" id="upload" data-text="Signout">
  66. <img src="../static/img/wx/tuichu_icon.png" />
  67. <div>退出</div>
  68. </div>
  69. </div>
  70. </div>
  71. <div class="bottommains">
  72. <div class="botmat1">
  73. <div class="botmat1img" data-text="gengduo">
  74. <img src="../static/img/wx/gengduo_icon.png" />
  75. </div>
  76. </div>
  77. <div class="botmat1">
  78. <div class="botmat1img" data-text="home">
  79. <img src="../static/img/wx/home_icon.png" />
  80. </div>
  81. </div>
  82. <div class="botmat1">
  83. <div class="botmat1img" data-text="return">
  84. <img src="../static/img/wx/fanhui_icon.png" />
  85. </div>
  86. </div>
  87. </div>
  88. <img class="loading loading_sceen_pic" />
  89. </div>
  90. <div class="mask">
  91. <div class="box-shear-plate"></div>
  92. <img class="close" onclick="handleClose()" src="img/guanbi_icon@2x.png" alt="" />
  93. </div>
  94. <div class="weui-mask_transparent"></div>
  95. <div class="weui-toast weui_loading_toast weui-toast--visible">
  96. <div class="weui_loading">
  97. <i class="weui-loading weui-icon_toast"></i>
  98. </div>
  99. <p class="weui-toast_content">数据加载中</p>
  100. </div>
  101. <div class="try-use-wrap">
  102. <div class="try-use-container">
  103. <video width="100%" height="100%" id="source" autoplay="autoplay" loop="loop" webkit-playsinline="true"
  104. playsinline="true" x5-video-player-type="h5-page">
  105. 您的浏览器不支持 video 标签。
  106. </video>
  107. <div class="time-close-wrap"><span class="time-node"></span> 关闭</div>
  108. </div>
  109. </div>
  110. <div class="buy-phone-wrap">
  111. <div class="bug-wrap">
  112. <div class="bug-title">获得极致体验服务请购买云手机</div>
  113. <div class="btn-list">
  114. <div class="btn cannel-btn">取消</div>
  115. <div class="btn go-bug">去购买</div>
  116. </div>
  117. </div>
  118. </div>
  119. <div class="look-wrap">
  120. <div class="bug-wrap">
  121. <div class="bug-title">关闭广告会退出云手机是否继续观看</div>
  122. <div class="btn-list">
  123. <div class="btn cannel-btn cannel-ad-btn">放弃</div>
  124. <div class="btn go-bug looking">继续观看</div>
  125. </div>
  126. </div>
  127. </div>
  128. <script type="text/javascript" src="https://res.wx.qq.com/open/js/jweixin-1.3.2.js"></script>
  129. <script src="https://lf1-cdn-tos.bytegoofy.com/goofy/developer/jssdk/jssdk-1.0.3.js"></script>
  130. <script type="text/javascript" src="jquery-1.11.0.min.js"></script>
  131. <!-- ffm软解 -->
  132. <script type="text/javascript" src="helper.js"></script>
  133. <script type="text/javascript" src="jquery-weui.min.js"></script>
  134. <script type="text/javascript" src="pcm-player.js"></script>
  135. <script type="text/javascript" src="webgl.js"></script>
  136. <script type="text/javascript" src="https://cdn.bootcss.com/vConsole/3.2.0/vconsole.min.js"></script>
  137. <script type="text/javascript" src="https://js.cdn.aliyun.dcloud.net.cn/dev/uni-app/uni.webview.1.5.2.js"></script>
  138. <script type="text/javascript">
  139. $(function () {
  140. //手指滑动多少距离就认为是滑成功
  141. //这个值不能太大,否则影响斜着滑动时,垂直滑动的流畅性,也不能太小,太灵敏也不好
  142. var diffXDistance = 50;
  143. //当前滑动的对象
  144. var currentObject;
  145. //上一次滑动的对象
  146. var lastObject;
  147. //是否可以左右滑动,在上下滑的时候禁止左右滑
  148. var canSlide = true;
  149. //用于记录按下的点
  150. var startPoint;
  151. $('.slide-content').css({
  152. width: $('.slide-wrapper').width(),
  153. });
  154. $('.slide-scroll')
  155. .css({
  156. width:
  157. $('.slide-wrapper').width() + $('.slide-content-button').width(),
  158. })
  159. .on('touchstart', function (e) {
  160. currentObject = this;
  161. startPoint = {
  162. x: e.originalEvent.changedTouches[0].pageX,
  163. y: e.originalEvent.changedTouches[0].pageY,
  164. };
  165. })
  166. .on('touchmove', function (e) {
  167. //如果是左右滑动,就禁止上下的滑动
  168. //如果是上下的滑动,就禁止左右滑动
  169. if (
  170. Math.abs(e.originalEvent.changedTouches[0].pageX - startPoint.x) >
  171. Math.abs(e.originalEvent.changedTouches[0].pageY - startPoint.y)
  172. ) {
  173. event.preventDefault();
  174. } else {
  175. canSlide = false;
  176. }
  177. })
  178. .on('touchend', function (e) {
  179. //如果是上下滑动,这里就直接返回了
  180. if (!canSlide) {
  181. canSlide = true;
  182. return true;
  183. }
  184. //点击除当前左滑对象之外的任意其他位置
  185. if (lastObject && currentObject != lastObject) {
  186. //右滑→
  187. $(lastObject).removeClass('animate-slide');
  188. //清空上一个左滑的对象
  189. lastObject = undefined;
  190. }
  191. var diffX = e.originalEvent.changedTouches[0].pageX - startPoint.x;
  192. if (diffX < -diffXDistance) {
  193. //左滑←
  194. $(currentObject).addClass('animate-slide');
  195. if (lastObject && lastObject != currentObject) {
  196. //右滑→
  197. $(lastObject).removeClass('animate-slide');
  198. }
  199. //记录上一个左滑的对象
  200. lastObject = currentObject;
  201. } else if (diffX >= diffXDistance) {
  202. if (currentObject == lastObject) {
  203. //右滑→
  204. $(currentObject).removeClass('animate-slide');
  205. //清空上一个左滑的对象
  206. lastObject = undefined;
  207. }
  208. }
  209. });
  210. });
  211. </script>
  212. <script>
  213. var videoTimer = null,
  214. videoTime = 0,
  215. adType = 0,
  216. sourceType = isNaN(parameters['sourceType'])
  217. ? sourceType
  218. : +parameters['sourceType'],
  219. disconnectionFlag = false,
  220. getDate = false;
  221. // 开发环境
  222. var isDev =
  223. /^192\.168\./.test(location.host) || /^localhost/.test(location.host);
  224. if (isDev) {
  225. baseUrl = 'http://gntest.phone.androidscloud.com:1280';
  226. sourceType = 2;
  227. }
  228. var topwinHeight = window.screen.height - window.innerHeight + 30; //计算title top 头部
  229. var url = window.location.href;
  230. url = url.split('/');
  231. var baseUrl = url[0] + '//' + url[2];
  232. console.log(baseUrl);
  233. var parameters = GetRequest();
  234. var token = parameters['token'];
  235. var mealType = parameters['mealType'];
  236. var userCardId = parameters['userCardId'];
  237. if (mealType === 'VIP') {
  238. $('.loading_sceen_pic').attr('src', '../static/img/home_bg_VIP.png');
  239. } else if (mealType === 'SVIP') {
  240. $('.loading_sceen_pic').attr('src', '../static/img/home_bg_SVIP.png');
  241. } else if (mealType === 'STAR') {
  242. $('.loading_sceen_pic').attr('src', '../static/img/home_bg_STAR.png');
  243. } else if (mealType === 'STARPRO') {
  244. $('.loading_sceen_pic').attr('src', '../static/img/home_bg_PRO.png');
  245. }
  246. $('#wine').css({
  247. width: window.screen.width,
  248. height: window.screen.height - topwinHeight - 20,
  249. position: 'absolute',
  250. });
  251. $('.loading').css({
  252. width: window.screen.width,
  253. height: window.screen.height - topwinHeight - 20,
  254. });
  255. var winese = document.createElement('wine');
  256. wine.style.top = '-' + winese + 'px';
  257. var isAudioPlay = false;
  258. let dbName = parameters['username'], version = 1, storeName = 'usercard'
  259. let indexedDB = window.indexedDB;
  260. let db
  261. var socketURL
  262. var cUrl
  263. var cardToken
  264. const request = indexedDB.open(dbName, version)
  265. request.onsuccess = function (event) {
  266. db = event.target.result // 数据库对象
  267. console.log('数据库打开成功')
  268. }
  269. request.onerror = function (event) {
  270. console.log('数据库打开报错')
  271. }
  272. request.onupgradeneeded = function (event) {
  273. // 数据库创建或升级的时候会触发
  274. console.log('onupgradeneeded')
  275. db = event.target.result // 数据库对象
  276. let objectStore
  277. if (!db.objectStoreNames.contains(storeName)) {
  278. objectStore = db.createObjectStore(storeName, { keyPath: 'id' }) // 创建表
  279. }
  280. }
  281. // 添加数据
  282. function addData(db, storeName, data) {
  283. let request = db.transaction([storeName], 'readwrite') // 事务对象 指定表格名称和操作模式("只读"或"读写")
  284. .objectStore(storeName) // 仓库对象
  285. .add(data)
  286. request.onsuccess = function (event) {
  287. console.log('数据写入成功')
  288. }
  289. request.onerror = function (event) {
  290. console.log('数据写入失败')
  291. throw new Error(event.target.error)
  292. }
  293. }
  294. // 根据id获取数据
  295. function getDataByKey(db, storeName, key) {
  296. let transaction = db.transaction([storeName]) // 事务
  297. let objectStore = transaction.objectStore(storeName) // 仓库对象
  298. let request = objectStore.get(key)
  299. request.onerror = function (event) {
  300. connect('add');
  301. }
  302. request.onsuccess = function (event) {
  303. console.log('主键查询结果: ', request.result)
  304. if (request.result) {
  305. socketURL = request.result.socketURL;
  306. cUrl = request.result.cUrl;
  307. cardToken = request.result.cardToken;
  308. resolvingPower = request.result.resolvingPower;
  309. doConnectBusiness();
  310. doConnectDirectives();
  311. } else {
  312. connect('add');
  313. }
  314. }
  315. }
  316. // 根据id修改数
  317. function updateDB(db, storeName, data) {
  318. let request = db.transaction([storeName], 'readwrite') // 事务对象
  319. .objectStore(storeName) // 仓库对象
  320. .put(data)
  321. request.onsuccess = function () {
  322. console.log('数据更新成功')
  323. }
  324. request.onerror = function () {
  325. console.log('数据更新失败')
  326. }
  327. }
  328. // 由于打开indexDB是异步的加个定时器避免 db对象还没获取到值导致 报错
  329. setTimeout(() => {
  330. getDataByKey(db, storeName, userCardId)
  331. }, 1000);
  332. function connect() {
  333. $.ajax({
  334. url: baseUrl + "/api/resources/user/cloud/connect",
  335. type: 'post',
  336. data: JSON.stringify({
  337. "userCardId": Number(userCardId)
  338. }),
  339. headers: {
  340. 'content-Type': 'application/json',
  341. 'Authorization': token
  342. },
  343. dataType: 'json',
  344. async: false,
  345. success: function (res) {
  346. if (res.status === 0) {
  347. if (res.data.internetHttps) {
  348. socketURL = 'wss://' + res.data.internetHttps + '/plugflow?cardIp=' + res.data.localIp + '&token=' + res.data.cardToken + '&type=business';
  349. cUrl = "wss://" + res.data.internetHttps + "/businessChannel?cardIp=" + res.data.localIp + "&token=" + res.data.cardToken + "&type=directives";
  350. cardToken = res.data.cardToken;
  351. resolvingPower = res.data.resolvingPower;
  352. doConnectBusiness();
  353. doConnectDirectives();
  354. if (type === 'add') {
  355. addData(db, storeName, { id: userCardId, socketURL: socketURL, cUrl: cUrl, cardToken: res.data.cardToken, resolvingPower: res.data.resolvingPower })
  356. } else {
  357. updateDB(db, storeName, { id: userCardId, socketURL: socketURL, cUrl: cUrl, cardToken: res.data.cardToken, resolvingPower: res.data.resolvingPower })
  358. }
  359. } else {
  360. $.toast("网络异常,请稍后重试", 'text');
  361. }
  362. } else {
  363. $.toast('画面异常,请重新进入', 'text');
  364. clearInterval(intervaler);
  365. quit();
  366. ws.close();
  367. wsss.close();
  368. }
  369. }
  370. });
  371. }
  372. initAD();
  373. $.alert({
  374. title: '提示',
  375. text: '开始使用云手机',
  376. onOK: function () {
  377. isAudioPlay = true;
  378. },
  379. });
  380. //云机倒计时
  381. let validTime = parameters['validTime'] || 10000;
  382. if (validTime > 32000) {
  383. validTime = 32000;
  384. }
  385. let detailTime = validTime * 60 * 1000;
  386. setTimeout(() => {
  387. $('.bug-title').eq(0).text('尊敬的用户您的云手机试用时间已到期');
  388. getDate = true;
  389. $('.buy-phone-wrap').eq(0).show();
  390. }, detailTime);
  391. var orientation = 0; //0 竖屏,1横屏
  392. function array_unique(arr) {
  393. return arr.filter(function (e, i) {
  394. return arr.indexOf(e) === i;
  395. });
  396. }
  397. var cutList = [];
  398. let timer,
  399. isFlag = true;
  400. function showShearPlate() {
  401. stopManyClick(() => {
  402. $('.box-shear-plate').empty();
  403. $.ajax({
  404. url: baseUrl + '/api/public/v5/shear/content',
  405. headers: {
  406. Authorization: token,
  407. },
  408. type: 'get',
  409. dataType: 'json',
  410. success: function (res) {
  411. if (res.status === 0) {
  412. if (res.data.length) {
  413. cutList = array_unique(res.data);
  414. var str =
  415. '<div class="title">剪贴板<div onclick="handleClear()" class="btn-clear">清空</div></div><div class="slide-wrapper-content">';
  416. cutList.forEach(function (item) {
  417. str +=
  418. "<div class='slide-wrapper'><div class='slide-scroll animate-slide-start'><div class='slide-content'><div onclick='handleCopy(\"" +
  419. item.content +
  420. '")\'>' +
  421. item.content +
  422. "</div></div><div class='slide-content-button'><button onclick='handleDelete(" +
  423. item.id +
  424. ")'>删除</button></div></div></div>";
  425. });
  426. str += '</div>';
  427. $('.box-shear-plate').append(str);
  428. } else {
  429. $('.box-shear-plate').append(
  430. '<img class="empty" src="img/jianqieban_pic@2x.png" alt="" /><div class="empty-txt">剪贴板为空</div>',
  431. );
  432. }
  433. $('.mask').show();
  434. initSlider();
  435. } else {
  436. $('.box-shear-plate').append(
  437. '<img class="empty" src="img/jianqieban_pic@2x.png" alt="" /><div class="empty-txt">剪贴板为空</div>',
  438. );
  439. $('.mask').show();
  440. }
  441. },
  442. });
  443. });
  444. }
  445. //防止提示一秒内重复显示
  446. function stopManyClick(fn) {
  447. if (isFlag) {
  448. fn();
  449. }
  450. isFlag = false;
  451. if (timer) {
  452. clearTimeout(timer);
  453. }
  454. timer = setTimeout(() => {
  455. isFlag = true;
  456. }, 1500);
  457. }
  458. // 清空剪贴板
  459. function handleClear() {
  460. var ids = '';
  461. cutList.forEach(function (item) {
  462. ids += 'ids=' + item.id + '&';
  463. });
  464. ids = ids.substring(0, ids.lastIndexOf('&'));
  465. $.confirm('确定清空剪贴板?', function () {
  466. $.ajax({
  467. url: baseUrl + '/api/public/v5/shear/content?' + ids,
  468. headers: {
  469. Authorization: token,
  470. },
  471. type: 'DELETE',
  472. dataType: 'json',
  473. success: function (res) {
  474. if (res.status === 0) {
  475. showShearPlate();
  476. } else {
  477. $.toast(res.msg, 'text');
  478. }
  479. },
  480. });
  481. });
  482. }
  483. function handleCopy(content) {
  484. var cutting = {
  485. type: 'cutting',
  486. data: {
  487. str: content,
  488. },
  489. };
  490. wsss.send(JSON.stringify(cutting));
  491. }
  492. // 删除剪贴板
  493. function handleDelete(id) {
  494. $.ajax({
  495. url: baseUrl + '/api/public/v5/shear/content?ids=' + id,
  496. headers: {
  497. Authorization: token,
  498. },
  499. type: 'DELETE',
  500. dataType: 'json',
  501. success: function (res) {
  502. if (res.status === 0) {
  503. showShearPlate();
  504. } else {
  505. $.toast(res.msg, 'text');
  506. }
  507. },
  508. });
  509. }
  510. function initSlider() {
  511. //手指滑动多少距离就认为是滑成功
  512. //这个值不能太大,否则影响斜着滑动时,垂直滑动的流畅性,也不能太小,太灵敏也不好
  513. var diffXDistance = 50;
  514. //当前滑动的对象
  515. var currentObject;
  516. //上一次滑动的对象
  517. var lastObject;
  518. //是否可以左右滑动,在上下滑的时候禁止左右滑
  519. var canSlide = true;
  520. //用于记录按下的点
  521. var startPoint;
  522. $('.slide-content').css({
  523. width: $('.slide-wrapper').width(),
  524. });
  525. document.body.removeEventListener(
  526. 'touchmove',
  527. function (e) {
  528. e.preventDefault();
  529. },
  530. {
  531. passive: false,
  532. },
  533. );
  534. $('.slide-scroll')
  535. .css({
  536. width:
  537. $('.slide-wrapper').width() + $('.slide-content-button').width(),
  538. })
  539. .on('touchstart', function (e) {
  540. currentObject = this;
  541. startPoint = {
  542. x: e.originalEvent.changedTouches[0].pageX,
  543. y: e.originalEvent.changedTouches[0].pageY,
  544. };
  545. })
  546. .on('touchmove', function (e) {
  547. //如果是左右滑动,就禁止上下的滑动
  548. //如果是上下的滑动,就禁止左右滑动
  549. if (
  550. Math.abs(e.originalEvent.changedTouches[0].pageX - startPoint.x) >
  551. Math.abs(e.originalEvent.changedTouches[0].pageY - startPoint.y)
  552. ) {
  553. event.preventDefault();
  554. } else {
  555. canSlide = false;
  556. }
  557. })
  558. .on('touchend', function (e) {
  559. //如果是上下滑动,这里就直接返回了
  560. if (!canSlide) {
  561. canSlide = true;
  562. return true;
  563. }
  564. //点击除当前左滑对象之外的任意其他位置
  565. if (lastObject && currentObject != lastObject) {
  566. //右滑→
  567. $(lastObject).removeClass('animate-slide');
  568. //清空上一个左滑的对象
  569. lastObject = undefined;
  570. }
  571. var diffX = e.originalEvent.changedTouches[0].pageX - startPoint.x;
  572. if (diffX < -diffXDistance) {
  573. //左滑←
  574. $(currentObject).addClass('animate-slide');
  575. if (lastObject && lastObject != currentObject) {
  576. //右滑→
  577. $(lastObject).removeClass('animate-slide');
  578. }
  579. //记录上一个左滑的对象
  580. lastObject = currentObject;
  581. } else if (diffX >= diffXDistance) {
  582. if (currentObject == lastObject) {
  583. //右滑→
  584. $(currentObject).removeClass('animate-slide');
  585. //清空上一个左滑的对象
  586. lastObject = undefined;
  587. }
  588. }
  589. });
  590. }
  591. var btnMuted = document.querySelector('#btnMuted');
  592. btnMuted &&
  593. (function () {
  594. var setHistory = function (left, top) {
  595. try {
  596. localStorage.setItem(
  597. 'muted-btn-loc',
  598. JSON.stringify({
  599. left: left,
  600. top: top,
  601. }),
  602. );
  603. } catch (ex) { }
  604. };
  605. var getHistory = function () {
  606. try {
  607. var value = localStorage.getItem('muted-btn-loc');
  608. if (!value) return null;
  609. value = JSON.parse(value);
  610. if (!value) return null;
  611. return value;
  612. } catch (ex) {
  613. return null;
  614. }
  615. };
  616. var fixLoc = function (loc) {
  617. var rect = btnMuted.getBoundingClientRect();
  618. rect = {
  619. top: rect.top,
  620. left: rect.left,
  621. width: rect.width,
  622. height: rect.height,
  623. }; // 部分低版本浏览器,该属性为只读
  624. if (loc) {
  625. rect.left = loc.left;
  626. rect.top = loc.top;
  627. }
  628. var minX = 0;
  629. var minY = 0;
  630. var docRect = document.documentElement.getBoundingClientRect();
  631. var maxY = docRect.height - rect.height;
  632. var maxX = docRect.width - rect.width;
  633. var left = rect.left;
  634. var top = rect.top;
  635. left = Math.min(left, maxX);
  636. left = Math.max(left, minX);
  637. top = Math.min(top, maxY);
  638. top = Math.max(top, minY);
  639. if (loc || top !== rect.top || left !== rect.left) {
  640. btnMuted.style.cssText +=
  641. 'left:' + left + 'px;top:' + top + 'px;';
  642. }
  643. };
  644. window.addEventListener('resize', function () {
  645. fixLoc();
  646. });
  647. var touchPoint = {
  648. pageY: 0,
  649. pageX: 0,
  650. };
  651. var currentLoc = {
  652. top: 0,
  653. left: 0,
  654. curTop: 0,
  655. curLeft: 0,
  656. };
  657. var toMove = false;
  658. var touchmove = function (e) {
  659. e.preventDefault();
  660. var point = e.changedTouches[0];
  661. var top = -touchPoint.pageY + point.pageY;
  662. var left = -touchPoint.pageX + point.pageX;
  663. if (toMove) {
  664. top += currentLoc.top;
  665. left += currentLoc.left;
  666. currentLoc.curLeft = left;
  667. currentLoc.curTop = top;
  668. btnMuted.style.cssText += 'left:' + left + 'px;top:' + top + 'px;';
  669. } else {
  670. if (Math.abs(top) >= 5 || Math.abs(left) >= 5) {
  671. toMove = true;
  672. }
  673. }
  674. };
  675. var touchend = function () {
  676. window.removeEventListener('touchmove', touchmove, {
  677. passive: false,
  678. });
  679. window.removeEventListener('touchend', touchend, {
  680. passive: false,
  681. });
  682. if (toMove) {
  683. setHistory(currentLoc.curLeft, currentLoc.curTop);
  684. fixLoc();
  685. } else {
  686. //按点击处理
  687. var set = $('.control-right-img').attr('data-id');
  688. if (set == '1') {
  689. $('.control-right-img').attr({
  690. 'data-id': '2',
  691. });
  692. $('.leftmains').css({
  693. right: '0rem',
  694. });
  695. } else {
  696. $('.control-right-img').attr({
  697. 'data-id': '1',
  698. });
  699. $('.leftmains').css({
  700. right: '-4rem',
  701. });
  702. }
  703. }
  704. };
  705. btnMuted.addEventListener(
  706. 'touchstart',
  707. function (e) {
  708. e.preventDefault();
  709. toMove = false;
  710. var point = e.changedTouches[0];
  711. touchPoint.pageX = point.pageX;
  712. touchPoint.pageY = point.pageY;
  713. var rect = e.target.getBoundingClientRect();
  714. currentLoc.top = rect.top;
  715. currentLoc.left = rect.left;
  716. window.addEventListener('touchmove', touchmove, {
  717. passive: false,
  718. });
  719. window.addEventListener('touchend', touchend, {
  720. passive: false,
  721. });
  722. },
  723. {
  724. passive: false,
  725. },
  726. );
  727. var history = getHistory();
  728. if (history) {
  729. fixLoc(history);
  730. }
  731. btnMuted.classList.remove('hide');
  732. })();
  733. $('#upload').on('click', function () {
  734. decodeWoker.postMessage('close');
  735. decodeWoker.terminate();
  736. webSocketWorker.terminate();
  737. quit();
  738. });
  739. function handleClose() {
  740. $('.mask').hide();
  741. }
  742. var decodeCount = 1;
  743. var isFinish = false;
  744. var player = new PCMPlayer({
  745. encoding: '16bitInt',
  746. channels: 2,
  747. sampleRate: 44100,
  748. flushingTime: 22,
  749. debug: false,
  750. });
  751. Module = {};
  752. Module.onRuntimeInitialized = function () {
  753. isFinish = true;
  754. };
  755. function decodeAAC(data) {
  756. var retPtr = Module._malloc(4 * 5 * 1024); //接收的数据
  757. var inputPtr = Module._malloc(4 * data.length); //输入数据
  758. for (var i = 0; i < data.length; i++) {
  759. Module.HEAPU8[inputPtr + i] = data[i]; //转换为堆数据
  760. }
  761. var pcmLen = Module._feedData(retPtr, inputPtr, data.length);
  762. if (pcmLen >= 0) {
  763. var pcmData = new Uint8Array(pcmLen);
  764. for (var i = 0; i < pcmLen; i++) {
  765. pcmData[i] = Module.HEAPU8[retPtr + i];
  766. }
  767. player.feed(pcmData);
  768. }
  769. decodeCount++;
  770. Module._free(inputPtr);
  771. Module._free(retPtr);
  772. }
  773. var decodeWoker = new Worker('decoder.js');
  774. var myVideo = document.getElementById('playCanvas');
  775. var logicWidth = 720;
  776. var logicHeight = 1280;
  777. decodeWoker.onmessage = function (event) {
  778. var objData = event.data;
  779. // console.log("🚀 ~ file: WXtrialInterface.html ~ line 806 ~ objData", objData)
  780. switch (objData.cmd) {
  781. case 0:
  782. break;
  783. case 1:
  784. if (logicWidth != objData.width || logicHeight != objData.height) {
  785. logicWidth = objData.width;
  786. logicHeight = objData.height;
  787. }
  788. webglPlayer.renderFrame(
  789. objData.data,
  790. logicWidth,
  791. logicHeight,
  792. logicWidth * logicHeight,
  793. (logicWidth / 2) * (logicHeight / 2),
  794. );
  795. $('.weui-mask_transparent').hide();
  796. $('.weui-toast').hide();
  797. $('.loading').hide();
  798. break;
  799. case 5:
  800. var buffer = RequestIFrame();
  801. webSocketWorker.postMessage(buffer);
  802. }
  803. };
  804. var isFinish = false;
  805. var webglPlayer = new WebGLPlayer(myVideo, {
  806. preserveDrawingBuffer: false,
  807. });
  808. function GetRequest() {
  809. var url = location.search; // 获取url中"?"符后的字串
  810. var obj = new Object();
  811. if (url.indexOf('?') != -1) {
  812. var str = url.substr(1);
  813. strs = str.split('&');
  814. for (var i = 0; i < strs.length; i++) {
  815. obj[strs[i].split('=')[0]] = strs[i].split('=')[1];
  816. }
  817. }
  818. return obj;
  819. }
  820. function doConnectBusiness() {
  821. var webSocketWorker = new Worker('websocket.js?socketURL=' + encodeURIComponent(socketURL) + '&cardToken=' + encodeURIComponent(cardToken));
  822. webSocketWorker.onmessage = function (event) {
  823. var input = event.data;
  824. if (input[0] == 0xff && isAudioPlay) {
  825. decodeAAC(input);
  826. }
  827. if (input[0] == 0 && input[1] == 0 && input[2] == 0 && input[3] == 1) {
  828. var cmd = {
  829. type: 'rawData',
  830. data: event.data,
  831. };
  832. decodeWoker.postMessage(cmd);
  833. }
  834. if (input[0] == 0x68) {
  835. if (input[23] == 0x5c) {
  836. if (CheckVerifyCode(input)) {
  837. webSocketWorker.postMessage(ConfigChannel('RK3923C1201900139'));
  838. var checkBuffer = GetScreenState();
  839. webSocketWorker.postMessage(checkBuffer);
  840. } else {
  841. connect('update');
  842. }
  843. }
  844. if (input[23] == 0x05) {
  845. //横竖屏标识
  846. var state = CheckScreenDirection(input.slice(24, 24 + 8));
  847. if (state == 1) {
  848. console.log('安卓卡此时竖屏');
  849. //竖屏处理
  850. resolving = 1;
  851. } else {
  852. console.log('安卓卡此时横屏');
  853. //横屏处理
  854. resolving = 0;
  855. }
  856. }
  857. if (input[23] == 0x0b) {
  858. console.log('多端登陆');
  859. }
  860. }
  861. if (event.data === 'close') {
  862. $.toast('画面异常,请重新进入', 'text');
  863. decodeWoker.postMessage('close');
  864. decodeWoker.terminate();
  865. webSocketWorker.terminate();
  866. quit();
  867. }
  868. };
  869. }
  870. // 激活码广告相关配置
  871. function getConfigByPhoneType() {
  872. return new Promise((resolve, reject) => {
  873. $.ajax({
  874. url: baseUrl + '/api/pay/v5/trialCodeConfig/getConfigByPhoneType',
  875. headers: {
  876. Authorization: token,
  877. },
  878. data: {
  879. userCardId: userCardId,
  880. phoneType: mealType,
  881. },
  882. type: 'get',
  883. dataType: 'json',
  884. success: function (res) {
  885. console.log(res);
  886. let obj = res.data;
  887. if (res.status === 0) {
  888. resolve(obj);
  889. } else {
  890. $.toast(res.msg, 'text');
  891. }
  892. },
  893. });
  894. });
  895. }
  896. //列表
  897. function getSetmealList() {
  898. return new Promise((resolve, reject) => {
  899. $.ajax({
  900. url: baseUrl + '/api/resources/v4/freetrial/setmeal/list',
  901. headers: {
  902. Authorization: token,
  903. },
  904. type: 'get',
  905. dataType: 'json',
  906. success: function (res) {
  907. if (res.status === 0) {
  908. let list = res.data;
  909. list.map((item) => {
  910. if (item.phoneType === mealType) {
  911. resolve(item);
  912. }
  913. });
  914. } else {
  915. $.toast(res.msg, 'text');
  916. }
  917. },
  918. });
  919. });
  920. }
  921. //广告信息
  922. var adData = null; // 广告数据
  923. var adLastTime = 0; // 广告时间
  924. var intervalTime = 0; // 间隔时间
  925. // let adType = 0;
  926. console.log(
  927. '🚀 ~ file: WXtrialInterface.html ~ line 973 ~ sourceType',
  928. sourceType,
  929. );
  930. // 拉取广告数据
  931. function getAD() {
  932. return $.ajax({
  933. url: baseUrl + '/api/public/v5/advertising/getAdInfoByAdPlace',
  934. headers: {
  935. Authorization: token,
  936. },
  937. data: JSON.stringify({
  938. adPlace: adType,
  939. os: 0,
  940. }),
  941. type: 'POST',
  942. dataType: 'json',
  943. contentType: 'application/json;charset=UTF-8',
  944. }).then(function (res) {
  945. if (res.status === 0) {
  946. var list = res.data.filter(
  947. (v) => v.adType === 1 && !!v.adVideoBase.videoUrl,
  948. );
  949. adData = list[Math.floor(Math.random() * list.length)];
  950. console.log(
  951. '🚀 ~ file: WXtrialInterface.html ~ line 990 ~ getAD ~ adData',
  952. adData,
  953. );
  954. return adData;
  955. } else {
  956. return Promise.reject(new Error(res.msg));
  957. }
  958. });
  959. }
  960. // 播放广告
  961. function playAD() {
  962. var nowTime = Date.now();
  963. if (
  964. adData &&
  965. // [1, 2].includes(sourceType) &&
  966. $('.try-use-wrap').eq(0).is(':hidden') &&
  967. nowTime > adLastTime + intervalTime
  968. ) {
  969. $('#source').attr('src', adData.adVideoBase.videoUrl);
  970. $('.try-use-wrap').eq(0).show();
  971. $('#source')[0].play();
  972. videoTime = adData.forcedTime;
  973. adData = null;
  974. adLastTime = nowTime;
  975. videoTimer = setInterval(() => {
  976. if (videoTime > 0) {
  977. videoTime--;
  978. $('.time-node')
  979. .eq(0)
  980. .text(videoTime + 's');
  981. } else {
  982. clearInterval(videoTimer);
  983. $('.time-node').eq(0).text('');
  984. }
  985. }, 1000);
  986. if (intervalTime > 0) {
  987. // 间隔广告拉取下一次广告数据
  988. adType = 16;
  989. getAD();
  990. }
  991. if (adType === 16 && sourceType == 1) {
  992. // 间隔广告和试用才上报
  993. report(0);
  994. }
  995. }
  996. }
  997. /**
  998. * 初始化广告
  999. * 因移动端video无法自动播放,play()方法不能异步调用。
  1000. * 解决方案,初始化时预先请求广告数据,在用户对云手机touchmove事件中去播放广告并请求下一次广告数据。
  1001. */
  1002. function initAD() {
  1003. console.log(
  1004. '🚀 ~ file: WXtrialInterface.html ~ line 1052 ~ initAD ~ sourceType',
  1005. sourceType,
  1006. );
  1007. (function () {
  1008. switch (sourceType) {
  1009. case 1: {
  1010. return getSetmealList().then(function (res) {
  1011. intervalTime =
  1012. res.intervalSwitch === 1
  1013. ? res.intervalAdvertDuration * 1000 * 60
  1014. : 0;
  1015. if (res.pushFlowAdvert === 1) {
  1016. adType = 15;
  1017. adTime = 0;
  1018. } else if (intervalTime > 0) {
  1019. adType = 16;
  1020. adTime = date.now();
  1021. }
  1022. });
  1023. }
  1024. case 2: {
  1025. return getConfigByPhoneType().then(function (res) {
  1026. if (res.isDisconnectionTime === 1) {
  1027. var time = res.disconnectionTime * 60 * 1000;
  1028. setTimeout(() => {
  1029. disconnectionFlag = true;
  1030. $('.buy-phone-wrap').eq(0).show();
  1031. }, time);
  1032. }
  1033. intervalTime =
  1034. res.isIntervalPlayAd === 1
  1035. ? res.intervalPlayAdTime * 1000 * 60
  1036. : 0;
  1037. if (res.isShowAd === 1) {
  1038. adType = 15;
  1039. adTime = 0;
  1040. } else if (intervalTime > 0) {
  1041. adType = 16;
  1042. adTime = date.now();
  1043. }
  1044. });
  1045. }
  1046. default: {
  1047. return Promise.reject();
  1048. }
  1049. }
  1050. })().then(function () {
  1051. console.log(adType);
  1052. this.$('#playCanvas').on('touchstart', playAD);
  1053. // this.$('#playCanvas').on('touchmove', playAD);
  1054. getAD();
  1055. });
  1056. }
  1057. //间隔广告上报
  1058. function report(type) {
  1059. $.ajax({
  1060. url: baseUrl + '/api/resources/v1/trial/report',
  1061. headers: {
  1062. Authorization: token,
  1063. },
  1064. data: JSON.stringify({
  1065. userCardId: userCardId,
  1066. reportType: type,
  1067. }),
  1068. type: 'POST',
  1069. dataType: 'json',
  1070. contentType: 'application/json;charset=UTF-8',
  1071. success: function (res) { },
  1072. });
  1073. }
  1074. //关闭广告
  1075. $('.time-close-wrap')[0].addEventListener('click', () => {
  1076. $('.buy-phone-wrap').eq(0).show();
  1077. });
  1078. // 点击取消
  1079. $('.cannel-btn')[0].addEventListener('click', () => {
  1080. $('.buy-phone-wrap').eq(0).hide();
  1081. if (disconnectionFlag || getDate) {
  1082. //设置了断线时间,取消直接退出
  1083. systemBuriedPoint('激活码-断线-取消');
  1084. quit();
  1085. return;
  1086. }
  1087. let pointName = '';
  1088. if (sourceType == 1) {
  1089. pointName =
  1090. videoTime == 0 ? '免费试用-关闭-取消' : '免费试用-强制关闭-取消';
  1091. } else {
  1092. pointName =
  1093. videoTime == 0 ? '激活码-关闭-取消' : '激活码-强制关闭-取消';
  1094. }
  1095. systemBuriedPoint(pointName);
  1096. if (videoTime == 0) {
  1097. if (adType === 16 && sourceType == 1) {
  1098. report(1);
  1099. }
  1100. $('.try-use-wrap').eq(0).hide();
  1101. $('#source')[0].pause();
  1102. return;
  1103. }
  1104. $('.look-wrap').eq(0).show();
  1105. });
  1106. // 点击去购买
  1107. $('.go-bug')[0].addEventListener('click', () => {
  1108. let pointName = '';
  1109. if (disconnectionFlag) {
  1110. pointName = '激活码-断线-去购买';
  1111. } else if (sourceType == 1) {
  1112. pointName =
  1113. videoTime == 0
  1114. ? '免费试用-关闭-去购买'
  1115. : '免费试用-强制关闭-去购买';
  1116. } else {
  1117. pointName =
  1118. videoTime == 0 ? '激活码-关闭-去购买' : '激活码-强制关闭-去购买';
  1119. }
  1120. systemBuriedPoint(pointName);
  1121. if (getDate) {
  1122. if (window.__wxjs_environment === 'miniprogram') {
  1123. wx.miniProgram.navigateTo({
  1124. url: '/packageA/order/buy/index?buyType=试用界面购买'
  1125. });
  1126. } else {
  1127. uni.webView.navigateTo({
  1128. url: '/pages/order/order',
  1129. });
  1130. }
  1131. } else {
  1132. if (window.__wxjs_environment === 'miniprogram') {
  1133. wx.miniProgram.navigateTo({
  1134. url: `/packageA/order/renew/index?buyType=${sourceType == 1 ? '试用弹窗购买按钮进入-普通试用' : '试用弹窗购买按钮进入-激活码试用'}&record=` + userCardId
  1135. });
  1136. } else {
  1137. uni.webView.navigateTo({
  1138. url: '/pages/order/order',
  1139. });
  1140. }
  1141. }
  1142. });
  1143. // 放弃
  1144. $('.cannel-ad-btn')[0].addEventListener('click', () => {
  1145. if (sourceType == 1) {
  1146. systemBuriedPoint('免费试用-强制关闭-放弃');
  1147. } else {
  1148. systemBuriedPoint('激活码-强制关闭-放弃');
  1149. }
  1150. quit();
  1151. });
  1152. // 继续观看
  1153. $('.looking')[0].addEventListener('click', () => {
  1154. $('.look-wrap').eq(0).hide();
  1155. if (sourceType == 1) {
  1156. systemBuriedPoint('免费试用-强制关闭-继续观看');
  1157. } else {
  1158. systemBuriedPoint('激活码-强制关闭-继续观看');
  1159. }
  1160. });
  1161. // 埋点
  1162. function systemBuriedPoint(pointName) {
  1163. $.ajax({
  1164. url: baseUrl + '/api/public/v1/systemBuriedPoint/stat',
  1165. headers: {
  1166. Authorization: token,
  1167. },
  1168. type: 'post',
  1169. data: JSON.stringify({
  1170. pointName: pointName,
  1171. }),
  1172. contentType: 'application/json',
  1173. dataType: 'json',
  1174. success: function (res) { },
  1175. });
  1176. }
  1177. function Close() {
  1178. // webworker 关闭,清理
  1179. var cmd = {
  1180. cmd: 0,
  1181. };
  1182. decodeWoker.postMessage(cmd);
  1183. decodeWoker.terminate();
  1184. webSocketWorker.postMessage(cmd);
  1185. webSocketWorker.terminate();
  1186. }
  1187. var isDrag = false;
  1188. myVideo.onkeydown = function (event) {
  1189. ExexuteKeyDown(e.keyCode);
  1190. };
  1191. var level = 2;
  1192. function switchSharpness() {
  1193. var cmd = {
  1194. type: 'switchSharpness',
  1195. };
  1196. decodeWoker.postMessage(cmd); //通知解码器worker切换分辨率
  1197. var buffer = makeSharpness(level);
  1198. webSocketWorker.postMessage(buffer);
  1199. if (level < 4) {
  1200. level++;
  1201. } else {
  1202. level = 0;
  1203. }
  1204. }
  1205. var hidden, visibilityChange;
  1206. if (typeof document.hidden !== 'undefined') {
  1207. // Opera 12.10 and Firefox 18 and later support
  1208. hidden = 'hidden';
  1209. visibilityChange = 'visibilitychange';
  1210. } else if (typeof document.msHidden !== 'undefined') {
  1211. hidden = 'msHidden';
  1212. visibilityChange = 'msvisibilitychange';
  1213. } else if (typeof document.webkitHidden !== 'undefined') {
  1214. hidden = 'webkitHidden';
  1215. visibilityChange = 'webkitvisibilitychange';
  1216. }
  1217. // 处理页面可见属性的改变
  1218. document.addEventListener('visibilitychange',function () {
  1219. if (document[hidden]) {
  1220. if (
  1221. !navigator.userAgent.toLowerCase().includes('toutiaomicroapp') ||
  1222. window.__wxjs_environment !== 'miniprogram'
  1223. ) {
  1224. webSocketWorker.terminate();
  1225. wsss.close();
  1226. uni.webView.navigateTo({
  1227. url: '/pages/index/index',
  1228. });
  1229. }
  1230. }
  1231. }, false);
  1232. function quit() {
  1233. if (navigator.userAgent.toLowerCase().includes('toutiaomicroapp')) {
  1234. tt.miniProgram.switchTab({
  1235. url: '/pages/home/home',
  1236. });
  1237. } else if (window.__wxjs_environment === 'miniprogram') {
  1238. wx.miniProgram.switchTab({
  1239. url: '/pages/home/home',
  1240. });
  1241. } else {
  1242. uni.webView.navigateTo({
  1243. url: '/pages/index/index',
  1244. });
  1245. }
  1246. }
  1247. window.onbeforeunload = function () {
  1248. wsss.close();
  1249. decodeWoker.postMessage('close');
  1250. decodeWoker.terminate();
  1251. webSocketWorker.terminate();
  1252. };
  1253. </script>
  1254. <script type="text/javascript" src="WXdraw.js"></script>
  1255. <script type="text/javascript" src="aac.js"></script>
  1256. </body>
  1257. </html>