From 0e0fed4eccf9b506317ee0ad25841b0a09aa7f7f Mon Sep 17 00:00:00 2001 From: hackrobot Date: Thu, 18 Jul 2024 18:31:20 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A4=E6=96=AD=E6=98=AF=E5=90=A6=E5=9C=A8?= =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E5=AE=A2=E6=88=B7=E7=AB=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/index/index.jsx | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) 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 = () => {