WXtrialInterface.html 59 KB

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