WXtrialInterface.html 57 KB

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