WXtrialInterface.html 59 KB

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