WXtrialInterface.html 55 KB

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