是否微信访问:
是否小程序访问:
源码:
export const isWeiXin = function(){
var ua = window.navigator.userAgent.toLowerCase();
console.log('ua',ua);
if(ua.match(/MicroMessenger/i) == 'micromessenger'){
return true;
}else{
return false;
}
}
export const isWeiXinWeapp = function(){
return new Promise((resolve, reject)=> {
if( isWeiXin() ){
wx.miniProgram.getEnv((res)=>{
if( res.miniprogram ){
console.log('小程序webview访问');
resolve(true);
}else{
console.log('非小程序访问-微信环境');
getLlbLogin(resolve);
}
})
}else{
console.log('非小程序访问-其他环境');
getLlbLogin(resolve);
}
});
}