WXtrialInterface.html 60 KB

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