WXtrialInterface.html 37 KB

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