From a1aef1d15c8d7b84d6f2f6d5fdb20a16c514a396 Mon Sep 17 00:00:00 2001 From: hackrobot Date: Wed, 17 Jul 2024 19:29:38 +0800 Subject: [PATCH] update --- src/pages/index/index.jsx | 134 ++++++++++++++++++++++++++++++------- src/pages/index/index.scss | 2 +- 2 files changed, 112 insertions(+), 24 deletions(-) diff --git a/src/pages/index/index.jsx b/src/pages/index/index.jsx index 53dff30..607343e 100644 --- a/src/pages/index/index.jsx +++ b/src/pages/index/index.jsx @@ -37,6 +37,7 @@ const Index = () => { const [current, setcurrent] = useState(0); const [openId, setopenId] = useState(null); const [wxid, setwxid] = useState(null); + const [userInfo, setuserInfo] = useState(null); const [open, setopen] = useState(false); const [referer, setreferer] = useState(window.document.referrer); @@ -70,6 +71,31 @@ const Index = () => { // 获取到openid window.localStorage.setItem("openid", hashopenid); setopenId(hashopenid); + // 查询数据库是否存在openid + Taro.request({ + method: "GET", + // url: `/api/add?openid=${hashopenid}`, //仅为示例,并非真实的接口地址 + url: `/api/user/${window.localStorage.getItem("openid")}`, //仅为示例,并非真实的接口地址 + success: function (res) { + if (res?.data?.userInfo) { + //判断wxid是否存在 + if (res?.data?.userInfo?.wxid) { + // 有完整的用户信息userInfo + setuserInfo(res?.data?.userInfo); + window.localStorage.setItem("userInfo", userInfo); + } else { + //不完整的openid用户信息 + } + } else { + // 新增openid用户 + // addopenidUser() + } + }, + complete: function (finy) { + // tg消息通知 + tgMessage(); + }, + }); } else { let nowUrl = window.location.href; let payUrl = `https://payjs.cn/api/openid?mchid=1561724891&callback_url=${nowUrl}`; @@ -81,34 +107,94 @@ const Index = () => { const getWxidFromUrl = () => { const urlParams = new URLSearchParams(window.location.search); const urlwxid = urlParams.get("wxid"); - if (!!urlwxid){ + if (!!urlwxid) { setwxid(urlwxid); - // 绑定wxid与openid到数据库 - + window.localStorage.setItem("wxid", wxid); // 优先查询openid是否存在数据库 Taro.request({ - method:'GET', - url: `/api/user/${openId}`, //仅为示例,并非真实的接口地址 - // url: "https://pay.hackrobot.cn/api/payh5", //仅为示例,并非真实的接口地址 + method: "GET", + url: `/api/user/${urlwxid}`, //仅为示例,并非真实的接口地址 + // url: `/api/user/${window.localStorage.getItem("openid")}`, //仅为示例,并非真实的接口地址 success: function (res) { - window.alert(res) + if (res?.data?.userInfo) { + //判断wxid是否存在 + if (res?.data?.userInfo?.openid) { + // 有完整的用户信息userInfo + setuserInfo(res?.data?.userInfo); + window.localStorage.setItem("userInfo", userInfo); + } else { + // 绑定wxid与openid到数据库 + wxidTapopenid(urlwxid); + } + } else { + // 新增wxid用户 + } + }, + complete: function (finy) { + // tg消息通知 + tgMessage(); }, }); + } else { + // tg消息通知 + tgMessage(); } return wxid; }; + // 绑定wxid与openid + const wxidTapopenid = (newWxid) => { + const userUpdateData = { + openid: window.localStorage.getItem("openid"), // 只更新 openid 字段 + }; + Taro.request({ + method: "PUT", + // url: `/api/user/${urlwxid}`, //仅为示例,并非真实的接口地址 + url: `/api/user/${newWxid}`, //仅为示例,并非真实的接口地址 + data: userUpdateData, + header: { + "Content-Type": "application/json", + }, + success: function (res) {}, + fail: function (err) {}, + complete: function (finy) {}, + }); + }; + + // 新增openid用户 + const addopenidUser = () => { + const userUpdateData = { + openid: window.localStorage.getItem("openid"), // 只更新 openid 字段 + }; + Taro.request({ + method: "GET", + // url: `/api/user/${urlwxid}`, //仅为示例,并非真实的接口地址 + url: `/api/user/${window.localStorage.getItem("openid")}`, //仅为示例,并非真实的接口地址 + data: userUpdateData, + header: { + "Content-Type": "application/json", + }, + success: function (res) {}, + fail: function (err) {}, + complete: function (finy) {}, + }); + }; + + + + // 网页查看通知 const tgMessage = () => { Taro.request({ - method:'GET', - url: `/api/tgMessage?openid=${openId}`, //仅为示例,并非真实的接口地址 + method: "GET", + url: `/api/tgMessage?openid=${window.localStorage.getItem("openid")}`, //仅为示例,并非真实的接口地址 // url: "https://pay.hackrobot.cn/api/payh5", //仅为示例,并非真实的接口地址 success: function (res) { - console.log('访问提醒发送成功'); + console.log("访问提醒发送成功"); }, }); }; + // 入群申请 useEffect(() => { @@ -119,7 +205,7 @@ const Index = () => { // window.alert(window.localStorage.getItem('openid')) // 获取wxid参数 getWxidFromUrl(); - tgMessage() + // tgMessage(); }, []); const goBack = () => { @@ -224,7 +310,7 @@ const Index = () => { style="width: 30px;height:30px;background: #fff;" src={nomad} /> - 数字游民 + 数字游民手册 多元自动化收入 @@ -232,14 +318,15 @@ const Index = () => { 1. 微信运营:云手机+机器人+AIGC
2. 自媒体:youtube获利+wordpress
- 3. 跨境电商:amazon
- 4. 软件saas:独立开发
- 5. 知识付费:如何出版一本书?
- - + 3. 跨境电商:amazon +
+ 4. 软件saas:独立开发 +
+ 5. 知识付费:如何出版一本书? +
- 立即阅读 + 预约 @@ -290,16 +377,17 @@ const Index = () => { {/* 右边 */} - - 数字游民 | 自由职业者沙龙 - + 数字游民 | 自由职业者沙龙 深圳市龙华区 - 18:00--20:00 - 了解详情 + + + 19:00--21:00 + + 立即报名 diff --git a/src/pages/index/index.scss b/src/pages/index/index.scss index 01a396c..c0e7e3b 100644 --- a/src/pages/index/index.scss +++ b/src/pages/index/index.scss @@ -48,7 +48,7 @@ .bookImg { width: 40%; height: 100%; - background-color: #1bb14e; + // background-color: #1bb14e; } .book-middle{