update
This commit is contained in:
@@ -53,6 +53,16 @@ const Index = () => {
|
|||||||
|
|
||||||
const [joinMeetup, setjoinMeetup] = useState(false);
|
const [joinMeetup, setjoinMeetup] = useState(false);
|
||||||
|
|
||||||
|
const getOpenidFromUrl=(url)=> {
|
||||||
|
const pattern = /[?&]openid=([^&#]+)/;
|
||||||
|
const match = url.match(pattern);
|
||||||
|
if (match) {
|
||||||
|
return match[1];
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// 获取openid
|
// 获取openid
|
||||||
const getOpenid = () => {
|
const getOpenid = () => {
|
||||||
// let newparams = Taro.getCurrentInstance().router.params;
|
// let newparams = Taro.getCurrentInstance().router.params;
|
||||||
@@ -62,50 +72,24 @@ const Index = () => {
|
|||||||
// http://192.168.31.245:10086/?openid=o7LFAwR32hWGq9XOpd7ZxK1wZxq8#/pages/index/index
|
// http://192.168.31.245:10086/?openid=o7LFAwR32hWGq9XOpd7ZxK1wZxq8#/pages/index/index
|
||||||
let hashopenid = null;
|
let hashopenid = null;
|
||||||
if (window.location.href.includes("openid")) {
|
if (window.location.href.includes("openid")) {
|
||||||
hashopenid = window.location.href
|
hashopenid= getOpenidFromUrl(window.location.href)
|
||||||
.split("#")[0]
|
|
||||||
.split("?")[1]
|
|
||||||
.split("=")[1];
|
|
||||||
} else {
|
} else {
|
||||||
hashopenid = window.localStorage.getItem("openid");
|
// hashopenid = window.localStorage.getItem("openid");
|
||||||
}
|
}
|
||||||
|
if (!!hashopenid && hashopenid != "undefined" && hashopenid != "null") {
|
||||||
let newOpenid = window.localStorage.getItem("openid");
|
|
||||||
|
|
||||||
if (
|
|
||||||
(!!newOpenid && newOpenid != "undefined" && newOpenid != "null") ||
|
|
||||||
(!!hashopenid && hashopenid != "undefined" && hashopenid != "null")
|
|
||||||
) {
|
|
||||||
// 获取到openid
|
// 获取到openid
|
||||||
window.localStorage.setItem("openid", hashopenid);
|
window.localStorage.setItem("openid", hashopenid);
|
||||||
|
|
||||||
setopenId(hashopenid);
|
setopenId(hashopenid);
|
||||||
|
// window.alert(hashopenid);
|
||||||
// 查询数据库是否存在openid
|
// 查询数据库是否存在openid
|
||||||
Taro.request({
|
|
||||||
method: "GET",
|
// 获取wxid参数
|
||||||
// url: `/api/add?openid=${hashopenid}`, //仅为示例,并非真实的接口地址
|
getWxidFromUrl();
|
||||||
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 {
|
} else {
|
||||||
let nowUrl = window.location.href;
|
let nowUrl = window.location.href;
|
||||||
|
window.localStorage.removeItem("openid")
|
||||||
let payUrl = `https://payjs.cn/api/openid?mchid=1561724891&callback_url=${nowUrl}`;
|
let payUrl = `https://payjs.cn/api/openid?mchid=1561724891&callback_url=${nowUrl}`;
|
||||||
window.location.href = payUrl;
|
window.location.href = payUrl;
|
||||||
}
|
}
|
||||||
@@ -147,15 +131,18 @@ const Index = () => {
|
|||||||
if (res?.data?.userInfo) {
|
if (res?.data?.userInfo) {
|
||||||
//判断wxid是否存在
|
//判断wxid是否存在
|
||||||
if (res?.data?.userInfo?.openid) {
|
if (res?.data?.userInfo?.openid) {
|
||||||
|
// window.alert(res?.data?.userInfo?.openid);
|
||||||
|
// window.alert(window.localStorage.getItem("openid"));
|
||||||
|
|
||||||
if (
|
if (
|
||||||
res?.data?.userInfo?.openid !==
|
res?.data?.userInfo?.openid !==
|
||||||
window.localStorage.getItem("openid")
|
window.localStorage.getItem("openid")
|
||||||
) {
|
) {
|
||||||
// 删除其他用户的wxid
|
// 删除其他用户的wxid
|
||||||
window.localStorage.removeItem('userInfo')
|
window.localStorage.removeItem("userInfo");
|
||||||
window.localStorage.removeItem('openid')
|
window.localStorage.removeItem("openid");
|
||||||
window.localStorage.removeItem('wxid')
|
window.localStorage.removeItem("wxid");
|
||||||
window.location.href="https://nomad.hackrobot.cn"
|
window.location.href = "http://nomad.hackrobot.cn";
|
||||||
} else {
|
} else {
|
||||||
// 有完整的用户信息userInfo
|
// 有完整的用户信息userInfo
|
||||||
setuserInfo(res?.data?.userInfo);
|
setuserInfo(res?.data?.userInfo);
|
||||||
@@ -239,8 +226,7 @@ const Index = () => {
|
|||||||
// window.alert(window.location.href)
|
// window.alert(window.location.href)
|
||||||
// o7LFAwR32hWGq9XOpd7ZxK1wZxq8
|
// o7LFAwR32hWGq9XOpd7ZxK1wZxq8
|
||||||
// window.alert(window.localStorage.getItem('openid'))
|
// window.alert(window.localStorage.getItem('openid'))
|
||||||
// 获取wxid参数
|
|
||||||
getWxidFromUrl();
|
|
||||||
// tgMessage();
|
// tgMessage();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
@@ -393,7 +379,9 @@ const Index = () => {
|
|||||||
// type: "success",
|
// type: "success",
|
||||||
// });
|
// });
|
||||||
|
|
||||||
setbookToast(true);
|
if (res.data.code == "200") {
|
||||||
|
setbookToast(true);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
fail: function (err) {},
|
fail: function (err) {},
|
||||||
complete: function (finy) {
|
complete: function (finy) {
|
||||||
@@ -518,7 +506,9 @@ const Index = () => {
|
|||||||
// message: "预约成功",
|
// message: "预约成功",
|
||||||
// type: "success",
|
// type: "success",
|
||||||
// });
|
// });
|
||||||
setmeetupToast(true);
|
if (res.data.code == "200") {
|
||||||
|
setmeetupToast(true);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
fail: function (err) {},
|
fail: function (err) {},
|
||||||
complete: function (finy) {
|
complete: function (finy) {
|
||||||
|
|||||||
Reference in New Issue
Block a user