Commit 234f16ab by dabai

xx

parent d694b2d6
Showing with 130 additions and 0 deletions
var _url = 'http://ceshi.yabolive.tv/web';
var _url2 = 'http://test.ybact.yazhaiyabo.com/';
var _url3 = 'http://ceshi.yabolive.tv';
if(location.href.indexOf('activity.yazhaiyabo.com') > -1) {
_url = 'https://webserver.yabolive.net';
_url2 = 'https://activity.yazhaiyabo.com/';
_url3 = 'https://webserver.yabolive.net';
}
var cdn = 'https://big.bgp.ourpow.com/comm';
function $ajax(opt) {
return new Promise(function(resolve, reject) {
opt = opt || {};
opt.method = opt.type || 'POST';
opt.url = _url + opt.url || '';
opt.async = opt.async || true;
opt.data = opt.data || null;
opt.dataType = opt.dataType || 'json';
opt.success = opt.success || function() {};
var xmlHttp = null;
if(XMLHttpRequest) {
xmlHttp = new XMLHttpRequest();
} else {
xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
}
var params = ['uid=' + getRequest().uid, 'cid=web_gw', 'os=WEB', 'token=' + getRequest().token, 'lang=' + (getRequest().lang || 2)];
for(var key in opt.data) {
params.push(key + '=' + (opt.data[key] || ''));
}
var postData = params.join('&');
if(opt.method.toUpperCase() === 'POST') {
xmlHttp.open(opt.method, opt.url, opt.async);
xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;charset=utf-8');
xmlHttp.send(postData);
} else if(opt.method.toUpperCase() === 'GET') {
xmlHttp.open(opt.method, opt.url + '?' + postData, opt.async);
xmlHttp.send(null);
}
xmlHttp.onreadystatechange = function() {
var res;
if(xmlHttp.readyState == 4 && xmlHttp.status == 200) {
res = xmlHttp.responseText;
if(opt.dataType == 'json') {
res = JSON.parse(res);
}
resolve(res);
}
};
})
}
function getTime(time) {
var timezone = 8; //目标时区时间,东八区
var offset_GMT = new Date(time).getTimezoneOffset(); // 本地时间和格林威治的时间差,单位为分钟
var nowDate = new Date(time).getTime(); // 本地时间距 1970 年 1 月 1 日午夜(GMT 时间)之间的毫秒数
var data = new Date(nowDate + offset_GMT * 60 * 1000 + timezone * 60 * 60 * 1000);
var year = data.getFullYear();
var month = data.getMonth() + 1;
var day = data.getDate();
var hour = data.getHours();
var minute = data.getMinutes();
var sec = data.getSeconds();
var obj = {
"year": year,
"month": add0(month),
"day": add0(day),
"hour": add0(hour),
"minute": add0(minute),
"sec": add0(sec),
}
return obj;
}
//加0
function add0(m) {
return m < 10 ? '0' + m + "" : m + ""
}
//获取url参数
function getRequest() {
var url = location.href;
var theRequest = new Object();
if(url.indexOf("?") != -1) {
var str = url.substr(url.indexOf("?") + 1);
strs = str.split("&");
for(var i = 0; i < strs.length; i++) {
theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
}
}
return theRequest;
}
function close() {
var obj = {
"cid": 14,
"reqCode": new Date().getTime(),
"data": {
"msg": '關閉半屏網頁',
}
}
var obj2 = JSON.stringify(obj);
appCollaboration(obj2);
}
function appCollaboration(msg) {
var sUserAgent = navigator.userAgent.toLowerCase();
var bIsIpad = sUserAgent.match(/ipad/i) == "ipad";
var bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os";
var bIsMidp = sUserAgent.match(/midp/i) == "midp";
var bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4";
var bIsUc = sUserAgent.match(/ucweb/i) == "ucweb";
var bIsAndroid = sUserAgent.match(/android/i) == "android";
var bIsCE = sUserAgent.match(/windows ce/i) == "windows ce";
var bIsWM = sUserAgent.match(/windows mobile/i) == "windows mobile";
if(!(bIsIpad || bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM)) {} else if(bIsAndroid) {
window.yazhai.appCollaboration(msg);
} else if(bIsIphoneOs || bIsIpad) {
window.webkit.messageHandlers.appCollaboration.postMessage(msg);
}
}
//客户端回调结果
function appCallback(msg) {
console.log(msg);
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment