WXtrialInterface.html 54 KB

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