From 6af9642ceb5cb541af584c9df8a50163427710e0 Mon Sep 17 00:00:00 2001 From: hackrobot Date: Thu, 11 Apr 2024 09:33:44 +0800 Subject: [PATCH] dffe --- src/pages/index/index.jsx | 74 +++++++++++++++++++++++---------------- 1 file changed, 44 insertions(+), 30 deletions(-) diff --git a/src/pages/index/index.jsx b/src/pages/index/index.jsx index eb673f3..fb3feff 100644 --- a/src/pages/index/index.jsx +++ b/src/pages/index/index.jsx @@ -53,43 +53,43 @@ const Index = () => { wxaccount: null, }); + // // 获取用户标识符 + // useEffect(() => { + // // 获取路由参数 + // const params = Taro.getCurrentInstance().router.params; + // console.log("params", params); + // let localwxid = window.localStorage.getItem("wxid"); + // let localh5openid = window.localStorage.getItem("h5openid"); - // 获取用户标识符 - useEffect(() => { - // 获取路由参数 - const params = Taro.getCurrentInstance().router.params; - console.log("params", params); - let localwxid = window.localStorage.getItem("wxid"); - let localh5openid = window.localStorage.getItem("h5openid"); - - if (params?.wxid || localwxid) { - // 本地存储 - window.localStorage.setItem("wxid", params?.wxid ?? ""); - // alert(params?.wxid); - setwxid(params?.wxid); - if ( - !localh5openid || - localh5openid == "undefined" || - localh5openid == "null" - ) { - getopenId(); - } else { - h5openidUser(); - } - } - }, []); + // if ( + // params?.wxid && + // (!localh5openid || + // localh5openid == "undefined" || + // localh5openid == "null") + // ) { + // // 本地存储 + // window.localStorage.setItem("wxid", params?.wxid ?? ""); + // // alert(params?.wxid); + // setwxid(params?.wxid); + // getopenId(); + // } + // }, []); const onBridgeReady = () => { WeixinJSBridge.call("hideOptionMenu"); }; + useEffect(()=>{ + getopenId() + },[]) + const h5openidUser = () => { try { const params = Taro.getCurrentInstance().router.params; let hashopenid = window.localStorage.getItem("h5openid"); let localwxid = window.localStorage.getItem("wxid"); - alert ("hashopenid",hashopenid) - alert ("localwxid",localwxid) + alert("hashopenid", hashopenid); + alert("localwxid", localwxid); //发起网络请求 Taro.request({ @@ -136,10 +136,24 @@ const Index = () => { // 查询用户信息 h5openidUser(); } else { - let nowUrl = window.location.href; - // alert(nowUrl); - let payUrl = `https://payjs.cn/api/openid?mchid=1561724891&callback_url=${nowUrl}`; - window.location.href = payUrl; + // 获取路由参数 + const params = Taro.getCurrentInstance().router.params; + console.log("params", params); + + if (params?.wxid) { + // 本地存储 + window.localStorage.setItem("wxid", params?.wxid ?? ""); + // alert(params?.wxid); + setwxid(params?.wxid); + let nowUrl = window.location.href; + // alert(nowUrl); + let payUrl = `https://payjs.cn/api/openid?mchid=1561724891&callback_url=${nowUrl}`; + window.location.href = payUrl; + }else{ + alert('没有wxid') + } + + } };