jquery.unicom.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716
  1. // import * as compnt from "./compnt.js";
  2. var unicom = window.unicom = {
  3. query: {},
  4. product: {},
  5. fesname: {},
  6. user: {},
  7. root: null,
  8. init: function () {
  9. root = this.getRootPath();
  10. this.parseQueryParms();
  11. $("#useraccount_tt").attr("value", getUrlParam("freeflow_token"));
  12. var param = {
  13. "fes": this.query.fes,
  14. "sou": this.query.sou
  15. }
  16. var that = this;
  17. //return new Promise(function (resolve, reject) {
  18. var def = $.Deferred();
  19. $.post(this.root + "-s1api" + "/ini/getstyle", JSON.stringify(param)).then(function (responseText) {
  20. var response = JSON.parse(responseText);
  21. if (response.resultCode != "0000") {
  22. //window.location.href = "/404.html";
  23. def.reject();
  24. return;
  25. }
  26. that.product = response.product[0];
  27. $("#fog_" + that.product.url).attr("value", that.product.fog);
  28. var smslist = that.product.icon.split(",");
  29. for (var i = 0; i < smslist.length; i++) {
  30. if (i == 0) {
  31. $("#sendsms_order_" + that.product.url).attr("value", smslist[i]);
  32. }
  33. if (i == 1) {
  34. $("#sendsms_cancel_" + that.product.url).attr("value", smslist[i]);
  35. }
  36. if (i == 2) {
  37. $("#sendsms_yuyue_" + that.product.url).attr("value", smslist[i]);
  38. }
  39. }
  40. def.resolve(response);
  41. })
  42. return def;
  43. //})
  44. },
  45. /**
  46. * 抖音产品订购
  47. */
  48. orderDouyin: function (token, usermob) {
  49. var param = {
  50. "fog": getMemoValbyId(this.product.url, "fog"),
  51. "usermob": usermob,
  52. "useraccount": getMemoValbyId(this.product.url, "useraccount"),
  53. "fes": this.getUrlParam("fes"),
  54. "sou": this.getUrlParam("sou"),
  55. "token": token
  56. }
  57. return $.post(this.root + "-s1api" + '/com/buyc', JSON.stringify(param));
  58. },
  59. /**
  60. * 获取项目根目录
  61. * @returns
  62. */
  63. getRootPath: function () {
  64. //获取当前网址,如: http://localhost:8080/ems/Pages/Basic/Person.jsp
  65. var curWwwPath = window.document.location.href;
  66. //获取主机地址之后的目录,如: /ems/Pages/Basic/Person.jsp
  67. var pathName = window.document.location.pathname;
  68. var pos = curWwwPath.indexOf(pathName);
  69. //获取主机地址,如: http://localhost:8080
  70. var localhostPath = curWwwPath.substring(0, pos);
  71. //获取带"/"的项目名,如:/ems
  72. var projectName = pathName.substring(0, pathName.substr(1).indexOf('/') + 1);
  73. this.root = (localhostPath + projectName);
  74. return (localhostPath + projectName);
  75. },
  76. parseQueryParms: function () {
  77. var QUERY_SEPARATOR = '&', VALUE_SEPARATOR = '=';
  78. var queryStr = window.location.search.substring(1);
  79. var startIndex = 0, vIndex, qIndex;
  80. while (queryStr.length > 0) {
  81. vIndex = queryStr.indexOf(VALUE_SEPARATOR, startIndex);
  82. if (vIndex == -1) {
  83. break;
  84. }
  85. qIndex = queryStr.indexOf(QUERY_SEPARATOR, vIndex + 1);
  86. if (qIndex == -1) {
  87. qIndex = queryStr.length;
  88. }
  89. var key = queryStr.substring(startIndex, vIndex);
  90. var value = queryStr.substring(vIndex + 1, qIndex);
  91. this.query[key] = decodeURIComponent(value);
  92. startIndex = qIndex + 1;
  93. }
  94. },
  95. /**
  96. * 获取当前url中参数信息
  97. * @param urlprm url中参数名称
  98. * @returns
  99. */
  100. getUrlParam: function (urlprm) {
  101. var reg = new RegExp("(^|&)" + urlprm + "=([^&]*)(&|$)");
  102. var r = window.location.search.substr(1).match(reg);
  103. if (r != null) {
  104. return r[2];
  105. } else {
  106. switch (urlprm) {
  107. case "con":
  108. return "1";
  109. case "freeflow_token":
  110. return "";
  111. default:
  112. var url = this.getRootPath() + "/404.html";
  113. $(location).attr('href', url);
  114. }
  115. }
  116. },
  117. burypointLogId: function (operid, remark, url) {
  118. var uuid = this.getCookie('uuid');
  119. if (uuid == null || uuid.trim() == '') {
  120. uuid = this.guid();
  121. this.setCookie('uuid', uuid, 1000 * 60 * 60 * 24);
  122. }
  123. var param = {
  124. operid: operid,
  125. uuid: uuid,
  126. fog: this.product.fog,
  127. userid: this.user.userid,
  128. fes: this.query.fes,
  129. sou: this.query.sou,
  130. url: encodeURIComponent(url || window.location.href),
  131. remark: encodeURIComponent(remark || '')
  132. }
  133. $.post(this.root + "-s1api" + "/burypoint/logid", JSON.stringify(param)).then(function() {})
  134. },
  135. /**
  136. * SliderCaptcha
  137. */
  138. verifyCaptcha: function (arr) {
  139. var that = this;
  140. $.post(this.root + "-s1api" + "/sliderCaptcha/verify", JSON.stringify(arr)).then(function (responseText) {
  141. var response = JSON.parse(responseText);
  142. if (response.resultCode == "0000") {
  143. that.product.captchaCode = response.captchaCode;
  144. return true;
  145. } else {
  146. compnt.showAlert(response.errorInfo);
  147. return false;
  148. }
  149. })
  150. },
  151. loadUserInfo: function (duration) {
  152. if (this.query.userid) {
  153. this.user.userid = this.query.userid;
  154. this.user.usermob = this.query.usermob;
  155. return;
  156. }
  157. try {
  158. var time = localStorage.getItem('time');
  159. if (time) {
  160. var curr = new Date().getTime();
  161. if (curr <= parseFloat(time) + duration || (1000 * 60 * 60)) {
  162. var userString = localStorage.getItem("user");
  163. var _user = JSON.parse(userString);
  164. this.user.userid = _user.userid;
  165. this.user.usermob = _user.usermob;
  166. if (_user.usermob == "18674842761") {
  167. setTimeout(function(){
  168. alert(time + duration || (1000 * 60 * 60))
  169. }, 100);
  170. }
  171. } else {
  172. localStorage.removeItem("time")
  173. localStorage.removeItem("user")
  174. }
  175. }
  176. } catch (e) {
  177. }
  178. },
  179. saveUserInfo: function (duration) {
  180. localStorage.setItem('user', JSON.stringify(this.user));
  181. localStorage.setItem('time', duration || ((new Date().getTime()) + ""));
  182. },
  183. generClientSecret: function (fog) {
  184. // console.log(product)
  185. var param = {
  186. "fog": this.product.fog || fog || "",
  187. "channel": ""
  188. }
  189. return $.post(this.root + "-s1api" + "/ini/gensign", JSON.stringify(param));
  190. },
  191. /**
  192. * 查询微信支付结果
  193. */
  194. queryWxPay: function (tradeno, tradedate, userid) {
  195. var param = {
  196. "fes": this.query.fes,
  197. "sou": this.query.sou,
  198. "fog": this.product.fog,
  199. "tradeno": tradeno,
  200. "userid": userid || this.user.userid,
  201. "tradedate": tradedate, //例子:20190115
  202. }
  203. var def = $.Deferred();
  204. if (isEmpty(param.userid)) {
  205. /*return new Promise((resolve, reject) => {
  206. reject("参数错误");
  207. });*/
  208. def.reject('参数错误')
  209. return def;
  210. }
  211. if (isEmpty(param.tradeno)) {
  212. /*return new Promise((resolve, reject) => {
  213. reject("参数错误");
  214. });*/
  215. def.reject('参数错误')
  216. return def;
  217. }
  218. return $.post(this.root + "-s1api" + '/backward/stackpkgquerypay', JSON.stringify(param));
  219. },
  220. /**
  221. * 订购
  222. */
  223. order: function (userid, token, usermob) {
  224. var param = {
  225. "fes": this.query.fes,
  226. "sou": this.query.sou,
  227. "fog": this.product.fog,
  228. "token": token,
  229. "userid": userid || this.user.userid,
  230. "usermob": usermob || this.user.usermob,
  231. "useraccount": ""
  232. }
  233. if (this.query.F) {
  234. param.f = this.query.F
  235. }
  236. // console.log("订购参数:" + param)
  237. return $.post(this.root + "-s1api" + '/comm/order', JSON.stringify(param));
  238. },
  239. /**
  240. * 退订
  241. */
  242. cancel: function (userid, usermob) {
  243. var param = {
  244. "fes": this.query.fes,
  245. "sou": this.query.sou,
  246. "fog": this.product.fog,
  247. "userid": userid || this.user.userid,
  248. "usermob": usermob || this.user.usermob,
  249. "useraccount": ""
  250. }
  251. return $.post(this.root + "-s1api" + '/comm/cancel', JSON.stringify(param));
  252. },
  253. /**
  254. * 查询流量消耗
  255. */
  256. queryFlow: function (userid, usermob) {
  257. var param = {
  258. "fes": this.query.fes,
  259. "sou": this.query.sou,
  260. "fog": this.product.fog,
  261. "userid": userid || this.user.userid,
  262. "usermob": usermob || this.user.usermob,
  263. }
  264. return $.post(this.root + "-s1api" + '/flow/query', JSON.stringify(param));
  265. },
  266. /**
  267. * 查询订购关系
  268. */
  269. queryOrder: function (userid, usermob) {
  270. var param = {
  271. "fes": this.query.fes,
  272. "sou": this.query.sou,
  273. "fog": this.product.fog,
  274. "userid": userid || this.user.userid,
  275. "usermob": usermob || this.user.usermob
  276. }
  277. return $.post(this.root + "-s1api" + '/comm/queryorder', JSON.stringify(param));
  278. },
  279. queryStock: function (stockcode) {
  280. var param = {
  281. "fes": this.query.fes,
  282. "sou": this.query.sou,
  283. "fog": this.product.fog,
  284. "stockcode": stockcode
  285. }
  286. return $.post(this.root + "-s1api" + '/backward/queryStock', JSON.stringify(param));
  287. },
  288. /**
  289. * 后向产品订购
  290. */
  291. orderBack: function (stockcode) {
  292. var param = {
  293. "fes": this.query.fes,
  294. "sou": this.query.sou,
  295. "fog": this.product.fog,
  296. "userid": this.user.userid
  297. }
  298. if (!!stockcode && stockcode != '') {
  299. param.stockcode = stockcode;
  300. }
  301. return $.post(this.root + "-s1api" + '/backward/order', JSON.stringify(param));
  302. },
  303. /**
  304. * 后向产品退款
  305. */
  306. refund: function (stockcode, username, password) {
  307. var param = {
  308. "fes": this.query.fes,
  309. "sou": this.query.sou,
  310. "fog": this.product.fog,
  311. "stockcode": stockcode,
  312. "captchaCode": this.product.captchaCode,
  313. "username": username,
  314. "password": password
  315. }
  316. // console.log(param)
  317. return $.post(this.root + "-s1api" + '/backward/refund', JSON.stringify(param));
  318. },
  319. /**
  320. * 检查用户是否可以订购
  321. */
  322. can: function (uid) {
  323. if (!uid) {
  324. var def = $.Deferred();
  325. def.reject();
  326. //return new Promise(function (resolve, reject) {
  327. // reject()
  328. //})
  329. return def;
  330. }
  331. var param = {
  332. "fes": this.query.fes,
  333. "sou": this.query.sou,
  334. "fog": this.product.fog,
  335. "uid": uid || ""
  336. }
  337. return $.post(this.root + "-s1api" + '/member/can', JSON.stringify(param));
  338. },
  339. /*
  340. * 领取会员
  341. */
  342. drawMember: function (uid, screen_name, userid, usermob) {
  343. if (uid == null || uid.trim() == "") {
  344. compnt.showAlert('获取微博账号信息失败')
  345. return;
  346. }
  347. var param = {
  348. "fes": this.query.fes,
  349. "sou": this.query.sou,
  350. "fog": this.product.fog,
  351. "userid": userid || this.user.userid,
  352. "usermob": usermob || this.user.usermob,
  353. "uid": uid,
  354. "screen_name": screen_name || ""
  355. }
  356. return $.post(this.root + "-s1api" + '/member/draw', JSON.stringify(param));
  357. },
  358. /**
  359. * 查询会员领取状态
  360. */
  361. queryMember: function (userid, usermob, uid) {
  362. var param = {
  363. "fes": this.query.fes,
  364. "sou": this.query.sou,
  365. "fog": this.product.fog,
  366. "userid": userid || this.user.userid,
  367. "usermob": usermob || this.user.usermob,
  368. "uid": uid || ''
  369. }
  370. if (isEmpty(param.userid) && isEmpty(param.uid)) {
  371. /*return new Promise((resolve, reject) => {
  372. reject("参数错误");
  373. });*/
  374. var def = $.Deferred();
  375. def.reject('参数错误')
  376. return def;
  377. }
  378. // alert(JSON.stringify(param))
  379. return $.post(this.root + "-s1api" + '/member/query', JSON.stringify(param));
  380. },
  381. /**
  382. * 发送短信验证码
  383. * @param {}} $container
  384. */
  385. sendSms: function ($container, smstype) {
  386. if ($container.attr('n') != null && $container.attr('n') > 0) {
  387. return;
  388. }
  389. var usermob = $container.find('.usermob').val();
  390. if (usermob == null || usermob.trim() == "") {
  391. compnt.showAlert('手机号码不能为空~');
  392. return;
  393. }
  394. if (!usermob.startsWith("1") || usermob.length != 11) {
  395. compnt.showAlert('手机号码格式不正确~');
  396. return;
  397. }
  398. var param = {
  399. "fes": this.query.fes,
  400. "sou": this.query.sou,
  401. "fog": this.product.fog,
  402. "usermob": usermob,
  403. "smstype": smstype
  404. }
  405. this.user.usermob = usermob
  406. var count = 60;
  407. $container.attr('n', count);
  408. $.post(this.root + "-s1api" + '/sms/send', param).then(function (responseText) {
  409. var response = JSON.parse(responseText);
  410. if (response.resultCode != "0000") {
  411. count = 0;
  412. $container.attr('n', count);
  413. compnt.showAlert(response.errorInfo);
  414. return;
  415. }
  416. var $sendcode = $container.find('.sendcode')
  417. var template = '重新发送({}s)'
  418. $sendcode.text(template.replace('{}', count));
  419. $sendcode.addClass('sendcode-wait');
  420. var timer = setInterval(function () {
  421. count -= 1;
  422. $container.attr('n', count);
  423. $sendcode.text(template.replace('{}', count));
  424. if (count === 0) {
  425. clearInterval(timer);
  426. $sendcode.text('获取验证码');
  427. $container.attr('n', count);
  428. $sendcode.removeClass('sendcode-wait');
  429. }
  430. }, 1000);
  431. })
  432. },
  433. /**
  434. * 检验短信验证码,并且返回手机号伪代码,有效期10分钟
  435. * @param {*} usermob
  436. * @param {*} smscode
  437. */
  438. checkCode: function ($container) {
  439. var def = $.Deferred();
  440. //return new Promise(function (resolve, reject) {
  441. var usermob = $container.find('.usermob').val();
  442. var smscode = $container.find('.smscode').val();
  443. if (usermob == null || usermob.trim() == "") {
  444. compnt.showAlert('短信验证码不能为空~');
  445. def.reject()
  446. return;
  447. }
  448. if (smscode.length != 6) {
  449. compnt.showAlert('短信验证码不正确~');
  450. def.reject()
  451. return;
  452. }
  453. var param = {
  454. "fes": this.query.fes,
  455. "sou": this.query.sou,
  456. "fog": this.product.fog,
  457. "code": smscode,
  458. "usermob": usermob,
  459. }
  460. var that = this;
  461. $.post(this.root + "-s1api" + '/checkvercode', param).then(function (responseText) {
  462. var response = JSON.parse(responseText);
  463. switch (response.resultCode) {
  464. case "0000":
  465. that.user.userid = response.userid;
  466. that.user.usermob = usermob;
  467. that.user.usertime = new Date().getTime();
  468. def.resolve(response.userid);
  469. break;
  470. default:
  471. compnt.showAlert(response.errorInfo)
  472. def.reject(response);
  473. break;
  474. }
  475. }).fail(function (error) {
  476. def.reject('服务调用异常')
  477. })
  478. return def;
  479. //})
  480. },
  481. /**
  482. * 打开统一认证的页面
  483. */
  484. showCapPage: function (fog, productName) {
  485. //var $iframe = $('<iframe id="uniauthframe" src="http://127.0.0.1:8090/cap/CAP-AUTH.html"></iframe>');
  486. var capUrl = "http://800.wo.cn/cap/CAP-AUTH.html";
  487. var baseUrl = "http://800.wo.cn/";
  488. if (window.location.href.indexOf("https") >= 0) {
  489. capUrl = "https://800.wo.cn/cap/CAP-AUTH.html";
  490. baseUrl = "https://800.wo.cn/";
  491. }
  492. var $iframe = $('<iframe id="uniauthframe" src="' + capUrl + '"></iframe>');
  493. $iframe.css({
  494. width: "100%",
  495. height: "100%",
  496. position: "fixed",
  497. top: 0,
  498. left: 0,
  499. margin: 0,
  500. padding: 0,
  501. "-webkit-overflow-scrolling": "touch",
  502. border: "0px",
  503. })
  504. var that = this
  505. $iframe.on('load', function () {
  506. that.generClientSecret(fog).then(function (response) {
  507. // var response = JSON.parse(responseText);
  508. // console.log(response)
  509. response.orderChannel = that.query.fes + "_" + that.query.sou;
  510. if (productName != null && productName != '') {
  511. response.productName = productName;
  512. }
  513. $iframe[0].contentWindow.postMessage(JSON.stringify(response), baseUrl)
  514. })
  515. })
  516. if (navigator.userAgent.indexOf("MicroMessenger") >= 0) {
  517. //微信6.7.4及以后版本 ios12软键盘顶起页面后隐藏不回弹解决方案
  518. //打开嵌入的统一认证取号页面前,让原来的页面上下滚动。
  519. //统一认证的页面关闭以后,删除定时任务 clearInterval(window.capTimer)
  520. var currentPosition;
  521. var speed = 1; // 页面滚动距离
  522. window.capTimer = setInterval(function () {
  523. currentPosition = document.documentElement.scrollTop || document.body.scrollTop;
  524. currentPosition -= speed;
  525. window.top.scrollTo(0, currentPosition);//页面向上滚动
  526. currentPosition += speed; //speed变量
  527. window.top.scrollTo(0, currentPosition);//页面向下滚动
  528. }, 200);
  529. }
  530. $('body').append($iframe);
  531. //return new Promise(function (resolve, reject) {
  532. var def = $.Deferred();
  533. window.addEventListener('message', function (event) {
  534. var data = JSON.parse(event.data);
  535. switch (data.resultcode) {
  536. case "0": //处理成功
  537. $iframe.remove();
  538. $("body").css("overflow", "auto");
  539. clearInterval(window.capTimer)
  540. that.user.token = data.token;
  541. that.user.userid = decodeURIComponent(data.userid);
  542. that.user.userid1 = data.userid1;
  543. that.user.usermob = data.usermob;
  544. that.user.usertime = new Date().getTime();
  545. def.resolve(that.user);
  546. break;
  547. case "9001"://关闭H5认证页面
  548. $iframe.remove();
  549. clearInterval(window.capTimer)
  550. $("body").css("overflow", "auto");
  551. def.reject(data)
  552. break;
  553. case "0001"://auth_no无效
  554. case "0003"://client_id不存在
  555. case "0006"://验证码不正确
  556. case "4444"://服务暂时不可用(系统忙/系统队列满)
  557. break;
  558. default:
  559. $iframe.remove();
  560. $("body").css("overflow", "auto");
  561. clearInterval(window.capTimer)
  562. compnt.showAlert(data.errorinfo)
  563. def.reject(data)
  564. break;
  565. }
  566. })
  567. return def;
  568. //});
  569. },
  570. getCookie: function (name) {
  571. var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
  572. if (arr = document.cookie.match(reg))
  573. return unescape(arr[2]);
  574. else
  575. return null;
  576. },
  577. setCookie: function(name, value, millis) {
  578. millis = (millis == undefined ? 0 : millis);
  579. var exp = new Date();
  580. exp.setTime(exp.getTime() + millis);
  581. document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString();
  582. },
  583. guid: function () {
  584. return 'xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
  585. var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
  586. return v.toString(16);
  587. });
  588. },
  589. getNowFormatDate: function (sperator) {
  590. if (sperator == null) {
  591. sperator = ''
  592. }
  593. var date = new Date();
  594. var year = date.getFullYear();
  595. var month = date.getMonth() + 1;
  596. var strDate = date.getDate();
  597. if (month >= 1 && month <= 9) {
  598. month = "0" + month;
  599. }
  600. if (strDate >= 0 && strDate <= 9) {
  601. strDate = "0" + strDate;
  602. }
  603. var currentdate = year + sperator + month + sperator + strDate;
  604. return currentdate;
  605. },
  606. setProduct: function (_product) {
  607. this.product = _product;
  608. },
  609. setFesname: function (_fesname) {
  610. this.fesname = _fesname;
  611. },
  612. isEmpty: function (str) {
  613. if (str == null || str == '') {
  614. return true;
  615. }
  616. return false;
  617. },
  618. }