feat: 获取openid

This commit is contained in:
eric
2023-12-03 18:27:39 +08:00
parent 16d997881d
commit 19b4aa7960
6 changed files with 72 additions and 10 deletions

View File

@@ -22,6 +22,32 @@ const Index = () => {
const [current, setcurrent] = useState(0);
const [isOpened, setisOpened] = useState(false);
// 获取openid
const getWxid = () => {
let newparams = Taro.getCurrentInstance().router.params;
let urlopenid = newparams.openid;
// window.alert(urlopenid)
let newOpenid = window.localStorage.getItem("openid");
// window.alert(newOpenid)
if (newOpenid || urlopenid) {
// window.alert('存在')
window.localStorage.setItem("openid", urlopenid);
// window.alert(urlopenid);
} else {
// window.alert('不存在')
let nowUrl = window.location.href;
window.alert(nowUrl)
let payUrl = `https://payjs.cn/api/openid?mchid=1561724891&callback_url=${nowUrl}`;
window.location.href = payUrl;
}
};
useEffect(() => {
getWxid();
}, []);
const handleClick = (value) => {
console.log("value", value);
setcurrent(value);
@@ -199,7 +225,7 @@ const Index = () => {
</View>
</AtCard>
{/* <View className="indexTablebar">
<View className="indexTablebar">
<AtTabBar
tabList={[
{ title: "首页", text: "" },
@@ -209,7 +235,7 @@ const Index = () => {
onClick={(value) => handleClick(value)}
current={current}
/>
</View> */}
</View>
</View>
);
};