var data_url = "https://server.bwgyou.com"
//var data_url = "http://192.168.1.113"
//判断是否微信
function isWx(){
var ua = navigator.userAgent.toLowerCase();
var isWeixin = ua.indexOf('micromessenger') != -1;
return isWeixin;
}
/**
* 微信登录(含扫一扫登录或微信里面调用微信登录)
*/
var currWbUserId = null
var currWbUserName = ""
$(function(){
wxLogin(window.location.href)
})
var wx_open_appid = "wx4c52dd01dc5ef636"
var wx_gz_appid = "wx4042de44369bc68f"
function wxLogin(params){
params = params.replace(/&/g,'*');
redirectUrl = "http://www.bwgyou.com/api/wx/login"
//获取开放平台参数
var ua = navigator.userAgent.toLowerCase();
var isWeixin = ua.indexOf('micromessenger') != -1;
if (!isWeixin) {
var os = $.getOs_();
if(1){ //os.device.type == 'desktop'
location='https://open.weixin.qq.com/connect/qrconnect?appid=' + wx_open_appid + '&'+
'redirect_uri=' + redirectUrl + '&'+
'response_type=code&'+
'scope=snsapi_login&'+
'state=' + params + '#wechat_redirect';
}else{
location = '/view/mobile/loginreg/index.html?backurl=' + params
}
}else{
location='https://open.weixin.qq.com/connect/oauth2/authorize?appid=' + wx_gz_appid + '&'+
'redirect_uri=' + redirectUrl + "gz" + '&'+
'response_type=code&'+
'scope=snsapi_userinfo&'+
'state=' + params + '#wechat_redirect';
}
}
/**
* 微信扫一扫
*/
function openScan(){
if(!isWx()){
//不是微信访问
alert('请使用微信访问')
return;
}
wx.scanQRCode({
needResult : 0, // 默认为0,扫描结果由微信处理,1则直接返回扫描结果,
scanType : [ "qrCode"], // 可以指定扫二维码还是一维码,默认二者都有
success : function(res) {
var result = res.resultStr; // 当needResult 为 1 时,扫码返回的结果
//document.getElementById("wm_id").value = result;//将扫描的结果赋予到jsp对应值上
//alert("扫描成功::扫描码=" + result);
}
});
}
function uuid_(len, radix){
var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('');
var uuid = [], i;
radix = radix || chars.length;
if (len) {
// Compact form
for (i = 0; i < len; i++) uuid[i] = chars[0 | Math.random()*radix];
} else {
// rfc4122, version 4 form
var r;
// rfc4122 requires these characters
uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-';
uuid[14] = '4';
// Fill in random data. At i==19 set the high bits of clock sequence as
// per rfc4122, sec. 4.1.5
for (i = 0; i < 36; i++) {
if (!uuid[i]) {
r = 0 | Math.random()*16;
uuid[i] = chars[(i == 19) ? (r & 0x3) | 0x8 : r];
}
}
}
return uuid.join('');
}
$.extend({
getOs_:function(){
return detect_(navigator.userAgent.toLowerCase());
},
isPC:function(){
var os = $.getOs_();
if(os.device.type == 'desktop'){
return true;
}else{
return false;
}
}
})
//userAgent regexp
var Exp_USERAGENT_ = {
//browser
MSIE : /(msie) ([\w.]+)/,
MOZILLA : /(mozilla)(?:.*? rv:([\w.]+)|)/,
SAFARI : /(safari)(?:.*version|)[\/]([\d.]+)/,
CHROME : /(chrome|crios)[\/]([\w.]+)/,
OPERA : /(opera|opr)(?:.*version|)[\/]([\w.]+)/,
WEBOS : /(webos|hpwos)[\s\/]([\d.]+)/,
DOLFIN : /(dolfin)(?:.*version|)[\/]([\w.]+)/, //
SILK : /(silk)(?:.*version|)[\/]([\w.]+)/, //
UC : /(uc)browser(?:.*version|)[\/]([\w.]+)/, //
TAOBAO : /(tao|taobao)browser(?:.*version|)[\/]([\w.]+)/,
LIEBAO : /(lb)browser(?:.*? rv:([\w.]+)|)/,
//AMAYA:/(amaya)[\/]([\w.]+)/,
//SEAMONKEY:/(seamonkey)[\/]([\w.]+)/,
//OMNIWEB:/(omniweb)[\/]v([\w.]+)/,
//FLOCK:/(flock)[\/]([\w.]+)/,
//EPIPHANY:/(epiphany)[\/]([\w.]+)/,
MicroMessenger :/micromessenger/i,//
//engine
WEBKIT : /webkit[\/]([\w.]+)/,
GECKO : /gecko[\/]([\w.]+)/, //
PRESTO : /presto[\/]([\w.]+)/, //
TRIDENT : /trident[\/]([\w.]+)/,
//device
MAC : /(mac os x)\s+([\w_]+)/, //
WINNDOWS : /(windows nt)\s+([\w.]+)/, //
LINUX : /linux/, //
//IOS : /i(?:pad|phone|pod)(?:.*)cpu(?: iphone)? os/,
IOS : /(i(?:pad|phone|pod))(?:.*)cpu(?: i(?:pad|phone|pod))? os (\d+(?:[\.|_]\d+){1,})/,
ANDROID : /(android)\s+([\d.]+)/,
WINDOWSPHONE : /windowsphone/, //
IPAD : /(ipad).*os\s([\d_]+)/,
IPHONE : /(iphone\sos)\s([\d_]+)/,
IPOD : /(ipod)(?:.*)cpu(?: iphone)? os (\d+(?:[\.|_]\d+){1,})/,
TOUCHPAD : /touchpad/,
BLACKBERRY : /(playbook|blackberry|bb\d+).*version\/([\d.]+)/,
RIMTABLET : /rimtablet/, //
BADA : /bada/, //
CHROMEOS : /cromeos///
};
function detect_(ua) {
var os = {},
//browser
chrome = ua.match(Exp_USERAGENT_.CHROME),
opera = ua.match(Exp_USERAGENT_.OPERA),
msie = ua.match(Exp_USERAGENT_.MSIE),
safari = (ua + ua.replace(Exp_USERAGENT_.SAFARI, ' ')).match(Exp_USERAGENT_.SAFARI), //modify the jquery bug
mozilla = ua.match(Exp_USERAGENT_.MOZILLA),
webos = ua.match(Exp_USERAGENT_.WEBOS),
dolphi = ua.match(Exp_USERAGENT_.DOLFIN),
silk = ua.match(Exp_USERAGENT_.SILK),
uc = ua.match(Exp_USERAGENT_.UC),
taobao=ua.match(Exp_USERAGENT_.TAOBAO),
liebao=ua.match(Exp_USERAGENT_.LIEBAO),
//engine
webkit = ua.match(Exp_USERAGENT_.WEBKIT),
gecko = ua.match(Exp_USERAGENT_.GECKO),
presto = ua.match(Exp_USERAGENT_.PRESTO),
trident = ua.match(Exp_USERAGENT_.TRIDENT),
//device
mac = ua.match(Exp_USERAGENT_.MAC),
windows = ua.match(Exp_USERAGENT_.WINNDOWS),
linux = ua.match(Exp_USERAGENT_.LINUX),
chromeos = ua.match(Exp_USERAGENT_.CHROMEOS),
//pad
ipad = ua.match(Exp_USERAGENT_.IPAD),
rimtablet = ua.match(Exp_USERAGENT_.RIMTABLET),
touchpad = webos && ua.match(Exp_USERAGENT_.TOUCHPAD),
//mobile
ios = ua.match(Exp_USERAGENT_.IOS),
ipod = ua.match(Exp_USERAGENT_.IPOD),
iphone = !ipad && ua.match(Exp_USERAGENT_.IPHONE),
android = ua.match(Exp_USERAGENT_.ANDROID),
windowsphone = ua.match(Exp_USERAGENT_.WINDOWSPHONE),
blackberry = ua.match(Exp_USERAGENT_.BLACKBERRY),
bada = ua.match(Exp_USERAGENT_.BADA);
//engine
if (webkit)
os.webkit = true;
if (gecko)
os.gecko = true;
if (presto)
os.presto = true;
if (trident)
os.trident = true;
//device
os['device'] = {};
//
if (mac)
os.mac = true, os['device']['name'] = 'mac os', os.version = mac[2];
if (windows)
os.windows = true, os['device']['name'] = 'window', os.version = windows[2];
if (linux)
os.linux = true, os['device']['name'] = 'linux'; //
if (chromeos)
os.chromeos = true, os['device']['name'] = 'chromeos', os.version = chromeos[2];
//if (ios) os.ios=true;//
if (android)
os.android = true, os['device']['name'] = 'android', os.version = android[2];
if (iphone)
os.ios = true, os['device']['name'] = 'iphone',os.version = iphone[2].replace(/_/g, '.'), os.iphone = true;
if (ipod)
os.ios = true, os['device']['name'] = 'ipod',os.version = ipod[2].replace(/_/g, '.'), os.ipod = true;
if (ipad)
os.ios = true, os['device']['name'] = 'ipad', os.version = ipad[2].replace(/_/g, '.'), os.ipad = true;
if (webos)
os.webos = true, os['device']['name'] = 'webos',os.version = webos[2];
if (blackberry)
os.blackberry = true, os['device']['name'] = 'blackberry', os.version = blackberry[2];
if (bada)
os.bada = true, os['device']['name'] = 'bada',os.version = ''; //
if (rimtablet)
os.rimtablet = true, os['device']['name'] = 'rimtablet', os.version = ''; //
if (touchpad)
os.touchpad = true, os['device']['name'] = 'touchpad',os.version = ''; //
//os.device.version
os['device']['version'] = os.version;
if (!(android || iphone || ipad || ipod || webos || blackberry || bada || rimtablet || touchpad))
os.desktop = true, os.version = '';
//browser
var match = dolphi || silk || uc || msie || taobao || liebao || opera || chrome || safari || (ua.indexOf('compatible') < 0 && mozilla);
//chrome
match[1] = match[1] === 'crios' ? 'chrome' : match[1];
//taobao
match[1] = match[1] === 'tao' ? 'taobao' : match[1];
//
os[match[1]] = true;
os['browser'] = match[1];
os['version'] = match[2]||'';
//major
os['version'] && (os['major'] = parseInt(os['version'],10));
//revise
//safari
if (os.ios && os.webkit && !os.desktop) {
try{
//in node js
os.safari = (window.canSetSearchEngine || window.TrackEvent) ? true : false;
}catch(e){}
var v=os['major']||parseInt(os['device-version'],10)||'';
v && (os['ios'+v]=true);
}
//ie 11
if(os.trident && os.major >= 11){
os.browser='msie';
os.msie=true;
delete os.mozilla;
}
//mozilla/firefox
if (os.mozilla) {
os.firefox = true;
}
//opera
if(os.browser === 'opr'){
os.browser = 'opera';
os.opera=os.opr;
}
//blackberry
if(os.blackberry){
//
delete os.safari;
}
//MicroMessager
if(Exp_USERAGENT_.MicroMessenger.test(ua)){
//
os.micromessage=true;
}
//uc
var DOMWindow = DOMWindow || {};
if (DOMWindow && DOMWindow.UCNewsJSController) {
os.uc = true,
os.browser = 'uc';
}
//
try{
//orientation
os.orientation = (window.orientation === 180 || window.orientation === 0) ? 'portrait' : 'landscape';
}catch(e){}
//os.device.type
if(os.desktop){
os.device['type']='desktop';
}else{
os.device['type']='mobile';
}
//
return os;
};