123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215 |
- window.dx = {'user':{}};
- !(function () {
- var toString = String.prototype.toString;
- Array.isArray || (Array.isArray = function (obj) {
- return toString.call(obj) === '[object Array]';
- });
- })();
- (function (dx, window) {
- dx.query = {};
- var QUERY_SEPARATOR = '&', VALUE_SEPARATOR = '=';
- var queryStr = window.location.search.substring(1);
- var startIndex = 0, vIndex, qIndex;
- while (queryStr.length > 0) {
- vIndex = queryStr.indexOf(VALUE_SEPARATOR, startIndex);
- if (vIndex == -1) {
- break;
- }
- qIndex = queryStr.indexOf(QUERY_SEPARATOR, vIndex + 1);
- if (qIndex == -1) {
- qIndex = queryStr.length;
- }
- var key = queryStr.substring(startIndex, vIndex);
- var value = queryStr.substring(vIndex + 1, qIndex);
- dx.query[key] = decodeURIComponent(value);
- startIndex = qIndex + 1;
- }
- })(dx, window);
- !(function (dx, window) {
- dx.utils = {
- /**
- * 消息发送获取Josn数据
- * @param method 方法名称
- * @param data 发送数据
- * @returns 返回的json数据
- * 此方法需加载页面头信息与页面显示图标:
- * 页面必须有 title 标签
- * id = "icon" 链接地址
- * <link id="icon" rel="shortcut icon" type="image/x-icon" href=""/>
- * 加载页面基本信息:
- * XX 为活动对应产品表中配置标示
- * <input type="hidden" id="fog_XX"/>
- */
- postini: function () {
- $.ajax({
- url: getRootPath() + "-s1api" + '/ini/getstyle',
- type: "POST", // 用POST方式传输
- contentType: "application/json; charset=utf-8",
- dataType: "Json",
- data: JSON.stringify(postiniDate()),
- success:
- function (msg) {
- var resCode = msg["resultCode"];
- if (resCode == "0000") {
- var festival = msg["festival"];
- theme(festival["title"], festival["icon"]);//加载页面信息头,图标
- var productlist = msg["product"];
- for (var i = 0, l = productlist.length; i < l; i++) {
- $("#fog_" + productlist[i].url).attr("value", productlist[i].fog);
- var smslist = productlist[i].icon.split(",");
- for (var int = 0; int < smslist.length; int++) {
- if (int == 0) {
- $("#sendsms_order_" + productlist[i].url).attr("value", smslist[int]);
- }
- if (int == 1) {
- $("#sendsms_cancel_" + productlist[i].url).attr("value", smslist[int]);
- }
- if (int == 2) {
- $("#sendsms_yuyue_" + productlist[i].url).attr("value", smslist[int]);
- }
- }
- }
- } else {//未取出对应渠道与活动组数据
- goto404();
- }
- },
- error:
- function (XMLHttpRequest, textStatus, errorThrown) {//加载请求失败
- goto404();
- },
- });
- },
- /**
- * 获取项目根目录
- * @returns
- */
- getRootPath: function () {
- //获取当前网址,如: http://localhost:8080/ems/Pages/Basic/Person.jsp
- var curWwwPath = window.document.location.href;
- //获取主机地址之后的目录,如: /ems/Pages/Basic/Person.jsp
- var pathName = window.document.location.pathname;
- var pos = curWwwPath.indexOf(pathName);
- //获取主机地址,如: http://localhost:8080
- var localhostPath = curWwwPath.substring(0, pos);
- //获取带"/"的项目名,如:/ems
- var projectName = pathName.substring(0, pathName.substr(1).indexOf('/') + 1);
- return (localhostPath + projectName);
- },
- /**
- * 获取项目页面前
- * @returns
- */
- getHref: function () {
- //获取当前网址,如: http://localhost:8080/ems/Pages/Basic/Person.jsp
- var curWwwPath = window.document.location.href;
- //获取主机地址之后的目录,如: /ems/Pages/Basic/Person.jsp
- var pathName = window.document.location.pathname;
- var pos = curWwwPath.indexOf(pathName);
- //获取主机地址,如: http://localhost:8080
- var localhostPath = curWwwPath.substring(0, pos);
- //获取带"/"的项目名,如:/ems
- var projectName = pathName.substring(0, pathName.substr(1).indexOf('/') + 1);
- return (localhostPath + pathName);
- },
- showToast: function (message) {
- alert(message)
- }
- }
- dx.funs = {
- order: function(usermob, token) {
- var data = {
- "fog": getMemoValbyId(product, "fog"),
- "usermob": usermob,
- "useraccount": getMemoValbyId(product, "useraccount"),
- "fes": getUrlParam("fes"),
- "sou": getUrlParam("sou"),
- "token": token
- };
- dx.flow.showLoading && dx.flow.showLoading();
- $.ajax({
- type: "POST",
- contentType: "application/json; charset=utf-8",
- dataType: "Json",
- url: dx.utils.getRootPath() + "-s1api" + '/com/buyc',
- data: JSON.stringify(data),
- success: function (data) {
- dx.handler.order && dx.handler.order(data);
- },
- error: function (XMLHttpRequest, textStatus, errorThrown) {
- dx.utils.showToast("请求失败,请确认网络是否正常!")
- },
- });
- },
- openCap : function () {
- //$("#major").attr('disabled', true);
- //$("body").dx.("overflow", "hidden");
- var $iframe = $('<iframe id="uniauthframe" src="https://cap.chinaunicom.cn/CAP-AUTH/auth-tt.html?_=148040518646"></iframe>')
- var params = {
- "PRODUCT_NAME": dx.user.productName, // 产品名称
- "PRODUCT_PRICE": dx.user.productPrice, // 产品资费,以元为单位,如10.00元
- "CLIENT_ID": "", // client_id:"snjLokl02pK5o8dprOky"---- cp/sp注册后生成的id 头条: 8434545
- "CLIENT": "3", // 注册的客户端,1->安卓,2->ios,3->H5
- "SERVICE_ID": "", // 手机号(若获取到手机号码则必须传入,否则传空,由用户手动填写)
- "AUTH_NO": "", // auth_no:"154501722031712345" 秒级时间戳+随机数(5位)
- "CLIENT_SECRET": "", // Md5(密钥+auth_no)密钥存储在本地,不在网络上传送
- "VERSION": "1.0", // 版本
- "SERVICE_PHONE": "", // 客户电话,建议传,无则不传
- "THEME": "", // 样式主题 空则为默认
- "PRODUCT_ID": dx.user.productId, // 产品id
- "PRODUCT_TYPE": "1" // 产品类型(0:点播;1:包月;2:周期包月)
- }
- $iframe.on('load', function () {
- $.ajax({
- //请求后项定向服务获取
- url: getRootPath() + "-s1api" + "/ini/clientsecret",
- dataType: "JSON",
- method: "GET",
- success: function (data) {
- params.CLIENT_ID = data.client_id;
- params.AUTH_NO = data.auth_no;
- params.CLIENT_SECRET = data.client_secret;
- $('#uniauthframe')[0].contentWindow.postMessage(JSON.stringify(params), "https://cap.chinaunicom.cn/CAP-AUTH/")
- }
- })
- })
- $('body').append($iframe);
- //监听统一认证结果
- window.addEventListener('message', function (e) {
- var data = JSON.parse(e.data);
- $('html,body').addClass('ovfHiden');
- switch (data.RSP.RSP_CODE) {
- case "0000": //处理成功
- $('#uniauthframe').remove();
- dx.handler.openCap && dx.handler.openCap();
- break;
- case "0001"://auth_no无效 (入参流水)
- case "0003"://client_id不存在 (注册id存在问题)
- case "0006"://验证码不正确
- case "4444"://服务暂时不可用(系统忙/系统队列满)
- break;
- case "9001"://关闭H5认证页面
- $('#uniauthframe').remove();
- break;
- }
- }, false);
- }
- }
- })(dx, window);
|