WXtrialInterface.html 61 KB

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