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