WXtrialInterface.html 58 KB

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