WXtrialInterface.html 59 KB

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