WXtrialInterface.html 58 KB

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