core.js 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. window.dx = {'user':{}};
  2. !(function () {
  3. var toString = String.prototype.toString;
  4. Array.isArray || (Array.isArray = function (obj) {
  5. return toString.call(obj) === '[object Array]';
  6. });
  7. })();
  8. (function (dx, window) {
  9. dx.query = {};
  10. var QUERY_SEPARATOR = '&', VALUE_SEPARATOR = '=';
  11. var queryStr = window.location.search.substring(1);
  12. var startIndex = 0, vIndex, qIndex;
  13. while (queryStr.length > 0) {
  14. vIndex = queryStr.indexOf(VALUE_SEPARATOR, startIndex);
  15. if (vIndex == -1) {
  16. break;
  17. }
  18. qIndex = queryStr.indexOf(QUERY_SEPARATOR, vIndex + 1);
  19. if (qIndex == -1) {
  20. qIndex = queryStr.length;
  21. }
  22. var key = queryStr.substring(startIndex, vIndex);
  23. var value = queryStr.substring(vIndex + 1, qIndex);
  24. dx.query[key] = decodeURIComponent(value);
  25. startIndex = qIndex + 1;
  26. }
  27. })(dx, window);
  28. !(function (dx, window) {
  29. dx.utils = {
  30. /**
  31. * 消息发送获取Josn数据
  32. * @param method 方法名称
  33. * @param data 发送数据
  34. * @returns 返回的json数据
  35. * 此方法需加载页面头信息与页面显示图标:
  36. * 页面必须有 title 标签
  37. * id = "icon" 链接地址
  38. * <link id="icon" rel="shortcut icon" type="image/x-icon" href=""/>
  39. * 加载页面基本信息:
  40. * XX 为活动对应产品表中配置标示
  41. * <input type="hidden" id="fog_XX"/>
  42. */
  43. postini: function () {
  44. $.ajax({
  45. url: getRootPath() + "-s1api" + '/ini/getstyle',
  46. type: "POST", // 用POST方式传输
  47. contentType: "application/json; charset=utf-8",
  48. dataType: "Json",
  49. data: JSON.stringify(postiniDate()),
  50. success:
  51. function (msg) {
  52. var resCode = msg["resultCode"];
  53. if (resCode == "0000") {
  54. var festival = msg["festival"];
  55. theme(festival["title"], festival["icon"]);//加载页面信息头,图标
  56. var productlist = msg["product"];
  57. for (var i = 0, l = productlist.length; i < l; i++) {
  58. $("#fog_" + productlist[i].url).attr("value", productlist[i].fog);
  59. var smslist = productlist[i].icon.split(",");
  60. for (var int = 0; int < smslist.length; int++) {
  61. if (int == 0) {
  62. $("#sendsms_order_" + productlist[i].url).attr("value", smslist[int]);
  63. }
  64. if (int == 1) {
  65. $("#sendsms_cancel_" + productlist[i].url).attr("value", smslist[int]);
  66. }
  67. if (int == 2) {
  68. $("#sendsms_yuyue_" + productlist[i].url).attr("value", smslist[int]);
  69. }
  70. }
  71. }
  72. } else {//未取出对应渠道与活动组数据
  73. goto404();
  74. }
  75. },
  76. error:
  77. function (XMLHttpRequest, textStatus, errorThrown) {//加载请求失败
  78. goto404();
  79. },
  80. });
  81. },
  82. /**
  83. * 获取项目根目录
  84. * @returns
  85. */
  86. getRootPath: function () {
  87. //获取当前网址,如: http://localhost:8080/ems/Pages/Basic/Person.jsp
  88. var curWwwPath = window.document.location.href;
  89. //获取主机地址之后的目录,如: /ems/Pages/Basic/Person.jsp
  90. var pathName = window.document.location.pathname;
  91. var pos = curWwwPath.indexOf(pathName);
  92. //获取主机地址,如: http://localhost:8080
  93. var localhostPath = curWwwPath.substring(0, pos);
  94. //获取带"/"的项目名,如:/ems
  95. var projectName = pathName.substring(0, pathName.substr(1).indexOf('/') + 1);
  96. return (localhostPath + projectName);
  97. },
  98. /**
  99. * 获取项目页面前
  100. * @returns
  101. */
  102. getHref: function () {
  103. //获取当前网址,如: http://localhost:8080/ems/Pages/Basic/Person.jsp
  104. var curWwwPath = window.document.location.href;
  105. //获取主机地址之后的目录,如: /ems/Pages/Basic/Person.jsp
  106. var pathName = window.document.location.pathname;
  107. var pos = curWwwPath.indexOf(pathName);
  108. //获取主机地址,如: http://localhost:8080
  109. var localhostPath = curWwwPath.substring(0, pos);
  110. //获取带"/"的项目名,如:/ems
  111. var projectName = pathName.substring(0, pathName.substr(1).indexOf('/') + 1);
  112. return (localhostPath + pathName);
  113. },
  114. showToast: function (message) {
  115. alert(message)
  116. }
  117. }
  118. dx.funs = {
  119. order: function(usermob, token) {
  120. var data = {
  121. "fog": getMemoValbyId(product, "fog"),
  122. "usermob": usermob,
  123. "useraccount": getMemoValbyId(product, "useraccount"),
  124. "fes": getUrlParam("fes"),
  125. "sou": getUrlParam("sou"),
  126. "token": token
  127. };
  128. dx.flow.showLoading && dx.flow.showLoading();
  129. $.ajax({
  130. type: "POST",
  131. contentType: "application/json; charset=utf-8",
  132. dataType: "Json",
  133. url: dx.utils.getRootPath() + "-s1api" + '/com/buyc',
  134. data: JSON.stringify(data),
  135. success: function (data) {
  136. dx.handler.order && dx.handler.order(data);
  137. },
  138. error: function (XMLHttpRequest, textStatus, errorThrown) {
  139. dx.utils.showToast("请求失败,请确认网络是否正常!")
  140. },
  141. });
  142. },
  143. openCap : function () {
  144. //$("#major").attr('disabled', true);
  145. //$("body").dx.("overflow", "hidden");
  146. var $iframe = $('<iframe id="uniauthframe" src="https://cap.chinaunicom.cn/CAP-AUTH/auth-tt.html?_=148040518646"></iframe>')
  147. var params = {
  148. "PRODUCT_NAME": dx.user.productName, // 产品名称
  149. "PRODUCT_PRICE": dx.user.productPrice, // 产品资费,以元为单位,如10.00元
  150. "CLIENT_ID": "", // client_id:"snjLokl02pK5o8dprOky"---- cp/sp注册后生成的id 头条: 8434545
  151. "CLIENT": "3", // 注册的客户端,1->安卓,2->ios,3->H5
  152. "SERVICE_ID": "", // 手机号(若获取到手机号码则必须传入,否则传空,由用户手动填写)
  153. "AUTH_NO": "", // auth_no:"154501722031712345" 秒级时间戳+随机数(5位)
  154. "CLIENT_SECRET": "", // Md5(密钥+auth_no)密钥存储在本地,不在网络上传送
  155. "VERSION": "1.0", // 版本
  156. "SERVICE_PHONE": "", // 客户电话,建议传,无则不传
  157. "THEME": "", // 样式主题 空则为默认
  158. "PRODUCT_ID": dx.user.productId, // 产品id
  159. "PRODUCT_TYPE": "1" // 产品类型(0:点播;1:包月;2:周期包月)
  160. }
  161. $iframe.on('load', function () {
  162. $.ajax({
  163. //请求后项定向服务获取
  164. url: getRootPath() + "-s1api" + "/ini/clientsecret",
  165. dataType: "JSON",
  166. method: "GET",
  167. success: function (data) {
  168. params.CLIENT_ID = data.client_id;
  169. params.AUTH_NO = data.auth_no;
  170. params.CLIENT_SECRET = data.client_secret;
  171. $('#uniauthframe')[0].contentWindow.postMessage(JSON.stringify(params), "https://cap.chinaunicom.cn/CAP-AUTH/")
  172. }
  173. })
  174. })
  175. $('body').append($iframe);
  176. //监听统一认证结果
  177. window.addEventListener('message', function (e) {
  178. var data = JSON.parse(e.data);
  179. $('html,body').addClass('ovfHiden');
  180. switch (data.RSP.RSP_CODE) {
  181. case "0000": //处理成功
  182. $('#uniauthframe').remove();
  183. dx.handler.openCap && dx.handler.openCap();
  184. break;
  185. case "0001"://auth_no无效 (入参流水)
  186. case "0003"://client_id不存在 (注册id存在问题)
  187. case "0006"://验证码不正确
  188. case "4444"://服务暂时不可用(系统忙/系统队列满)
  189. break;
  190. case "9001"://关闭H5认证页面
  191. $('#uniauthframe').remove();
  192. break;
  193. }
  194. }, false);
  195. }
  196. }
  197. })(dx, window);