const wxUtil = {
//获取base64编码
getBase64: function(str) {
var c1, c2, c3;
var base64EncodeChars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
var i = 0,
len = str.length,
string = '';
while (i < len) {
c1 = str.charCodeAt(i++) & 0xff;
if (i == len) {
string += base64EncodeChars.charAt(c1 >> 2);
string += base64EncodeChars.charAt((c1 & 0x3) << 4);
string += '==';
break;
}
c2 = str.charCodeAt(i++);
if (i == len) {
string += base64EncodeChars.charAt(c1 >> 2);
string += base64EncodeChars.charAt(((c1 & 0x3) << 4) | ((c2 & 0xf0) >> 4));
string += base64EncodeChars.charAt((c2 & 0xf) << 2);
string += '=';
break;
}
c3 = str.charCodeAt(i++);
string += base64EncodeChars.charAt(c1 >> 2);
string += base64EncodeChars.charAt(((c1 & 0x3) << 4) | ((c2 & 0xf0) >> 4));
string += base64EncodeChars.charAt(((c2 & 0xf) << 2) | ((c3 & 0xc0) >> 6));
string += base64EncodeChars.charAt(c3 & 0x3f);
}
return string;
},
//获取url上从参数
getUrlParam: function(param) {
var reg = new RegExp('(^|&)' + param + '=([^&]*)(&|$)', 'i');
var r = window.location.search.substr(1).match(reg);
if (r != null) {
return unescape(r[2]);
}
return '';
},
//通过微信服务器跳转授权
weixinJump: function(base64str) {
var that = this;
if (navigator.userAgent) {
var ua = navigator.userAgent.toLowerCase(); //获取判断用的对象
if (ua.match(/MicroMessenger/i) == 'micromessenger') {
var openid = that.getUrlParam('openid');
localStorage.setItem('wx_openid', openid);
window.location.href = 'http://111111111/weixinmp/userinfo?' + 'url=' + base64str;
//"url=aHR0cDovLzE5Mi4xNjguMS4yMTM6ODA4MS9zdGF0aWMvYWJpbGl0eSMv"
}
}
}
};
export default wxUtil;