diff --git a/src/pages/index/index.jsx b/src/pages/index/index.jsx index 45cb436..07c56ae 100644 --- a/src/pages/index/index.jsx +++ b/src/pages/index/index.jsx @@ -53,6 +53,8 @@ const Index = () => { const [joinMeetup, setjoinMeetup] = useState(false); + const [isWeChat, setisWeChat] = useState(false); + const getOpenidFromUrl = (url) => { const pattern = /[?&]openid=([^&#]+)/; const match = url.match(pattern); @@ -62,6 +64,18 @@ const Index = () => { return null; }; + // 是否在微信客户端 + const isWeChatFun = () => { + var ua = navigator.userAgent.toLowerCase(); + if (ua.indexOf("micromessenger") != -1) { + setisWeChat(true); + return true; + } else { + setisWeChat(false); + return false; + } + }; + // 获取openid const getOpenid = () => { // let newparams = Taro.getCurrentInstance().router.params; @@ -232,13 +246,14 @@ const Index = () => { // 入群申请 useEffect(() => { - // 获取openId - getOpenid(); - // window.alert(window.location.href) - // o7LFAwR32hWGq9XOpd7ZxK1wZxq8 - // window.alert(window.localStorage.getItem('openid')) - - // tgMessage(); + let inwechat = isWeChatFun(); + if (inwechat) { + // 获取openId + getOpenid(); + } else { + // window.alert('不在微信') + + } }, []); const goBack = () => {