WXtrialInterface.html 58 KB

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