WXtrialInterface.html 56 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766
  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. }
  723. if (input[23] == 0x0b) {
  724. //多端登录处理, 数据从索引24开始取, input 是接收到的原始数据
  725. var jsonobj = checkMultiLoginInfo(input);
  726. }
  727. }
  728. return {
  729. audio: audio,
  730. video: video,
  731. duration: duration,
  732. frameType: frameType,
  733. };
  734. }
  735. function GetRequest() {
  736. var url = location.search; // 获取url中"?"符后的字串
  737. var obj = new Object();
  738. if (url.indexOf('?') != -1) {
  739. var str = url.substr(1);
  740. strs = str.split('&');
  741. for (var i = 0; i < strs.length; i++) {
  742. obj[strs[i].split('=')[0]] = strs[i].split('=')[1];
  743. }
  744. }
  745. return obj;
  746. }
  747. function Back() {
  748. ExexuteKeyDown(4);
  749. window.event.returnValue = false;
  750. return false;
  751. }
  752. function array_unique(arr) {
  753. return arr.filter(function (e, i) {
  754. return arr.indexOf(e) === i;
  755. });
  756. }
  757. var cutList = [];
  758. let timer,
  759. isFlag = true;
  760. function showShearPlate() {
  761. if (!isControl) {
  762. return;
  763. }
  764. stopManyClick(() => {
  765. new Promise((resolve, reject) => {
  766. if (window.navigator.clipboard) {
  767. window.navigator.clipboard
  768. .readText()
  769. .then(
  770. function (content) {
  771. return $.ajax({
  772. url: baseUrl + '/api/public/v5/shear/content',
  773. type: 'post',
  774. dataType: 'json',
  775. data: JSON.stringify({
  776. content: content,
  777. }),
  778. headers: {
  779. 'content-Type': 'application/json',
  780. Authorization: token,
  781. },
  782. });
  783. },
  784. function (err) {
  785. $.toast('读取剪贴板失败', 'text');
  786. },
  787. )
  788. .finally(resolve);
  789. } else {
  790. resolve();
  791. }
  792. }).then(function () {
  793. $('.box-shear-plate').empty();
  794. $.ajax({
  795. url: baseUrl + '/api/public/v5/shear/content',
  796. headers: {
  797. Authorization: token,
  798. },
  799. type: 'get',
  800. dataType: 'json',
  801. success: function (res) {
  802. if (res.status === 0) {
  803. if (res.data.length) {
  804. cutList = array_unique(res.data);
  805. var str =
  806. '<div class="title">剪贴板<div onclick="handleClear()" class="btn-clear">清空</div></div><div class="slide-wrapper-content">';
  807. cutList.forEach(function (item) {
  808. str +=
  809. "<div class='slide-wrapper'><div class='slide-scroll animate-slide-start'><div class='slide-content'><div onclick='handleCopy(\"" +
  810. item.content +
  811. '")\'>' +
  812. item.content +
  813. "</div></div><div class='slide-content-button'><button onclick='handleDelete(" +
  814. item.id +
  815. ")'>删除</button></div></div></div>";
  816. });
  817. str += '</div>';
  818. $('.box-shear-plate').append(str);
  819. } else {
  820. $('.box-shear-plate').append(
  821. '<img class="empty" src="img/jianqieban_pic@2x.png" alt="" /><div class="empty-txt">剪贴板为空</div>',
  822. );
  823. }
  824. $('.mask').show();
  825. initSlider();
  826. } else {
  827. $('.box-shear-plate').append(
  828. '<img class="empty" src="img/jianqieban_pic@2x.png" alt="" /><div class="empty-txt">剪贴板为空</div>',
  829. );
  830. $('.mask').show();
  831. }
  832. },
  833. });
  834. });
  835. });
  836. }
  837. //防止提示一秒内重复显示
  838. function stopManyClick(fn) {
  839. if (isFlag) {
  840. fn();
  841. }
  842. isFlag = false;
  843. if (timer) {
  844. clearTimeout(timer);
  845. }
  846. timer = setTimeout(() => {
  847. isFlag = true;
  848. }, 1500);
  849. }
  850. // 清空剪贴板
  851. function handleClear() {
  852. var ids = '';
  853. cutList.forEach(function (item) {
  854. ids += 'ids=' + item.id + '&';
  855. });
  856. ids = ids.substring(0, ids.lastIndexOf('&'));
  857. $.confirm('确定清空剪贴板?', function () {
  858. $.ajax({
  859. url: baseUrl + '/api/public/v5/shear/content?' + ids,
  860. headers: {
  861. Authorization: token,
  862. },
  863. type: 'DELETE',
  864. dataType: 'json',
  865. success: function (res) {
  866. if (res.status === 0) {
  867. showShearPlate();
  868. } else {
  869. $.toast(res.msg, 'text');
  870. }
  871. },
  872. });
  873. });
  874. }
  875. function handleCopy(content) {
  876. var cutting = {
  877. type: 'cutting',
  878. data: {
  879. str: content,
  880. },
  881. };
  882. wsss.send(JSON.stringify(cutting));
  883. }
  884. // 删除剪贴板
  885. function handleDelete(id) {
  886. $.ajax({
  887. url: baseUrl + '/api/public/v5/shear/content?ids=' + id,
  888. headers: {
  889. Authorization: token,
  890. },
  891. type: 'DELETE',
  892. dataType: 'json',
  893. success: function (res) {
  894. if (res.status === 0) {
  895. showShearPlate();
  896. } else {
  897. $.toast(res.msg, 'text');
  898. }
  899. },
  900. });
  901. }
  902. function initSlider() {
  903. //手指滑动多少距离就认为是滑成功
  904. //这个值不能太大,否则影响斜着滑动时,垂直滑动的流畅性,也不能太小,太灵敏也不好
  905. var diffXDistance = 50;
  906. //当前滑动的对象
  907. var currentObject;
  908. //上一次滑动的对象
  909. var lastObject;
  910. //是否可以左右滑动,在上下滑的时候禁止左右滑
  911. var canSlide = true;
  912. //用于记录按下的点
  913. var startPoint;
  914. $('.slide-content').css({
  915. width: $('.slide-wrapper').width(),
  916. });
  917. document.body.removeEventListener(
  918. 'touchmove',
  919. function (e) {
  920. e.preventDefault();
  921. },
  922. {
  923. passive: false,
  924. },
  925. );
  926. $('.slide-scroll')
  927. .css({
  928. width:
  929. $('.slide-wrapper').width() + $('.slide-content-button').width(),
  930. })
  931. .on('touchstart', function (e) {
  932. currentObject = this;
  933. startPoint = {
  934. x: e.originalEvent.changedTouches[0].pageX,
  935. y: e.originalEvent.changedTouches[0].pageY,
  936. };
  937. })
  938. .on('touchmove', function (e) {
  939. //如果是左右滑动,就禁止上下的滑动
  940. //如果是上下的滑动,就禁止左右滑动
  941. if (
  942. Math.abs(e.originalEvent.changedTouches[0].pageX - startPoint.x) >
  943. Math.abs(e.originalEvent.changedTouches[0].pageY - startPoint.y)
  944. ) {
  945. event.preventDefault();
  946. } else {
  947. canSlide = false;
  948. }
  949. })
  950. .on('touchend', function (e) {
  951. //如果是上下滑动,这里就直接返回了
  952. if (!canSlide) {
  953. canSlide = true;
  954. return true;
  955. }
  956. //点击除当前左滑对象之外的任意其他位置
  957. if (lastObject && currentObject != lastObject) {
  958. //右滑→
  959. $(lastObject).removeClass('animate-slide');
  960. //清空上一个左滑的对象
  961. lastObject = undefined;
  962. }
  963. var diffX = e.originalEvent.changedTouches[0].pageX - startPoint.x;
  964. if (diffX < -diffXDistance) {
  965. //左滑←
  966. $(currentObject).addClass('animate-slide');
  967. if (lastObject && lastObject != currentObject) {
  968. //右滑→
  969. $(lastObject).removeClass('animate-slide');
  970. }
  971. //记录上一个左滑的对象
  972. lastObject = currentObject;
  973. } else if (diffX >= diffXDistance) {
  974. if (currentObject == lastObject) {
  975. //右滑→
  976. $(currentObject).removeClass('animate-slide');
  977. //清空上一个左滑的对象
  978. lastObject = undefined;
  979. }
  980. }
  981. });
  982. }
  983. var btnMuted = document.querySelector('#btnMuted');
  984. btnMuted &&
  985. (function () {
  986. var setHistory = function (left, top) {
  987. try {
  988. localStorage.setItem(
  989. 'muted-btn-loc',
  990. JSON.stringify({
  991. left: left,
  992. top: top,
  993. }),
  994. );
  995. } catch (ex) {}
  996. };
  997. var getHistory = function () {
  998. try {
  999. var value = localStorage.getItem('muted-btn-loc');
  1000. if (!value) return null;
  1001. value = JSON.parse(value);
  1002. if (!value) return null;
  1003. return value;
  1004. } catch (ex) {
  1005. return null;
  1006. }
  1007. };
  1008. var fixLoc = function (loc) {
  1009. var rect = btnMuted.getBoundingClientRect();
  1010. rect = {
  1011. top: rect.top,
  1012. left: rect.left,
  1013. width: rect.width,
  1014. height: rect.height,
  1015. }; //部分低版本浏览器,该属性为只读
  1016. if (loc) {
  1017. rect.left = loc.left;
  1018. rect.top = loc.top;
  1019. }
  1020. var minX = 0;
  1021. var minY = 0;
  1022. var docRect = document.documentElement.getBoundingClientRect();
  1023. var maxY = docRect.height - rect.height;
  1024. var maxX = docRect.width - rect.width;
  1025. var left = rect.left;
  1026. var top = rect.top;
  1027. left = Math.min(left, maxX);
  1028. left = Math.max(left, minX);
  1029. top = Math.min(top, maxY);
  1030. top = Math.max(top, minY);
  1031. if (loc || top !== rect.top || left !== rect.left) {
  1032. btnMuted.style.cssText +=
  1033. 'left:' + left + 'px;top:' + top + 'px;';
  1034. }
  1035. };
  1036. window.addEventListener('resize', function () {
  1037. fixLoc();
  1038. });
  1039. var touchPoint = {
  1040. pageY: 0,
  1041. pageX: 0,
  1042. };
  1043. var currentLoc = {
  1044. top: 0,
  1045. left: 0,
  1046. curTop: 0,
  1047. curLeft: 0,
  1048. };
  1049. var toMove = false;
  1050. var touchmove = function (e) {
  1051. e.preventDefault();
  1052. var point = e.changedTouches[0];
  1053. var top = -touchPoint.pageY + point.pageY;
  1054. var left = -touchPoint.pageX + point.pageX;
  1055. if (toMove) {
  1056. top += currentLoc.top;
  1057. left += currentLoc.left;
  1058. currentLoc.curLeft = left;
  1059. currentLoc.curTop = top;
  1060. btnMuted.style.cssText +=
  1061. 'left:' + left + 'px;top:' + top + 'px;';
  1062. } else {
  1063. if (Math.abs(top) >= 5 || Math.abs(left) >= 5) {
  1064. toMove = true;
  1065. }
  1066. }
  1067. };
  1068. var touchend = function () {
  1069. window.removeEventListener('touchmove', touchmove, {
  1070. passive: false,
  1071. });
  1072. window.removeEventListener('touchend', touchend, {
  1073. passive: false,
  1074. });
  1075. if (toMove) {
  1076. setHistory(currentLoc.curLeft, currentLoc.curTop);
  1077. fixLoc();
  1078. } else {
  1079. //按点击处理
  1080. var set = $('.control-right-img').attr('data-id');
  1081. if (set == '1') {
  1082. $('.control-right-img').attr({
  1083. 'data-id': '2',
  1084. });
  1085. $('.leftmains').css({
  1086. right: '0rem',
  1087. });
  1088. } else {
  1089. $('.control-right-img').attr({
  1090. 'data-id': '1',
  1091. });
  1092. $('.leftmains').css({
  1093. right: '-4rem',
  1094. });
  1095. }
  1096. }
  1097. };
  1098. btnMuted.addEventListener(
  1099. 'touchstart',
  1100. function (e) {
  1101. e.preventDefault();
  1102. toMove = false;
  1103. var point = e.changedTouches[0];
  1104. touchPoint.pageX = point.pageX;
  1105. touchPoint.pageY = point.pageY;
  1106. var rect = e.target.getBoundingClientRect();
  1107. currentLoc.top = rect.top;
  1108. currentLoc.left = rect.left;
  1109. window.addEventListener('touchmove', touchmove, {
  1110. passive: false,
  1111. });
  1112. window.addEventListener('touchend', touchend, {
  1113. passive: false,
  1114. });
  1115. },
  1116. {
  1117. passive: false,
  1118. },
  1119. );
  1120. var history = getHistory();
  1121. if (history) {
  1122. fixLoc(history);
  1123. }
  1124. btnMuted.classList.remove('hide');
  1125. })();
  1126. $('#upload').on('click', function () {
  1127. clearInterval(intervaler);
  1128. quit();
  1129. ws.close();
  1130. wsss.close();
  1131. });
  1132. function selectText(x) {
  1133. if (document.selection) {
  1134. var range = document.body.createTextRange();
  1135. range.moveToElementText(x);
  1136. range.select();
  1137. } else if (window.getSelection) {
  1138. var selection = window.getSelection();
  1139. var range = document.createRange();
  1140. selection.removeAllRanges();
  1141. range.selectNodeContents(x);
  1142. selection.addRange(range);
  1143. }
  1144. }
  1145. // 激活码广告相关配置
  1146. function getConfigByPhoneType() {
  1147. return new Promise((resolve, reject) => {
  1148. $.ajax({
  1149. url: baseUrl + '/api/pay/v5/trialCodeConfig/getConfigByPhoneType',
  1150. headers: {
  1151. Authorization: token,
  1152. },
  1153. data: {
  1154. userCardId: userCardId,
  1155. phoneType: mealType,
  1156. },
  1157. type: 'get',
  1158. dataType: 'json',
  1159. success: function (res) {
  1160. let obj = res.data;
  1161. if (res.status === 0) {
  1162. resolve(obj);
  1163. } else {
  1164. $.toast(res.msg, 'text');
  1165. }
  1166. },
  1167. });
  1168. });
  1169. }
  1170. //列表
  1171. function getSetmealList() {
  1172. return new Promise((resolve, reject) => {
  1173. $.ajax({
  1174. url: baseUrl + '/api/resources/v4/freetrial/setmeal/list',
  1175. headers: {
  1176. Authorization: token,
  1177. },
  1178. type: 'get',
  1179. dataType: 'json',
  1180. success: function (res) {
  1181. if (res.status === 0) {
  1182. let list = res.data;
  1183. list.map((item) => {
  1184. if (item.phoneType === parameters['mealType']) {
  1185. resolve(item);
  1186. }
  1187. });
  1188. } else {
  1189. $.toast(res.msg, 'text');
  1190. }
  1191. },
  1192. });
  1193. });
  1194. }
  1195. //广告信息
  1196. var adData = null; // 广告数据
  1197. var adLastTime = 0; // 广告时间
  1198. var intervalTime = 0; // 间隔时间
  1199. // let adType = 0;
  1200. console.log(
  1201. '🚀 ~ file: WXtrialInterface.html ~ line 973 ~ sourceType',
  1202. sourceType,
  1203. );
  1204. // 拉取广告数据
  1205. function getAD() {
  1206. return $.ajax({
  1207. url: baseUrl + '/api/public/v5/advertising/getAdInfoByAdPlace',
  1208. headers: {
  1209. Authorization: token,
  1210. },
  1211. data: JSON.stringify({
  1212. adPlace: adType,
  1213. os: 0,
  1214. }),
  1215. type: 'POST',
  1216. dataType: 'json',
  1217. contentType: 'application/json;charset=UTF-8',
  1218. }).then(function (res) {
  1219. if (res.status === 0) {
  1220. var list = res.data.filter(
  1221. (v) => v.adType === 1 && !!v.adVideoBase.videoUrl,
  1222. );
  1223. adData = list[Math.floor(Math.random() * list.length)];
  1224. console.log(
  1225. '🚀 ~ file: WXtrialInterface.html ~ line 990 ~ getAD ~ adData',
  1226. adData,
  1227. );
  1228. return adData;
  1229. } else {
  1230. return Promise.reject(new Error(res.msg));
  1231. }
  1232. });
  1233. }
  1234. // 播放广告
  1235. function playAD() {
  1236. var nowTime = Date.now();
  1237. if (
  1238. adData &&
  1239. // [1, 2].includes(sourceType) &&
  1240. $('.try-use-wrap').eq(0).is(':hidden') &&
  1241. nowTime > adLastTime + intervalTime
  1242. ) {
  1243. $('#source').attr('src', adData.adVideoBase.videoUrl);
  1244. $('.try-use-wrap').eq(0).show();
  1245. $('#source')[0].play();
  1246. videoTime = adData.forcedTime;
  1247. adData = null;
  1248. adLastTime = nowTime;
  1249. videoTimer = setInterval(() => {
  1250. if (videoTime > 0) {
  1251. videoTime--;
  1252. $('.time-node')
  1253. .eq(0)
  1254. .text(videoTime + 's');
  1255. } else {
  1256. clearInterval(videoTimer);
  1257. $('.time-node').eq(0).text('');
  1258. }
  1259. }, 1000);
  1260. if (intervalTime > 0) {
  1261. // 间隔广告拉取下一次广告数据
  1262. adType = 16;
  1263. getAD();
  1264. }
  1265. if (adType === 16 && sourceType == 1) {
  1266. // 间隔广告和试用才上报
  1267. report(0);
  1268. }
  1269. }
  1270. }
  1271. /**
  1272. * 初始化广告
  1273. * 因移动端video无法自动播放,play()方法不能异步调用。
  1274. * 解决方案,初始化时预先请求广告数据,在用户对云手机touchmove事件中去播放广告并请求下一次广告数据。
  1275. */
  1276. function initAD() {
  1277. console.log(
  1278. '🚀 ~ file: WXtrialInterface.html ~ line 1052 ~ initAD ~ sourceType',
  1279. sourceType,
  1280. );
  1281. (function () {
  1282. switch (sourceType) {
  1283. case 1: {
  1284. return getSetmealList().then(function (res) {
  1285. intervalTime =
  1286. res.intervalSwitch === 1
  1287. ? res.intervalAdvertDuration * 1000 * 60
  1288. : 0;
  1289. if (res.pushFlowAdvert === 1) {
  1290. adType = 15;
  1291. adTime = 0;
  1292. } else if (intervalTime > 0) {
  1293. adType = 16;
  1294. adTime = date.now();
  1295. }
  1296. });
  1297. }
  1298. case 2: {
  1299. return getConfigByPhoneType().then(function (res) {
  1300. if (res.isDisconnectionTime === 1) {
  1301. var time = res.disconnectionTime * 60 * 1000;
  1302. setTimeout(() => {
  1303. disconnectionFlag = true;
  1304. $('.buy-phone-wrap').eq(0).show();
  1305. }, time);
  1306. }
  1307. intervalTime =
  1308. res.isIntervalPlayAd === 1
  1309. ? res.intervalPlayAdTime * 1000 * 60
  1310. : 0;
  1311. if (res.isShowAd === 1) {
  1312. adType = 15;
  1313. adTime = 0;
  1314. } else if (intervalTime > 0) {
  1315. adType = 16;
  1316. adTime = date.now();
  1317. }
  1318. });
  1319. }
  1320. default: {
  1321. return Promise.reject();
  1322. }
  1323. }
  1324. })().then(function () {
  1325. console.log(adType);
  1326. this.$('#wine').on('touchstart', playAD);
  1327. getAD();
  1328. });
  1329. }
  1330. //广告信息
  1331. // function adInit() {
  1332. // sourceType = parameters['sourceType'];
  1333. // if (sourceType == 1) {
  1334. // getSetmealList().then((res) => {
  1335. // if (res.pushFlowAdvert === 1) {
  1336. // getAdList(15);
  1337. // }
  1338. // if (res.intervalSwitch === 1) {
  1339. // let time = res.intervalAdvertDuration * 60 * 1000;
  1340. // setInterval(() => {
  1341. // $('.try-use-wrap').eq(0).hide();
  1342. // getAdList(16);
  1343. // }, time);
  1344. // }
  1345. // })
  1346. // } else if (sourceType == 2) {
  1347. // getConfigByPhoneType().then((res) => {
  1348. // if (res.isDisconnectionTime === 1) {
  1349. // let time = res.disconnectionTime * 60 * 1000;
  1350. // setTimeout(() => {
  1351. // disconnectionFlag = true;
  1352. // $('.buy-phone-wrap').eq(0).show();
  1353. // }, time);
  1354. // }
  1355. // if (res.isShowAd === 1) {
  1356. // getAdList(15);
  1357. // }
  1358. // if (res.isIntervalPlayAd === 1) {
  1359. // let time = res.intervalPlayAdTime * 60 * 1000;
  1360. // setInterval(() => {
  1361. // $('.try-use-wrap').eq(0).hide();
  1362. // getAdList(16);
  1363. // }, time);
  1364. // }
  1365. // })
  1366. // }
  1367. // }
  1368. // 广告接口
  1369. // function getAdList(type) {
  1370. // adType = type;
  1371. // $.ajax({
  1372. // url: baseUrl + '/api/public/v5/advertising/getAdInfoByAdPlace',
  1373. // headers: {
  1374. // Authorization: form.token,
  1375. // },
  1376. // data: JSON.stringify({
  1377. // adPlace: type,
  1378. // os: 0,
  1379. // }),
  1380. // type: 'POST',
  1381. // dataType: 'json',
  1382. // contentType: 'application/json;charset=UTF-8',
  1383. // success: function (res) {
  1384. // if (res.status === 0) {
  1385. // let list = res.data;
  1386. // let indexs = Math.floor(Math.random() * list.length);
  1387. // videoTime = list[indexs].forcedTime;
  1388. // // $('#source').src = list[0].adVideoBase.videoUrl;
  1389. // $('#source').attr('src', list[indexs].adVideoBase.videoUrl); //更新url
  1390. // $('#source').attr('autoplay', 'true'); //直接播放
  1391. // videoTimer = setInterval(() => {
  1392. // if (videoTime > 0) {
  1393. // videoTime--;
  1394. // $('.time-node')
  1395. // .eq(0)
  1396. // .text(videoTime + 's');
  1397. // } else {
  1398. // clearInterval(videoTimer);
  1399. // $('.time-node').eq(0).text('');
  1400. // }
  1401. // }, 1000);
  1402. // if (adType === 16 && sourceType == 1) {
  1403. // // 间隔广告和试用才上报
  1404. // report(0);
  1405. // }
  1406. // $('.try-use-wrap').eq(0).show();
  1407. // } else {
  1408. // $.toast(res.msg, 'text');
  1409. // }
  1410. // },
  1411. // });
  1412. // }
  1413. //间隔广告上报
  1414. function report(type) {
  1415. $.ajax({
  1416. url: baseUrl + '/api/resources/v1/trial/report',
  1417. headers: {
  1418. Authorization: token,
  1419. },
  1420. data: JSON.stringify({
  1421. userCardId: userCardId,
  1422. reportType: type,
  1423. }),
  1424. type: 'POST',
  1425. dataType: 'json',
  1426. contentType: 'application/json;charset=UTF-8',
  1427. success: function (res) {},
  1428. });
  1429. }
  1430. // 观看广告次数上报
  1431. function reportFrequency() {
  1432. $.ajax({
  1433. url:
  1434. baseUrl +
  1435. '/api/resoures/v1/trial/reportFrequency/' +
  1436. form.userCardId,
  1437. headers: {
  1438. Authorization: form.token,
  1439. },
  1440. type: 'post',
  1441. contentType: 'application/json',
  1442. dataType: 'json',
  1443. success: function (res) {},
  1444. });
  1445. }
  1446. //关闭广告
  1447. $('.time-close-wrap')[0].addEventListener('click', () => {
  1448. if (videoTime == 0) {
  1449. reportFrequency();
  1450. }
  1451. $('.buy-phone-wrap').eq(0).show();
  1452. });
  1453. // 点击取消
  1454. $('.cannel-btn')[0].addEventListener('click', () => {
  1455. $('.buy-phone-wrap').eq(0).hide();
  1456. if (disconnectionFlag || getDate) {
  1457. //设置了断线时间,取消直接退出
  1458. systemBuriedPoint('激活码-断线-取消');
  1459. quit();
  1460. return;
  1461. }
  1462. let pointName = '';
  1463. if (sourceType == 1) {
  1464. pointName =
  1465. videoTime == 0 ? '免费试用-关闭-取消' : '免费试用-强制关闭-取消';
  1466. } else {
  1467. pointName =
  1468. videoTime == 0 ? '激活码-关闭-取消' : '激活码-强制关闭-取消';
  1469. }
  1470. systemBuriedPoint(pointName);
  1471. if (videoTime == 0) {
  1472. if (adType === 16 && sourceType == 1) {
  1473. report(1);
  1474. }
  1475. $('.try-use-wrap').eq(0).hide();
  1476. $('#source')[0].pause();
  1477. return;
  1478. }
  1479. $('.look-wrap').eq(0).show();
  1480. });
  1481. // 点击去购买
  1482. $('.go-bug')[0].addEventListener('click', () => {
  1483. let pointName = '';
  1484. if (disconnectionFlag) {
  1485. pointName = '激活码-断线-去购买';
  1486. } else if (sourceType == 1) {
  1487. pointName =
  1488. videoTime == 0
  1489. ? '免费试用-关闭-去购买'
  1490. : '免费试用-强制关闭-去购买';
  1491. } else {
  1492. pointName =
  1493. videoTime == 0 ? '激活码-关闭-去购买' : '激活码-强制关闭-去购买';
  1494. }
  1495. systemBuriedPoint(pointName);
  1496. if (getDate) {
  1497. wx.miniProgram.navigateTo({
  1498. url: '/packageA/order/buy/index?buyType=试用界面购买',
  1499. });
  1500. } else {
  1501. // 过期续费按钮进入
  1502. wx.miniProgram.navigateTo({
  1503. url:
  1504. `/packageA/order/renew/index?buyType=${
  1505. sourceType == 1
  1506. ? '试用弹窗购买按钮进入-普通试用'
  1507. : '试用弹窗购买按钮进入-激活码试用'
  1508. }&record=` + userCardId,
  1509. });
  1510. }
  1511. });
  1512. // 放弃
  1513. $('.cannel-ad-btn')[0].addEventListener('click', () => {
  1514. if (sourceType == 1) {
  1515. systemBuriedPoint('免费试用-强制关闭-放弃');
  1516. } else {
  1517. systemBuriedPoint('激活码-强制关闭-放弃');
  1518. }
  1519. quit();
  1520. });
  1521. // 继续观看
  1522. $('.looking')[0].addEventListener('click', () => {
  1523. $('.look-wrap').eq(0).hide();
  1524. if (sourceType == 1) {
  1525. systemBuriedPoint('免费试用-强制关闭-继续观看');
  1526. } else {
  1527. systemBuriedPoint('激活码-强制关闭-继续观看');
  1528. }
  1529. });
  1530. // 埋点
  1531. function systemBuriedPoint(pointName) {
  1532. $.ajax({
  1533. url: baseUrl + '/api/public/v1/systemBuriedPoint/stat',
  1534. headers: {
  1535. Authorization: token,
  1536. },
  1537. type: 'post',
  1538. data: JSON.stringify({
  1539. pointName: pointName,
  1540. }),
  1541. contentType: 'application/json',
  1542. dataType: 'json',
  1543. success: function (res) {},
  1544. });
  1545. }
  1546. function quit() {
  1547. if (navigator.userAgent.toLowerCase().includes('toutiaomicroapp')) {
  1548. tt.miniProgram.switchTab({
  1549. url: '/pages/home/home',
  1550. });
  1551. } else if (window.__wxjs_environment === 'miniprogram') {
  1552. wx.miniProgram.switchTab({
  1553. url: '/pages/home/home',
  1554. });
  1555. } else {
  1556. uni.webView.navigateBack({
  1557. delta: 1,
  1558. });
  1559. }
  1560. }
  1561. window.onbeforeunload = function () {
  1562. ws.close();
  1563. wsss.close();
  1564. };
  1565. function updatePhoneSizeListHtml() {
  1566. const templatePhoneSizeItem = doT.template(
  1567. $('#template-phone-size-item').html().replace(/&amp;/g, '&'),
  1568. );
  1569. const phoneSizeListItemsHtml = templatePhoneSizeItem({
  1570. list: window.phoneSizeList,
  1571. active: window.activePhoneSize,
  1572. });
  1573. $('#phone-size-list').html(phoneSizeListItemsHtml);
  1574. }
  1575. $('#open-set-phone-size-dialog-btn').on('click', function (e) {
  1576. window.activePhoneSize = window.currentPhoneSize;
  1577. updatePhoneSizeListHtml();
  1578. $('#set-phone-size-dialog').addClass('show');
  1579. });
  1580. // $('#set-phone-size-dialog').addClass('show');
  1581. $('.dialog .dialog-mask')
  1582. .add('.dialog .dialog-btn.cancel')
  1583. .on('click', function (e) {
  1584. $(e.currentTarget).parents('.dialog').removeClass('show');
  1585. });
  1586. // 分辨率列表
  1587. window.phoneSizeList = [];
  1588. // 当前生效的分辨率
  1589. window.currentPhoneSize = {
  1590. width: 720,
  1591. height: 1280,
  1592. };
  1593. // 选中的分辨率
  1594. window.activePhoneSize = window.currentPhoneSize;
  1595. function getPhoneSizeList() {
  1596. return $.ajax({
  1597. url:
  1598. baseUrl + '/api/resources/v5/machine/resolution/getResolvingPower',
  1599. headers: {
  1600. Authorization: token,
  1601. },
  1602. type: 'get',
  1603. dataType: 'json',
  1604. data: {
  1605. userCardId,
  1606. },
  1607. }).then(function (response) {
  1608. return response.data.map(function (v) {
  1609. return {
  1610. id: v.id,
  1611. dpi: v.dpi,
  1612. width: v.width || v.abscissa,
  1613. height: v.height || v.ordinate || v.high,
  1614. };
  1615. });
  1616. });
  1617. }
  1618. getPhoneSizeList().then(function (phoneSizeList) {
  1619. window.phoneSizeList = phoneSizeList;
  1620. const currentPhoneSize = window.phoneSizeList.find(function (v) {
  1621. return (
  1622. v.width === window.currentPhoneSize.width &&
  1623. v.height === window.currentPhoneSize.height
  1624. );
  1625. });
  1626. window.currentPhoneSize = currentPhoneSize || window.currentPhoneSize;
  1627. return updatePhoneSizeListHtml();
  1628. });
  1629. // const phoneSizeListSwiper = new Swiper('#phone-size-list-swiper', {
  1630. // direction: 'vertical',
  1631. // slidesPerView: 'auto',
  1632. // loop: false,
  1633. // centeredSlides: true,
  1634. // });
  1635. function setPhoneSize(config) {
  1636. wsss.send(
  1637. JSON.stringify({
  1638. type: 'setPhoneSize',
  1639. data: {
  1640. id: config.id,
  1641. width: config.width,
  1642. height: config.height,
  1643. dpi: config.dpi,
  1644. },
  1645. }),
  1646. );
  1647. wsss.send(
  1648. JSON.stringify({
  1649. type: 'forwardMsg',
  1650. data: {
  1651. code: 'phoneSizeChange',
  1652. id: config.id,
  1653. width: config.width,
  1654. height: config.height,
  1655. dpi: config.dpi,
  1656. desc: '分辨率修改', // 可选
  1657. },
  1658. }),
  1659. );
  1660. $.ajax({
  1661. url:
  1662. baseUrl +
  1663. '/api/resources/v5/machine/resolution/operationResolvingPower',
  1664. headers: {
  1665. Authorization: token,
  1666. },
  1667. type: 'post',
  1668. dataType: 'json',
  1669. contentType: 'application/json; charset=UTF-8',
  1670. data: JSON.stringify({
  1671. userCardId: window.userCardId,
  1672. resolvingPowerId: config.id,
  1673. // width: config.width,
  1674. // height: config.height,
  1675. // dpi: config.dpi,
  1676. }),
  1677. });
  1678. window.currentPhoneSize = config;
  1679. }
  1680. // wsss.addEventListener('message', function (event) {
  1681. // console.log(
  1682. // '🚀 ~ file: WXtrialInterface.html ~ line 1476 ~ event',
  1683. // event,
  1684. // );
  1685. // });
  1686. $('#phone-size-list').on('click', '.phone-size-item', function (e) {
  1687. const data = $(e.currentTarget).data();
  1688. window.activePhoneSize = data;
  1689. updatePhoneSizeListHtml();
  1690. // setPhoneSize(data.width, data.height);
  1691. });
  1692. $('#set-phone-size-dialog .dialog-btn.confirm').on('click', function (e) {
  1693. setPhoneSize(window.activePhoneSize);
  1694. $('#set-phone-size-dialog').removeClass('show');
  1695. });
  1696. </script>
  1697. <script type="text/javascript" src="WXdraw.js"></script>
  1698. <script type="text/javascript" src="aac.js"></script>
  1699. </body>
  1700. </html>