WXtrialInterface.html 56 KB

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